From 1b6cb52fed60b978e50414a4c56458f297832e75 Mon Sep 17 00:00:00 2001 From: Pravin_s Date: Wed, 4 Sep 2019 15:54:34 +0530 Subject: [PATCH 01/52] Task #169 fix: Resolve PHP CS and fatal error of getListQuery --- .../com_tjucm/site/models/items.php | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/components/com_tjucm/site/models/items.php b/src/components/com_tjucm/site/models/items.php index 62a62ecf..33ee338a 100644 --- a/src/components/com_tjucm/site/models/items.php +++ b/src/components/com_tjucm/site/models/items.php @@ -93,7 +93,7 @@ protected function populateState($ordering = "a.id", $direction = "DESC") foreach ($fields as $field) { $filterValue = $app->getUserStateFromRequest($this->context . '.' . $field->name, $field->name, '', 'STRING'); - $this->setState('filter.field.' . $field->name, $filterValue); + $this->setState('filter.field.' . $field->name, $filterValue); } if (empty($ucmType)) @@ -230,7 +230,7 @@ protected function getListQuery() } } - $query->where($db->quoteName('a.cluster_id') . ' IN (' . implode(",", $usersClusters) . ')'); + $query->where($db->quoteName('a.cluster_id') . " IN ('" . implode("','", $usersClusters) . "')"); } } @@ -272,7 +272,7 @@ protected function getListQuery() else { // If no search results found then do not return any record - $query->where($db->quoteName('a.id') . '=0'); + $query->where($db->quoteName('a.id') . '=0'); } } @@ -337,12 +337,13 @@ private function filterContent() if ($filterFieldsCount > 1) { - $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . $db->qn('fv' . ($filterFieldsCount-1).'.content_id') . ' = ' . $db->qn('fv'.$filterFieldsCount.'.content_id') . ')'); + $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . + $db->qn('fv' . ($filterFieldsCount - 1) . '.content_id') . ' = ' . $db->qn('fv' . $filterFieldsCount . '.content_id') . ')'); } $search = trim(str_replace($field . ':', '', $search)); - $query->where($db->qn('fv'.$filterFieldsCount.'.field_id') . ' = ' . $fieldId); - $query->where($db->qn('fv'.$filterFieldsCount.'.value') . ' LIKE ' . $db->q('%' . $search . '%')); + $query->where($db->qn('fv' . $filterFieldsCount . '.field_id') . ' = ' . $fieldId); + $query->where($db->qn('fv' . $filterFieldsCount . '.value') . ' LIKE ' . $db->q('%' . $search . '%')); $filterFieldFound = 1; $filterApplied = 1; @@ -358,12 +359,13 @@ private function filterContent() if ($filterFieldsCount > 1) { - $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . $db->qn('fv' . ($filterFieldsCount-1).'.content_id') . ' = ' . $db->qn('fv'.$filterFieldsCount.'.content_id') . ')'); + $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . + $db->qn('fv' . ($filterFieldsCount - 1) . '.content_id') . ' = ' . $db->qn('fv' . $filterFieldsCount . '.content_id') . ')'); } - $query->where($db->quoteName('fv'.$filterFieldsCount.'.value') . ' LIKE ' . $db->q('%' . $search . '%')); + $query->where($db->quoteName('fv' . $filterFieldsCount . '.value') . ' LIKE ' . $db->q('%' . $search . '%')); $filterApplied = 1; - } + } // For filterable fields JLoader::import('components.com_tjfields.models.fields', JPATH_ADMINISTRATOR); @@ -382,11 +384,12 @@ private function filterContent() if ($filterFieldsCount > 1) { - $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . $db->qn('fv' . ($filterFieldsCount-1).'.content_id') . ' = ' . $db->qn('fv'.$filterFieldsCount.'.content_id') . ')'); + $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . + $db->qn('fv' . ($filterFieldsCount - 1) . '.content_id') . ' = ' . $db->qn('fv' . $filterFieldsCount . '.content_id') . ')'); } - $query->where($db->qn('fv'.$filterFieldsCount.'.field_id') . ' = ' . $field->id); - $query->where($db->qn('fv'.$filterFieldsCount.'.value') . ' = ' . $db->q($filterValue)); + $query->where($db->qn('fv' . $filterFieldsCount . '.field_id') . ' = ' . $field->id); + $query->where($db->qn('fv' . $filterFieldsCount . '.value') . ' = ' . $db->q($filterValue)); $filterApplied = 1; } } From 048fab5fa6af4251b788b141d6f416385aaf945e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Wed, 6 Nov 2019 12:32:28 +0530 Subject: [PATCH 02/52] Bug #223 fix: Pagination not working as expected when we filter the content in the list view --- src/components/com_tjucm/site/models/items.php | 18 ++++++++---------- .../site/views/items/tmpl/default.php | 4 ---- .../site/views/items/tmpl/default_filters.php | 6 +++++- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/components/com_tjucm/site/models/items.php b/src/components/com_tjucm/site/models/items.php index bcda4f90..87f85bdc 100644 --- a/src/components/com_tjucm/site/models/items.php +++ b/src/components/com_tjucm/site/models/items.php @@ -93,7 +93,7 @@ protected function populateState($ordering = "a.id", $direction = "DESC") foreach ($fields as $field) { $filterValue = $app->getUserStateFromRequest($this->context . '.' . $field->name, $field->name, '', 'STRING'); - $this->setState('filter.field.' . $field->name, $filterValue); + $this->setState('filter.field.' . $field->name, $filterValue); } if (empty($ucmType)) @@ -272,7 +272,7 @@ protected function getListQuery() else { // If no search results found then do not return any record - $query->where($db->quoteName('a.id') . '=0'); + $query->where($db->quoteName('a.id') . '=0'); } } @@ -341,8 +341,8 @@ private function filterContent() } $search = trim(str_replace($field . ':', '', $search)); - $query->where($db->qn('fv'.$filterFieldsCount.'.field_id') . ' = ' . $fieldId); - $query->where($db->qn('fv'.$filterFieldsCount.'.value') . ' LIKE ' . $db->q('%' . $search . '%')); + $query->where($db->qn('fv' . $filterFieldsCount . '.field_id') . ' = ' . $fieldId); + $query->where($db->qn('fv' . $filterFieldsCount . '.value') . ' LIKE ' . $db->q('%' . $search . '%')); $filterFieldFound = 1; $filterApplied = 1; @@ -361,9 +361,9 @@ private function filterContent() $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . $db->qn('fv' . ($filterFieldsCount-1).'.content_id') . ' = ' . $db->qn('fv'.$filterFieldsCount.'.content_id') . ')'); } - $query->where($db->quoteName('fv'.$filterFieldsCount.'.value') . ' LIKE ' . $db->q('%' . $search . '%')); + $query->where($db->quoteName('fv' . $filterFieldsCount . '.value') . ' LIKE ' . $db->q('%' . $search . '%')); $filterApplied = 1; - } + } // For filterable fields JLoader::import('components.com_tjfields.models.fields', JPATH_ADMINISTRATOR); @@ -385,14 +385,12 @@ private function filterContent() $query->join('LEFT', $db->qn('#__tjfields_fields_value', 'fv' . $filterFieldsCount) . ' ON (' . $db->qn('fv' . ($filterFieldsCount-1).'.content_id') . ' = ' . $db->qn('fv'.$filterFieldsCount.'.content_id') . ')'); } - $query->where($db->qn('fv'.$filterFieldsCount.'.field_id') . ' = ' . $field->id); - $query->where($db->qn('fv'.$filterFieldsCount.'.value') . ' = ' . $db->q($filterValue)); + $query->where($db->qn('fv' . $filterFieldsCount . '.field_id') . ' = ' . $field->id); + $query->where($db->qn('fv' . $filterFieldsCount . '.value') . ' = ' . $db->q($filterValue)); $filterApplied = 1; } } - $query->setLimit($this->getState('list.limit')); - // If there is any filter applied then only execute the query if ($filterApplied) { diff --git a/src/components/com_tjucm/site/views/items/tmpl/default.php b/src/components/com_tjucm/site/views/items/tmpl/default.php index 2db9ffdb..61e0c4b5 100644 --- a/src/components/com_tjucm/site/views/items/tmpl/default.php +++ b/src/components/com_tjucm/site/views/items/tmpl/default.php @@ -33,10 +33,6 @@ $appendUrl .= "&client=" . $this->client; } -$tmpListColumn = $this->listcolumn; -reset($tmpListColumn); -$firstListColumn = key($tmpListColumn); - $link = 'index.php?option=com_tjucm&view=items' . $appendUrl; $itemId = $tjUcmFrontendHelper->getItemId($link); $fieldsData = array(); diff --git a/src/components/com_tjucm/site/views/items/tmpl/default_filters.php b/src/components/com_tjucm/site/views/items/tmpl/default_filters.php index 769b7066..945418ea 100644 --- a/src/components/com_tjucm/site/views/items/tmpl/default_filters.php +++ b/src/components/com_tjucm/site/views/items/tmpl/default_filters.php @@ -11,6 +11,10 @@ defined('_JEXEC') or die; use Joomla\CMS\Component\ComponentHelper; + +$tmpListColumn = $this->listcolumn; +reset($tmpListColumn); +$firstListColumn = key($tmpListColumn); ?>
@@ -81,4 +85,4 @@ } ?>
-

\ No newline at end of file +

From 21858986c7008d30e43ba2c6bf67cbeef9b8368b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Wed, 6 Nov 2019 12:58:48 +0530 Subject: [PATCH 03/52] Bug #223 fix: Pagination not working as expected when we filter the content in the list view --- src/components/com_tjucm/site/models/items.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/com_tjucm/site/models/items.php b/src/components/com_tjucm/site/models/items.php index 87f85bdc..ba3d53d4 100644 --- a/src/components/com_tjucm/site/models/items.php +++ b/src/components/com_tjucm/site/models/items.php @@ -391,6 +391,9 @@ private function filterContent() } } + $query->order('fv1.content_id DESC'); + $query->group('fv1.content_id'); + // If there is any filter applied then only execute the query if ($filterApplied) { From 74f05ef23657665fbe0caf8e3d7491064e50359a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Wed, 6 Nov 2019 17:22:04 +0530 Subject: [PATCH 04/52] Bug #225 fix: Navigation buttons are not visible if there are multiple tabs and auto save and save as draft is disabled --- .../languages/site/en-GB/en-GB.com_tjucm.ini | 8 +++--- .../site/views/itemform/tmpl/default.php | 28 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/components/com_tjucm/languages/site/en-GB/en-GB.com_tjucm.ini b/src/components/com_tjucm/languages/site/en-GB/en-GB.com_tjucm.ini index eb9f7ded..3f359642 100644 --- a/src/components/com_tjucm/languages/site/en-GB/en-GB.com_tjucm.ini +++ b/src/components/com_tjucm/languages/site/en-GB/en-GB.com_tjucm.ini @@ -150,14 +150,14 @@ COM_TJUCM_TYPES_ADD_NEW_DATA_URL="Create Item" COM_TJUCM_NEXT_BUTTON="Next" COM_TJUCM_PREVIOUS_BUTTON="Previous" COM_TJUCM_CANCEL_BUTTON="Cancel" -COM_TJUCM_SAVE_ITEM="Submit Section" -COM_TJUCM_SAVE_AS_DRAFT_ITEM="Save Section Progress" +COM_TJUCM_SAVE_ITEM="Submit" +COM_TJUCM_SAVE_AS_DRAFT_ITEM="Save Progress" COM_TJUCM_NOTE_ON_FORM="Please make sure you have filled all the fields before you submit the form" COM_TJUCM_MSG_ON_SAVED_FORM="Data saved successfully." -COM_TJUCM_MSG_ON_DRAFT_FORM="Section saved as draft successfully" +COM_TJUCM_MSG_ON_DRAFT_FORM="Saved as draft successfully" COM_TJUCM_ALLOWED_COUNT_LIMIT="You are allowed to fill this form upto %d time(s) only" COM_TJUCM_NO_FIELDS_TO_SHOW_ON_LIST_VIEW="Please set 'Show on list view' to 'yes' for at least one field of this UCM type" -COM_TJUCM_ITEMFORM_SUBMIT_ALERT="Are you sure you want to submit this section?"; +COM_TJUCM_ITEMFORM_SUBMIT_ALERT="Are you sure you want to submit this form?"; COM_TJUCM_NO_ACTIVITIES="There are no activities here yet" COM_TJUCM_SAVE_FAILED="Save failed: %s" COM_TJUCM_DELETE_FAILED="Delete failed: %s" diff --git a/src/components/com_tjucm/site/views/itemform/tmpl/default.php b/src/components/com_tjucm/site/views/itemform/tmpl/default.php index 89f2358d..561d185e 100644 --- a/src/components/com_tjucm/site/views/itemform/tmpl/default.php +++ b/src/components/com_tjucm/site/views/itemform/tmpl/default.php @@ -162,23 +162,23 @@ if (isset($setnavigation) && $setnavigation == true) { - if (!empty($this->allow_draft_save)) - { - ?> - - - + + + + + allow_auto_save || $this->allow_draft_save) && $itemState) { ?> @@ -190,6 +190,8 @@ ?> " id="tjUcmSectionFinalSave" onclick="tjUcmItemForm.saveUcmFormData();" /> + " onclick="Joomla.submitbutton('itemform.cancel');" /> + From 90b3423793678574e700fd67f90c8bb07722e319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Thu, 7 Nov 2019 16:54:32 +0530 Subject: [PATCH 05/52] Task #227 fix: Unused code in repo --- .../site/controllers/itemform.json.php | 53 +- .../com_tjucm/site/controllers/itemform.php | 445 +------------- src/components/com_tjucm/site/models/item.php | 123 ---- .../com_tjucm/site/models/itemform.php | 566 +----------------- .../com_tjucm/site/models/items.php | 80 --- 5 files changed, 32 insertions(+), 1235 deletions(-) diff --git a/src/components/com_tjucm/site/controllers/itemform.json.php b/src/components/com_tjucm/site/controllers/itemform.json.php index f5f3a285..95683603 100644 --- a/src/components/com_tjucm/site/controllers/itemform.json.php +++ b/src/components/com_tjucm/site/controllers/itemform.json.php @@ -63,52 +63,6 @@ public function __construct() parent::__construct(); } - /** - * Method to check if you can add a new record. - * - * Extended classes can override this if necessary. - * - * @param array $data An array of input data. - * - * @return boolean - * - * @since 12.2 - */ - protected function allowAdd($data = array()) - { - $user = Factory::getUser(); - - return $user->authorise('core.type.createitem', 'com_tjucm.type.' . $this->ucmTypeId); - } - - /** - * Method to check if you can edit an existing record. - * - * Extended classes can override this if necessary. - * - * @param array $data An array of input data. - * @param string $key The name of the key for the primary key; default is id. - * - * @return boolean - * - * @since 12.2 - */ - protected function allowEdit($data = array(), $key = 'id') - { - $user = Factory::getUser(); - $edit = $user->authorise('core.type.edititem', 'com_tjucm.type.' . $this->ucmTypeId); - $editOwn = $user->authorise('core.type.editownitem', 'com_tjucm.type.' . $this->ucmTypeId); - - if ($edit || $editOwn) - { - return true; - } - else - { - return false; - } - } - /** * Function to save ucm data item * @@ -472,6 +426,13 @@ private function processErrors($errors) } } + /** + * Method to get updated list of options for related field + * + * @return void + * + * @since 1.2.1 + */ public function getRelatedFieldOptions() { JSession::checkToken() or jexit(Text::_('JINVALID_TOKEN')); diff --git a/src/components/com_tjucm/site/controllers/itemform.php b/src/components/com_tjucm/site/controllers/itemform.php index 0517aa72..8f64a208 100644 --- a/src/components/com_tjucm/site/controllers/itemform.php +++ b/src/components/com_tjucm/site/controllers/itemform.php @@ -18,8 +18,6 @@ jimport('joomla.filesystem.file'); -require_once JPATH_SITE . "/components/com_tjfields/filterFields.php"; - /** * Item controller class. * @@ -27,9 +25,6 @@ */ class TjucmControllerItemForm extends JControllerForm { - // Use imported Trait in model - use TjfieldsFilterField; - /** * Constructor * @@ -90,66 +85,6 @@ public function __construct() parent::__construct(); } - /** - * Method to add a new record. - * - * @return boolean True if the record can be added, false if not. - * - * @since 12.2 - */ - public function add() - { - $app = Factory::getApplication(); - $context = "$this->option.edit.$this->context"; - - $tjUcmFrontendHelper = new TjucmHelpersTjucm; - - // Access check. - if (!$this->allowAdd()) - { - // Set the internal error and also the redirect error. - $this->setError(Text::_('JLIB_APPLICATION_ERROR_CREATE_RECORD_NOT_PERMITTED')); - $this->setMessage($this->getError(), 'error'); - - $link = 'index.php?option=com_tjucm&view=items' . $this->appendUrl; - $itemId = $tjUcmFrontendHelper->getItemId($link); - - $this->setRedirect(Route::_($link . '&Itemid=' . $itemId . $this->getRedirectToListAppend(), false)); - - return false; - } - - // Clear the record edit information from the session. - $app->setUserState($context . '.data', null); - - $clusterId = $app->input->getInt('cluster_id', 0); - $cluster = ''; - - // Check cluster exist - if ($clusterId) - { - $cluster = '&cluster_id=' . $clusterId; - } - - // Redirect to the edit screen. - $link = 'index.php?option=com_tjucm&view=itemform&client=' . $this->client; - $itemId = $tjUcmFrontendHelper->getItemId($link); - - $this->setRedirect(Route::_($link . '&Itemid=' . $itemId . $cluster . $this->getRedirectToItemAppend(), false)); - - return true; - } - - /** - * Function to apply field data changes - * - * @return void - */ - public function apply() - { - $this->save(); - } - /** * Method to check out an item for editing and redirect to the edit form. * @@ -197,338 +132,6 @@ public function edit($key = null, $urlVar = null) $this->setRedirect(Route::_('index.php?option=com_tjucm&view=itemform' . $recordId . '&Itemid=' . $itemId, false)); } - /** - * Method to save a record. - * - * @param string $key The name of the primary key of the URL variable. - * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). - * - * @return boolean True if successful, false otherwise. - * - * @since 12.2 - */ - public function save($key = null, $urlVar = null) - { - // Check for request forgeries. - Session::checkToken() or jexit(Text::_('JINVALID_TOKEN')); - $app = Factory::getApplication(); - $lang = Factory::getLanguage(); - $model = $this->getModel(); - $task = $this->getTask(); - $formStatus = $app->input->get('form_status', '', 'STRING'); - - // Set client value - $model->setClient($this->client); - - $table = $model->getTable(); - - // Get the user data. - $data = $app->input->get('jform', array(), 'array'); - $data['id'] = empty($data['id']) ? 0 : (int) $data['id']; - $all_jform_data = $data; - - // Get file information - $files = $app->input->files->get('jform'); - - // Jform tweak - Get all posted data. - $post = $app->input->post; - - // Populate the row id from the session. - - // $data[$key] = $recordId; - - // The save2copy task needs to be handled slightly differently. - if ($task == 'save2copy') - { - // Check-in the original row. - if ($checkin && $model->checkin($data[$key]) === false) - { - // Check-in failed. Go back to the item and display a notice. - $this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError())); - $this->setMessage($this->getError(), 'error'); - - echo new JResponseJson(null); - jexit(); - } - - // Reset the ID, the multilingual associations and then treat the request as for Apply. - $data[$key] = 0; - $data['associations'] = array(); - $task = 'apply'; - } - - // Access check. - if (!$this->allowSave($data, $key)) - { - $this->setError(Text::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED')); - $this->setMessage($this->getError(), 'error'); - - echo new JResponseJson(null); - jexit(); - } - - // Validate the posted data. - // Sometimes the form needs some posted data, such as for plugins and modules. - $form = $model->getForm($data, false); - - if (!$form) - { - $app->enqueueMessage($model->getError(), 'error'); - - echo new JResponseJson(null); - jexit(); - } - - // Test whether the data is valid. - $validData = $model->validate($form, $data); - - // Check for validation errors. - if ($validData === false) - { - // Get the validation messages. - $errors = $model->getErrors(); - - // Push up to three validation messages out to the user. - for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) - { - if ($errors[$i] instanceof Exception) - { - $app->enqueueMessage($errors[$i]->getMessage(), 'error'); - } - else - { - $app->enqueueMessage($errors[$i], 'error'); - } - } - - echo new JResponseJson(null); - jexit(); - } - - // Jform tweaking - get data for extra fields jform. - $extra_jform_data = array_diff_key($all_jform_data, $validData); - - // Check if form file is present. - jimport('joomla.filesystem.file'); - /* Explode client 1. Componet name 2.type */ - $client = explode(".", $this->client); - /* End */ - - $filePath = JPATH_ADMINISTRATOR . '/components/com_tjucm/models/forms/' . $client[1] . '_extra.xml'; - - if (JFile::exists($filePath)) - { - // Validate the posted data. - $formExtra = $model->getFormExtra( - array( - "category" => isset($data['category_id']) ? $data['category_id'] : '', - "clientComponent" => 'com_tjucm', - "client" => $this->client, - "view" => $client[1], - "layout" => 'edit', ) - ); - - if (!$formExtra) - { - JError::raiseWarning(500, $model->getError()); - - return false; - } - - if (!empty($formExtra)) - { - // Remove required attribute from fields if data is stored in draft mode - if ($formStatus == 'draft') - { - $validData['draft'] = 1; - $fieldSets = $formExtra->getFieldsets(); - - foreach ($fieldSets as $fieldset) - { - foreach ($formExtra->getFieldset($fieldset->name) as $field) - { - $formExtra->setFieldAttribute($field->fieldname, 'required', false); - $formExtra->setFieldAttribute($field->fieldname, 'validate', ''); - } - } - } - else - { - $validData['draft'] = 0; - } - - // Remove the fields having empty value from both the array before merge - if (is_array($data)) - { - $data = array_filter($data); - } - - if (is_array($files)) - { - $files = array_filter($files); - } - - /* If file field is required then in the validation method return false - * * so that we will mearge $data and $ files array using array_merge function - * * and pass to the validation funcation.*/ - - if (!empty($files)) - { - $extra_jform_data = array_merge_recursive($data, $files); - } - - // Validate the posted extra data. - $extra_jform_data = $model->validateExtra($formExtra, $extra_jform_data); - } - - // Check for errors. - if ($extra_jform_data === false) - { - // Get the validation messages. - $errors = $model->getErrors(); - - // Push up to three validation messages out to the user. - for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) - { - if ($errors[$i] instanceof Exception) - { - $app->enqueueMessage($errors[$i]->getMessage(), 'error'); - } - else - { - $app->enqueueMessage($errors[$i], 'error'); - } - } - - echo new JResponseJson(null); - jexit(); - } - } - - if (!isset($validData['tags'])) - { - $validData['tags'] = null; - } - - $response = ''; - - try - { - $status_title = $app->input->get('form_status'); - $validData['status'] = $status_title; - - if (!empty($files)) - { - $extra_jform_data['tjFieldFileField'] = $files; - } - - // If no data send then dont add any entry in item form table - start - $allow = 0; - - foreach ($extra_jform_data as $extra_data) - { - if ($extra_data != '') - { - $allow = 1; - - break; - } - } - - if (empty($allow)) - { - $app->enqueueMessage(Text::_("COM_TJUCM_NO_FORM_DATA"), 'error'); - - echo new JResponseJson(null); - jexit(); - } - - // Set cluster values to store in core UCM table values - $model->setClusterData($validData, $data); - - // Get sorted dataset of submitted ucmsubform records as per their client - $ucmSubFormDataSet = $model->getFormattedUcmSubFormRecords($validData, $extra_jform_data); - - $isNew = empty($validData['id']) ? 1 : 0; - - // Save parent form record - $recordId = $model->save($validData, $extra_jform_data); - $validData['parent_id'] = $recordId; - - // Save ucmSubForm records - if (!empty($ucmSubFormDataSet)) - { - $subFormContentIds = $model->saveUcmSubFormRecords($validData, $ucmSubFormDataSet); - } - - // Get updated options for related fields - $app->input->set('id', $recordId); - $updatedRelatedFieldsOptions = $model->getUdatedRelatedFieldOptions($recordId); - - if ($recordId === false) - { - echo new JResponseJson(null); - jexit(); - } - - if ($recordId) - { - $validData['id'] = $recordId; - - $dispatcher = JEventDispatcher::getInstance(); - JPluginHelper::importPlugin("system", "jlike_tjucm"); - $dispatcher->trigger('jlike_tjucmOnAfterSave', array($recordId, $validData)); - - // TJ-ucm plugin trigger after save - $dispatcher = JEventDispatcher::getInstance(); - JPluginHelper::importPlugin("content"); - $dispatcher->trigger('onUcmItemAfterSave', array($validData, $extra_jform_data, $isNew)); - - $response = $recordId; - $redirect_url = ''; - $redirect_msg = ''; - } - } - catch (Exception $e) - { - $response = $e; - $redirect_url = ''; - $redirect_msg = $e->getMessage(); - } - - if ($this->isajax) - { - if (!empty($response)) - { - $response = array('id' => $response); - - // Add subform record ids in the response - if (isset($subFormContentIds) && !empty($subFormContentIds)) - { - $response['childContentIds'] = $subFormContentIds; - } - - // Add updated options of related fields in the response - if (!empty($updatedRelatedFieldsOptions)) - { - $response['relatedFieldOptions'] = $updatedRelatedFieldsOptions; - } - } - - echo new JResponseJson($response); - jexit(); - } - else - { - $app->redirect($redirect_url, $redirect_msg); - } - - // Invoke the postSave method to allow for the child class to access the model. - $this->postSaveHook($model, $validData); - - return true; - } - /** * Method to cancel an edit. * @@ -665,58 +268,12 @@ public function redirectToListView($typeId, $allowedCount) Factory::getApplication()->redirect($link, sprintf(Text::_('COM_TJUCM_ALLOWED_COUNT_LIMIT'), $allowedCount), "Warning"); } - /** - * Method to check if you can add a new record. - * - * Extended classes can override this if necessary. - * - * @param array $data An array of input data. - * - * @return boolean - * - * @since 12.2 - */ - protected function allowAdd($data = array()) - { - $user = Factory::getUser(); - - return $user->authorise('core.type.createitem', 'com_tjucm.type.' . $this->ucmTypeId); - } - - /** - * Method to check if you can edit an existing record. - * - * Extended classes can override this if necessary. - * - * @param array $data An array of input data. - * @param string $key The name of the key for the primary key; default is id. - * - * @return boolean - * - * @since 12.2 - */ - protected function allowEdit($data = array(), $key = 'id') - { - $user = Factory::getUser(); - $edit = $user->authorise('core.type.edititem', 'com_tjucm.type.' . $this->ucmTypeId); - $editOwn = $user->authorise('core.type.editownitem', 'com_tjucm.type.' . $this->ucmTypeId); - - if ($edit || $editOwn) - { - return true; - } - else - { - return false; - } - } - /** * Method to check out an item for copying and redirect to the edit form. * * @return void * - * @since __DEPLOY_VERSION__ + * @since 1.2.1 */ public function prepareForCopy() { diff --git a/src/components/com_tjucm/site/models/item.php b/src/components/com_tjucm/site/models/item.php index 02e31596..973a20be 100644 --- a/src/components/com_tjucm/site/models/item.php +++ b/src/components/com_tjucm/site/models/item.php @@ -241,109 +241,6 @@ public function getTable($type = 'Item', $prefix = 'TjucmTable', $config = array return JTable::getInstance($type, $prefix, $config); } - /** - * Get the id of an item by alias - * - * @param string $alias Item alias - * - * @return mixed - */ - public function getItemIdByAlias($alias) - { - $table = $this->getTable(); - - $table->load(array('alias' => $alias)); - - return $table->id; - } - - /** - * Method to check in an item. - * - * @param integer $id The id of the row to check out. - * - * @return boolean True on success, false on failure. - * - * @since 1.6 - */ - public function checkin($id = null) - { - // Get the id. - $id = (!empty($id)) ? $id : (int) $this->getState('item.id'); - - if ($id) - { - // Initialise the table - $table = $this->getTable(); - - // Attempt to check the row in. - if (method_exists($table, 'checkin')) - { - if (!$table->checkin($id)) - { - return false; - } - } - } - - return true; - } - - /** - * Method to check out an item for editing. - * - * @param integer $id The id of the row to check out. - * - * @return boolean True on success, false on failure. - * - * @since 1.6 - */ - public function checkout($id = null) - { - // Get the user id. - $id = (!empty($id)) ? $id : (int) $this->getState('item.id'); - - if ($id) - { - // Initialise the table - $table = $this->getTable(); - - // Get the current user object. - $user = JFactory::getUser(); - - // Attempt to check the row out. - if (method_exists($table, 'checkout')) - { - if (!$table->checkout($user->get('id'), $id)) - { - return false; - } - } - } - - return true; - } - - /** - * Get the name of a category by id - * - * @param int $id Category id - * - * @return Object|null Object if success, null in case of failure - */ - public function getCategoryName($id) - { - $db = JFactory::getDbo(); - $query = $db->getQuery(true); - $query - ->select('title') - ->from('#__categories') - ->where('id = ' . $id); - $db->setQuery($query); - - return $db->loadObject(); - } - /** * Publish the element * @@ -391,26 +288,6 @@ public function delete(&$id) } } - /** - * Method to getAliasFieldNameByView - * - * @param array $view An array of record primary keys. - * - * @return boolean True if successful, false if an error occurs. - * - * @since 1.0 - */ - public function getAliasFieldNameByView($view) - { - switch ($view) - { - case 'type': - case 'typeform': - return 'alias'; - break; - } - } - /** * Method to check if a user has permissions to view ucm items of given type * diff --git a/src/components/com_tjucm/site/models/itemform.php b/src/components/com_tjucm/site/models/itemform.php index 32175e0a..d42cd838 100644 --- a/src/components/com_tjucm/site/models/itemform.php +++ b/src/components/com_tjucm/site/models/itemform.php @@ -241,89 +241,6 @@ public function getTable($type = 'Item', $prefix = 'TjucmTable', $config = array return JTable::getInstance($type, $prefix, $config); } - /** - * Get an item by alias - * - * @param string $alias Alias string - * - * @return int Element id - */ - public function getItemIdByAlias($alias) - { - $table = $this->getTable(); - - $table->load(array('alias' => $alias)); - - return $table->id; - } - - /** - * Method to check in an item. - * - * @param integer $id The id of the row to check out. - * - * @return boolean True on success, false on failure. - * - * @since 1.6 - */ - public function checkin($id = null) - { - // Get the id. - $id = (!empty($id)) ? $id : (int) $this->getState('item.id'); - - if ($id) - { - // Initialise the table - $table = $this->getTable(); - - // Attempt to check the row in. - if (method_exists($table, 'checkin')) - { - if (!$table->checkin($id)) - { - return false; - } - } - } - - return true; - } - - /** - * Method to check out an item for editing. - * - * @param integer $id The id of the row to check out. - * - * @return boolean True on success, false on failure. - * - * @since 1.6 - */ - public function checkout($id = null) - { - // Get the user id. - $id = (!empty($id)) ? $id : (int) $this->getState('item.id'); - - if ($id) - { - // Initialise the table - $table = $this->getTable(); - - // Get the current user object. - $user = JFactory::getUser(); - - // Attempt to check the row out. - if (method_exists($table, 'checkout')) - { - if (!$table->checkout($user->get('id'), $id)) - { - return false; - } - } - } - - return true; - } - /** * Get an array of data items * @@ -336,16 +253,6 @@ public function setClient($client) $this->client = $client; } - /** - * Get an client value - * - * @return mixed Array of data items on success, false on failure. - */ - public function getClient() - { - return $this->client; - } - /** * Method to get the record form. * @@ -382,7 +289,7 @@ public function getForm($data = array(), $loadData = true) * * @return JForm A JForm object on success, false on failure * - * @since 1.6 + * @since 1.2.2 */ public function getFieldForm($data = array(), $loadData = true) { @@ -430,6 +337,16 @@ public function getFieldForm($data = array(), $loadData = true) return $form; } + /** + * Method to get the type form object. + * + * @param array $data An optional array of data for the form to interogate. + * @param boolean $loadData True if the form is to load its own data (default case), false if not. + * + * @return JForm A JForm object on success, false on failure + * + * @since 1.2.2 + */ public function getTypeForm($data = array(), $loadData = true) { $draft = isset($data['draft']) ? $data['draft'] : 0; @@ -468,6 +385,16 @@ public function getTypeForm($data = array(), $loadData = true) return $form; } + /** + * Method to get the type section form object. + * + * @param array $data An optional array of data for the form to interogate. + * @param boolean $loadData True if the form is to load its own data (default case), false if not. + * + * @return JForm A JForm object on success, false on failure + * + * @since 1.2.2 + */ public function getSectionForm($data = array(), $loadData = true) { if (empty($data['client']) || empty($data['section'])) @@ -710,266 +637,6 @@ public function saveExtraFields($fieldData) return TjfieldsFilterField::saveExtraFields($fieldData); } - /** - * Method to save the form data. - * - * @param array $data The form data. - * @param array $extra_jform_data Exra field data. - * - * @return boolean - * - * @since 1.6 - */ - public function saveTOBEDELETED($data, $extra_jform_data = '') - { - $app = JFactory::getApplication(); - $user = JFactory::getUser(); - $status_title = $app->input->get('form_status'); - $ucmTypeId = $this->getState('ucmType.id'); - $typeItemId = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('item.id'); - $authorised = false; - - JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/models'); - $tjUcmModelType = JModelLegacy::getInstance('Type', 'TjucmModel'); - - if (empty($ucmTypeId)) - { - // Get UCM type id from uniquue identifier - $ucmTypeId = $tjUcmModelType->getTypeId($data['client']); - } - - if ($ucmTypeId) - { - // Check if user is allowed to save the content - $typeData = $tjUcmModelType->getItem($ucmTypeId); - $allowedCount = $typeData->allowed_count; - - // 0 : add unlimited records against this UCM type - $allowedCount = empty($allowedCount) ? 0 : $allowedCount; - $userId = $user->id; - $allowedToAdd = $this->allowedToAddTypeData($userId, $data['client'], $allowedCount); - - if (!$allowedToAdd && $typeItemId == 0) - { - $message = JText::sprintf('COM_TJUCM_ALLOWED_COUNT_LIMIT', $allowedCount); - $app->enqueueMessage($message, 'warning'); - - return false; - } - - if ($typeItemId) - { - // Check the user can edit this item - $canEdit = $user->authorise('core.type.edititem', 'com_tjucm.type.' . $ucmTypeId); - $canEditOwn = $user->authorise('core.type.editownitem', 'com_tjucm.type.' . $ucmTypeId); - - // Get the UCM item details - Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/tables'); - $itemDetails = Table::getInstance('Item', 'TjucmTable'); - $itemDetails->load(array('id' => $typeItemId)); - - // If there is ownership field in form and the field is assigned some value then update created_by for the record - $client = explode(".", $itemDetails->client); - $ownershipField = $client[0] . '_' . $client[1] . '_ownershipcreatedby'; - - if (isset($extra_jform_data[$ownershipField]) && !empty($extra_jform_data[$ownershipField])) - { - JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); - $ownershipFieldData = Table::getInstance('Field', 'TjfieldsTable'); - $ownershipFieldData->load(array('name' => $ownershipField)); - $ownershipFieldParams = json_decode($ownershipFieldData->params); - - if ($ownershipFieldParams->ucmItemOwner == 1) - { - $data['created_by'] = $extra_jform_data[$ownershipField]; - } - } - else - { - $data['created_by'] = $itemDetails->created_by; - } - - if ($canEdit) - { - $authorised = true; - } - elseif (($canEditOwn) && ($itemDetails->created_by == $user->id)) - { - if (!empty($data['created_by']) && $itemDetails->created_by == $data['created_by']) - { - $authorised = true; - } - } - } - else - { - // Check the user can create new items in this section - $authorised = $user->authorise('core.type.createitem', 'com_tjucm.type.' . $ucmTypeId); - } - } - - if ($authorised !== true) - { - throw new Exception(JText::_('COM_TJUCM_ERROR_MESSAGE_NOT_AUTHORISED'), 403); - - return false; - } - - $ucmTypeData = $this->common->getDataValues('#__tj_ucm_types', 'id AS type_id, params', 'unique_identifier = "' - . $data['client'] . '"', 'loadAssoc'); - - $data['type_id'] = empty($data['type_id']) ? $ucmTypeData['type_id'] : $data['type_id']; - - $ucmTypeParams = json_decode($ucmTypeData['params']); - - $table = $this->getTable(); - - if (isset($ucmTypeParams->publish_items) && $ucmTypeParams->publish_items == 0) - { - $data['state'] = 0; - } - else - { - $data['state'] = 1; - } - - // To store fields value in TJ-Fields - $data_extra = array(); - - if (!empty($extra_jform_data)) - { - $data_extra['client'] = $data['client']; - $data_extra['fieldsvalue'] = $extra_jform_data; - } - - $isNew = empty($typeItemId) ? 1 : 0; - - // OnBefore UCM record save trigger. - JPluginHelper::importPlugin('tjucm'); - $dispatcher = JDispatcher::getInstance(); - $dispatcher->trigger('tjucmOnBeforeSaveItem', array(&$data, &$data_extra, $isNew)); - - // Load TJ-Fields tables - Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/tables'); - - // If item category field is added in the type then save item category agains the item record - foreach ($extra_jform_data as $fieldName => $fieldData) - { - $fieldTable = Table::getInstance('Field', 'TjfieldsTable'); - $fieldTable->load(array('name' => $fieldName)); - - if ($fieldTable->type == 'itemcategory') - { - $data['category_id'] = $fieldData; - - break; - } - } - - if ($table->save($data) === true) - { - if (!empty($extra_jform_data)) - { - $data_extra['content_id'] = $table->id; - - // Save extra fields data. - $this->saveExtraFields($data_extra); - } - - $data['id'] = $table->id; - - // OnAfter UCM record save trigger. - $dispatcher->trigger('tjucmOnAfterSaveItem', array($data, $data_extra)); - - return $table->id; - } - else - { - throw new Exception($table->getError()); - } - } - - /** - * Method to duplicate an Item - * - * @param array &$pks An array of primary key IDs. - * - * @return boolean True if successful. - * - * @throws Exception - */ - public function duplicate(&$pks) - { - $user = JFactory::getUser(); - $ucmTypeId = $this->getState('ucmType.id'); - - // Access checks. - if (!$user->authorise('core.type.createitem', 'com_tjucm.type.' . $ucmTypeId)) - { - throw new Exception(JText::_('JERROR_CORE_CREATE_NOT_PERMITTED')); - - return false; - } - - $dispatcher = JEventDispatcher::getInstance(); - $context = $this->option . '.' . $this->name; - - // Include the plugins for the save events. - JPluginHelper::importPlugin($this->events_map['save']); - - $table = $this->getTable(); - - foreach ($pks as $pk) - { - if ($table->load($pk, true)) - { - // Reset the id to create a new record. - $table->id = 0; - - if (!$table->check()) - { - throw new Exception($table->getError()); - - return false; - } - - if (!empty($table->type_id)) - { - if (is_array($table->type_id)) - { - $table->type_id = implode(',', $table->type_id); - } - } - else - { - $table->type_id = ''; - } - - // Trigger the before save event. - $result = $dispatcher->trigger($this->event_before_save, array($context, &$table, true)); - - if (in_array(false, $result, true) || !$table->store()) - { - throw new Exception($table->getError()); - } - - // Trigger the after save event. - $dispatcher->trigger($this->event_after_save, array($context, &$table, true)); - } - else - { - throw new Exception($table->getError()); - - return false; - } - } - - // Clean cache - $this->cleanCache(); - - return true; - } - /** * Method to delete data * @@ -1050,38 +717,6 @@ public function delete(&$contentId) } } - /** - * Check if data can be saved - * - * @return bool - */ - public function getCanSave() - { - $table = $this->getTable(); - - return $table !== false; - } - - /** - * Method to getAliasFieldNameByView - * - * @param array $view An array of record primary keys. - * - * @return boolean True if successful, false if an error occurs. - * - * @since 1.0 - */ - public function getAliasFieldNameByView($view) - { - switch ($view) - { - case 'type': - case 'typeform': - return 'alias'; - break; - } - } - /** * Check if user is submit new type data or not * @@ -1125,161 +760,6 @@ public function allowedToAddTypeData($userId, $client, $allowedCount) } } - /** - * Method to set cluster data in posted data. - * - * @param array &$validData The validated data. - * - * @param array $data UCM form data. - * - * @return null - * - * @since 1.6 - */ - public function setClusterData(&$validData, $data) - { - $clusterField = $ownershipField = ''; - - // To get type of UCM - if (!empty($this->client)) - { - $client = explode(".", $this->client); - $clusterField = $client[0] . '_' . $client[1] . '_clusterclusterid'; - $ownershipField = $client[0] . '_' . $client[1] . '_ownershipcreatedby'; - } - - JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); - $ownershipFieldData = Table::getInstance('Field', 'TjfieldsTable'); - $ownershipFieldData->load(array('name' => $ownershipField)); - $ownershipFieldParams = json_decode($ownershipFieldData->params); - - // Save created_by field by ownership user field (To save form on behalf of someone) - if (!empty($data[$ownershipField]) && empty($data[$clusterField]) && ($ownershipFieldParams->ucmItemOwner == 1)) - { - $validData['created_by'] = $data[$ownershipField]; - } - - // Cluster Id store in UCM data - $clusterExist = ComponentHelper::getComponent('com_cluster', true)->enabled; - - if (!empty($data[$clusterField]) && $clusterExist) - { - $user = Factory::getUser(); - $isSuperUser = $user->authorise('core.admin'); - - JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR); - $ClusterModel = ClusterFactory::model('ClusterUsers', array('ignore_request' => true)); - $ClusterModel->setState('list.group_by_user_id', 1); - $ClusterModel->setState('filter.published', 1); - $ClusterModel->setState('filter.cluster_id', (int) $data[$clusterField]); - - if (!$isSuperUser && !$user->authorise('core.manageall', 'com_cluster')) - { - $ClusterModel->setState('filter.user_id', $user->id); - } - - // Get all assigned cluster entries - $clusters = $ClusterModel->getItems(); - - if (!empty($clusters)) - { - $validData['cluster_id'] = $data[$clusterField]; - - if (!empty($data[$ownershipField])) - { - $clusterUsers = array(); - - foreach ($clusters as $cluster) - { - $clusterUsers[] = $cluster->user_id; - } - - if (in_array($data[$ownershipField], $clusterUsers) && ($ownershipFieldParams->ucmItemOwner == 1)) - { - $validData['created_by'] = $data[$ownershipField]; - } - } - } - } - } - - /** - * Function to get formatted data to be added of ucmsubform records - * - * @param ARRAY $validData Parent record data - * @param ARRAY &$extra_jform_data form data - * - * @return ARRAY - */ - public function getFormattedUcmSubFormRecords($validData, &$extra_jform_data) - { - JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/models'); - $tjUcmModelType = JModelLegacy::getInstance('Type', 'TjucmModel'); - - JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/models'); - $tjFieldsFieldsModel = JModelLegacy::getInstance('Fields', 'TjfieldsModel', array('ignore_request' => true)); - $tjFieldsFieldsModel->setState('filter.client', $validData['client']); - $tjFieldsFieldsModel->setState('filter.type', 'ucmsubform'); - - // Get list of ucmsubform fields in the parent form - $ucmSubFormFields = $tjFieldsFieldsModel->getItems(); - - // Variable to store ucmsubform records posted in the form - $ucmSubFormDataSet = array(); - - // Sort all the ucmsubform records as per client - foreach ($ucmSubFormFields as $ucmSubFormField) - { - if (!isset($extra_jform_data[$ucmSubFormField->name])) - { - continue; - } - - $subformRecords = $extra_jform_data[$ucmSubFormField->name]; - - if (!empty($subformRecords)) - { - $ucmSubFormData = array(); - - foreach ($subformRecords as $key => $subformRecord) - { - // Append file data to the ucmSubForm data - if (array_key_exists('tjFieldFileField', $extra_jform_data)) - { - if (isset($extra_jform_data['tjFieldFileField'][$ucmSubFormField->name][$key])) - { - $subformRecord['tjFieldFileField'] = $extra_jform_data['tjFieldFileField'][$ucmSubFormField->name][$key]; - } - } - - $subformRecord = array_filter($subformRecord); - - if (!empty($subformRecord)) - { - // Add ucmSubFormFieldName in the data to pass data to JS - $subformRecord['ucmSubformFieldName'] = $ucmSubFormField->name; - - $ucmSubFormData[] = $subformRecord; - } - } - - if (!empty($ucmSubFormData)) - { - $ucmSubFormFieldParams = json_decode($ucmSubFormField->params); - $ucmSubFormFormSource = explode('/', $ucmSubFormFieldParams->formsource); - $ucmSubFormClient = $ucmSubFormFormSource[1] . '.' . str_replace('form_extra.xml', '', $ucmSubFormFormSource[4]); - $ucmSubFormDataSet[$ucmSubFormClient] = $ucmSubFormData; - $extra_jform_data[$ucmSubFormField->name] = $ucmSubFormClient; - } - } - } - - // Remove empty records - $ucmSubFormDataSet = array_filter($ucmSubFormDataSet); - - return $ucmSubFormDataSet; - } - /** * Function to save ucmSubForm records * @@ -1435,7 +915,9 @@ public function getUcmSubFormFieldDataJson($parentRecordId, $efd) /** * Function to updated related field options * - * @param INT $contentId parent content id + * @param INT $client client + * + * @param INT $contentId Content id * * @return ARRAY */ diff --git a/src/components/com_tjucm/site/models/items.php b/src/components/com_tjucm/site/models/items.php index ba3d53d4..8c6ad78b 100644 --- a/src/components/com_tjucm/site/models/items.php +++ b/src/components/com_tjucm/site/models/items.php @@ -553,86 +553,6 @@ private function getFieldsData($contentIds) return $db->loadObjectList(); } - /** - * Overrides the default function to check Date fields format, identified by - * "_dateformat" suffix, and erases the field if it's not correct. - * - * @return void - */ - protected function loadFormData() - { - $app = JFactory::getApplication(); - $filters = $app->getUserState($this->context . '.filter', array()); - $error_dateformat = false; - - foreach ($filters as $key => $value) - { - if (strpos($key, '_dateformat') && !empty($value) && $this->isValidDate($value) == null) - { - $filters[$key] = ''; - $error_dateformat = true; - } - } - - if ($error_dateformat) - { - $app->enqueueMessage(JText::_("COM_TJUCM_SEARCH_FILTER_DATE_FORMAT"), "warning"); - $app->setUserState($this->context . '.filter', $filters); - } - - return parent::loadFormData(); - } - - /** - * Checks if a given date is valid and in a specified format (YYYY-MM-DD) - * - * @param string $date Date to be checked - * - * @return bool - */ - private function isValidDate($date) - { - $date = str_replace('/', '-', $date); - - return (date_create($date)) ? JFactory::getDate($date)->format("Y-m-d") : null; - } - - /** - * Method to getAliasFieldNameByView - * - * @param array $view An array of record primary keys. - * - * @return boolean True if successful, false if an error occurs. - * - * @since 12.2 - */ - public function getAliasFieldNameByView($view) - { - switch ($view) - { - case 'items': - return 'alias'; - break; - } - } - - /** - * Get an item by alias - * - * @param string $alias Alias string - * - * @return int Element id - */ - public function getItemIdByAlias($alias) - { - $db = JFactory::getDbo(); - $table = JTable::getInstance('type', 'TjucmTable', array('dbo', $db)); - - $table->load(array('alias' => $alias)); - - return $table->id; - } - /** * Check if there are fields to show in list view * From 9af0f373e37b9b7da6a0d6fcaed4538932602965 Mon Sep 17 00:00:00 2001 From: Amol Thite Date: Fri, 8 Nov 2019 15:18:59 +0530 Subject: [PATCH 06/52] Task #229 feat: Basic class sructure created --- .../com_tjucm/site/includes/defines.php | 23 ++ .../com_tjucm/site/includes/item.php | 316 ++++++++++++++++++ .../com_tjucm/site/includes/tjucm.php | 176 ++++++++++ 3 files changed, 515 insertions(+) create mode 100644 src/components/com_tjucm/site/includes/defines.php create mode 100644 src/components/com_tjucm/site/includes/item.php create mode 100644 src/components/com_tjucm/site/includes/tjucm.php diff --git a/src/components/com_tjucm/site/includes/defines.php b/src/components/com_tjucm/site/includes/defines.php new file mode 100644 index 00000000..e6485254 --- /dev/null +++ b/src/components/com_tjucm/site/includes/defines.php @@ -0,0 +1,23 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +if (defined('COM_TJUCM_SITE_DEFINE_FILE')) +{ + return; +} + +define('COM_TJUCM_ITEM_STATE_PUBLISHED', 1); +define('COM_TJUCM_ITEM_STATE_UNPUBLISHED', 0); +define('COM_TJUCM_ITEM_STATE_ARCHIVED', 2); +define('COM_TJUCM_ITEM_STATE_TRASHED', -2); +define('COM_TJUCM_ITEM_STATE_DRAFT', -1); + +// Need this constant for performance purpose Always define this at the end of file +define('COM_TJUCM_SITE_DEFINE_FILE', true); diff --git a/src/components/com_tjucm/site/includes/item.php b/src/components/com_tjucm/site/includes/item.php new file mode 100644 index 00000000..806d9fcf --- /dev/null +++ b/src/components/com_tjucm/site/includes/item.php @@ -0,0 +1,316 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +defined('_JEXEC') or die(); + +use Joomla\CMS\Object\CMSObject; + +/** + * Tjucm item class. + * + * @since __DEPLOY_VERSION__ + */ +class TjucmItem extends CMSObject +{ + /** + * The auto incremental primary key of the item + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $id = 0; + + /** + * In case of UCM-Subform parent_id is used to point to the parent record of the UCM-Subform records + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $parent_id = 0; + + /** + * Id of assets table for the item + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $asset_id = 0; + + /** + * Defines ordering of the item - Not Used As Of Now + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $ordering = 0; + + /** + * State of item + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $state = COM_TJUCM_ITEM_STATE_UNPUBLISHED; + + /** + * Category of the item - Category from the categories created for UCM type + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $category_id = ''; + + /** + * Id of UCM type to which the item belongs + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $type_id = 0; + + /** + * Unique identifier of the UCM type + * + * @var string + * @since __DEPLOY_VERSION__ + */ + public $client = ''; + + /** + * Cluster id to which the item belongs + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $cluster_id = ''; + + /** + * Joomla user id by whom the record is being checked out + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $checked_out = ''; + + /** + * Joomla user id by whom the record is created + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $created_by = ''; + + /** + * Joomla user id by whom the record is modified + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $modified_by = ''; + + /** + * Flag to mark if the item is a draft + * + * @var integer + * @since __DEPLOY_VERSION__ + */ + public $draft = ''; + + /** + * Date time when the item was last checked out + * + * @var datetime + * @since __DEPLOY_VERSION__ + */ + public $checked_out_time = ''; + + /** + * Date time when the item was created + * + * @var datetime + * @since __DEPLOY_VERSION__ + */ + public $created_date = ''; + + /** + * Date time when the item was last modified + * + * @var datetime + * @since __DEPLOY_VERSION__ + */ + public $modified_date = ''; + + /** + * holds the already loaded instances of the Item + * + * @var array + * @since __DEPLOY_VERSION__ + */ + protected static $itemObj = array(); + + /** + * Holds the fields values in the item + * + * @var array + * @since __DEPLOY_VERSION__ + */ + private $fieldsValues = array(); + + /** + * Constructor activating the default information of the item + * + * @param int $id The unique item key to load. + * + * @since __DEPLOY_VERSION__ + */ + public function __construct($id = 0) + { + if (!empty($id)) + { + $this->load($id); + } + } + + /** + * Returns the item object + * + * @param integer $id The primary key of the item to load (optional). + * + * @return TjucmItem The item object. + * + * @since __DEPLOY_VERSION__ + */ + public static function getInstance($id = 0) + { + if (!$id) + { + return new TjucmItem; + } + + if (empty(self::$itemObj[$id])) + { + self::$itemObj[$id] = new TjucmItem($id); + } + + return self::$itemObj[$id]; + } + + /** + * Method to load a item properties + * + * @param int $id The item id + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function load($id) + { + $table = Tjucm::table("item"); + + if ($table->load($id)) + { + $this->setProperties($table->getProperties()); + + // Load field values for the item + // $this->setFieldsValues($table->id); + + return true; + } + + return false; + } + + /** + * Method to save the Item object to the database + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function save() + { + $isNew = $this->isNew(); + + // Create the item table object + $table = Tjucm::table('item'); + + // Allow an exception to be thrown. + try + { + $table->bind(get_object_vars($this)); + + // Check and store the object. + if (!$table->check()) + { + $this->setError($table->getError()); + + return false; + } + + // Store the item data in the database + $result = $table->store(); + + // Set the id for the item object in case we created a new item. + if ($result && $isNew) + { + $this->load($table->get('id')); + $item = Tjucm::model('item'); + $this->item_id = $item->generateItemID($this->id); + + return $this->save(); + } + elseif ($result && !$isNew) + { + return $this->load($this->id); + } + } + catch (\Exception $e) + { + $this->setError($e->getMessage()); + + return false; + } + + return $result; + } + + /** + * Method to check is item new or not + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + private function isNew() + { + return $this->id < 1; + } + + /** + * Returns a property of the object or the default value if the property is not set. + * + * @param string $property The name of the property. + * @param mixed $default The default value. + * + * @return mixed The value of the property. + * + * @since __DEPLOY_VERSION__ + */ + public function get($property, $default = null) + { + if (isset($this->$property)) + { + return $this->$property; + } + + return $default; + } +} diff --git a/src/components/com_tjucm/site/includes/tjucm.php b/src/components/com_tjucm/site/includes/tjucm.php new file mode 100644 index 00000000..8311e061 --- /dev/null +++ b/src/components/com_tjucm/site/includes/tjucm.php @@ -0,0 +1,176 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +defined('_JEXEC') or die(); + +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Table\Table; +use Joomla\String\StringHelper; + +require_once JPATH_SITE . '/components/com_tjucm/includes/defines.php'; + +/** + * Tjucm factory class. + * + * This class perform the helpful operation required to Tjucm package + * + * @since __DEPLOY_VERSION__ + */ +class Tjucm +{ + /** + * Holds the record of the loaded Tjucm classes + * + * @var array + * @since __DEPLOY_VERSION__ + */ + private static $loadedClass = array(); + + /** + * Holds the record of the component config + * + * @var Joomla\Registry\Registry + * @since __DEPLOY_VERSION__ + */ + private static $config = null; + + /** + * Retrieves a table from the table folder + * + * @param string $name The table file name + * @param array $config Configuration array for model. Optional. + * + * @return Table|boolean object or false on failure + * + * @since __DEPLOY_VERSION__ + **/ + public static function table($name, $config = array()) + { + Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjucm/tables'); + $table = Table::getInstance($name, 'TjucmTable', $config); + + return $table; + } + + /** + * Retrieves a model from the model folder + * + * @param string $name The model name + * @param array $config Configuration array for model. Optional. + * + * @return BaseDatabaseModel|boolean object or false on failure + * + * @since __DEPLOY_VERSION__ + **/ + public static function model($name, $config = array()) + { + JLoader::import('components.com_tjucm.models.type', JPATH_ADMINISTRATOR); + JLoader::import('components.com_tjucm.models.types', JPATH_ADMINISTRATOR); + BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_tjucm/models', 'TjucmModel'); + $model = BaseDatabaseModel::getInstance($name, 'TjucmModel', $config); + + return $model; + } + + /** + * Magic method to create instance of Tjucm library + * + * @param string $name The name of the class + * @param mixed $arguments Arguments of class + * + * @return mixed return the Object of the respective class if exist OW return false + * + * @since __DEPLOY_VERSION__ + **/ + public static function __callStatic($name, $arguments) + { + self::loadClass($name); + + $className = 'Tjucm' . StringHelper::ucfirst($name); + + if (class_exists($className)) + { + if (method_exists($className, 'getInstance')) + { + return call_user_func_array(array($className, 'getInstance'), $arguments); + } + + return new $className; + } + + return false; + } + + /** + * Load the class library if not loaded + * + * @param string $className The name of the class which required to load + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + **/ + public static function loadClass($className) + { + if (! isset(self::$loadedClass[$className])) + { + $className = (string) StringHelper::strtolower($className); + + $path = JPATH_SITE . '/components/com_tjucm/includes/' . $className . '.php'; + + include_once $path; + + self::$loadedClass[$className] = true; + } + + return self::$loadedClass[$className]; + } + + /** + * Load the component configuration + * + * @return Joomla\Registry\Registry A Registry object. + */ + public static function config() + { + if (empty(self::$config)) + { + self::$config = ComponentHelper::getParams('com_tjucm'); + } + + return self::$config; + } + + /** + * Initializes the css, js and necessary dependencies + * + * @param string $location The location where the assets needs to load + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public static function init($location = 'site') + { + static $loaded = null; + $docType = Factory::getDocument()->getType(); + + if (! $loaded[$location] && ($docType == 'html')) + { + // HTMLHelper::script('administrator/components/com_tjucm/assets/js/tjucm_ajaxForm_save.js'); + HTMLHelper::StyleSheet('media/jui/css/icomoon.css'); + + $loaded[$location] = true; + } + } +} From 795f537aa2831c90c6bc4638e4c21c0a3daab917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Fri, 8 Nov 2019 16:45:28 +0530 Subject: [PATCH 07/52] Task #229 fix: Improve the codebase --- .../com_tjucm/site/models/itemform.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/com_tjucm/site/models/itemform.php b/src/components/com_tjucm/site/models/itemform.php index d42cd838..7add93fc 100644 --- a/src/components/com_tjucm/site/models/itemform.php +++ b/src/components/com_tjucm/site/models/itemform.php @@ -26,7 +26,7 @@ /** * Tjucm model. * - * @since 1.6 + * @since 1.0 */ class TjucmModelItemForm extends JModelAdmin { @@ -34,7 +34,7 @@ class TjucmModelItemForm extends JModelAdmin /** * @var string The prefix to use with controller messages. - * @since 1.6 + * @since 1.0 */ protected $text_prefix = 'COM_TJUCM'; @@ -55,7 +55,7 @@ class TjucmModelItemForm extends JModelAdmin * @param array $config An optional associative array of configuration settings. * * @see JController - * @since 1.6 + * @since 1.0 */ public function __construct($config = array()) { @@ -72,7 +72,7 @@ public function __construct($config = array()) * * @return void * - * @since 1.6 + * @since 1.0 */ protected function populateState() { @@ -232,7 +232,7 @@ public function &getData($id = null) * * @return JTable A database object * - * @since 1.6 + * @since 1.0 */ public function getTable($type = 'Item', $prefix = 'TjucmTable', $config = array()) { @@ -261,7 +261,7 @@ public function setClient($client) * * @return JForm A JForm object on success, false on failure * - * @since 1.6 + * @since 1.0 */ public function getForm($data = array(), $loadData = true) { @@ -466,7 +466,7 @@ public function getSectionForm($data = array(), $loadData = true) * * @return mixed The data for the form. * - * @since 1.6 + * @since 1.0 */ protected function loadFormData() { @@ -493,7 +493,7 @@ protected function loadFormData() * * @return boolean True on success. * - * @since 1.6 + * @since 1.0 */ public function save($data) { From 436bdd06c3728407b66a271b659761b93434fc20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Fri, 8 Nov 2019 17:08:26 +0530 Subject: [PATCH 08/52] Task #229 fix: Improve the codebase --- src/components/com_tjucm/site/models/itemform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/com_tjucm/site/models/itemform.php b/src/components/com_tjucm/site/models/itemform.php index 7add93fc..a9c4a300 100644 --- a/src/components/com_tjucm/site/models/itemform.php +++ b/src/components/com_tjucm/site/models/itemform.php @@ -244,7 +244,7 @@ public function getTable($type = 'Item', $prefix = 'TjucmTable', $config = array /** * Get an array of data items * - * @param string $client client value + * @param string $client client * * @return mixed Array of data items on success, false on failure. */ From 94e4d6125a83974f4d8b12a88c19ca88e5059642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Fri, 8 Nov 2019 17:11:34 +0530 Subject: [PATCH 09/52] Task #229 fix: Improve the codebase --- src/components/com_tjucm/site/models/itemform.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/com_tjucm/site/models/itemform.php b/src/components/com_tjucm/site/models/itemform.php index a9c4a300..5c3e98de 100644 --- a/src/components/com_tjucm/site/models/itemform.php +++ b/src/components/com_tjucm/site/models/itemform.php @@ -24,7 +24,7 @@ use Joomla\Registry\Registry; /** - * Tjucm model. + * Tjucm model * * @since 1.0 */ @@ -609,7 +609,9 @@ public function saveExtraFields($fieldData) $ownerShipFieldName = str_replace('.', '_', $fieldData['client']) . '_ownershipcreatedby'; $itemCategoryFieldName = str_replace('.', '_', $fieldData['client']) . '_itemcategory'; - if (array_key_exists($clusterFieldName, $fieldData['fieldsvalue']) || array_key_exists($ownerShipFieldName, $fieldData['fieldsvalue']) || array_key_exists($itemCategoryFieldName, $fieldData['fieldsvalue'])) + if (array_key_exists($clusterFieldName, $fieldData['fieldsvalue']) + || array_key_exists($ownerShipFieldName, $fieldData['fieldsvalue']) + || array_key_exists($itemCategoryFieldName, $fieldData['fieldsvalue'])) { JLoader::import('components.com_tjucm.tables.item', JPATH_ADMINISTRATOR); $ucmItemTable = JTable::getInstance('Item', 'TjucmTable', array('dbo', JFactory::getDbo())); From 6d875272ea417b8a86964a948214d78a6cd20a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Mon, 11 Nov 2019 10:55:04 +0530 Subject: [PATCH 10/52] Task #229 fix: Improve the codebase --- src/components/com_tjucm/site/models/itemform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/com_tjucm/site/models/itemform.php b/src/components/com_tjucm/site/models/itemform.php index 5c3e98de..9c60c53a 100644 --- a/src/components/com_tjucm/site/models/itemform.php +++ b/src/components/com_tjucm/site/models/itemform.php @@ -24,7 +24,7 @@ use Joomla\Registry\Registry; /** - * Tjucm model + * Tjucm model. * * @since 1.0 */ From 9aa4b788e0773ae1bc025a6a8bd2d309a4dbf072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Mon, 11 Nov 2019 11:10:08 +0530 Subject: [PATCH 11/52] Task #229 fix: Improve the codebase --- src/components/com_tjucm/tjucm.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/com_tjucm/tjucm.xml b/src/components/com_tjucm/tjucm.xml index 876a72f3..37c4391d 100644 --- a/src/components/com_tjucm/tjucm.xml +++ b/src/components/com_tjucm/tjucm.xml @@ -36,6 +36,7 @@ layouts controllers helpers + includes js From 56c3b5a709d1d9dc5fd292be1755c7ac2cd8e52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Wed, 13 Nov 2019 12:54:59 +0530 Subject: [PATCH 12/52] Task #229 fix: Improve the codebase --- .../administrator/assets/css/tjucm.css | 30 ----- .../administrator/assets/js/tjucm_type.js | 3 - .../administrator/classes/funlist.php | 62 ---------- .../com_tjucm/administrator/models/item.php | 8 +- .../com_tjucm/administrator/models/type.php | 15 +-- .../com_tjucm/administrator/tjucm.php | 9 -- .../administrator/views/type/tmpl/edit.php | 7 -- src/components/com_tjucm/media/.htaccess | 4 + src/components/com_tjucm/media/css/.htaccess | 3 + src/components/com_tjucm/media/css/index.html | 1 + src/components/com_tjucm/media/css/tjucm.css | 8 ++ .../com_tjucm/media/js/com_tjucm.min.js | 1 + .../com_tjucm/media/js/core/base.min.js | 1 + .../com_tjucm/media/js/core/class.min.js | 1 + src/components/com_tjucm/media/js/form.js | 19 --- src/components/com_tjucm/media/js/index.html | 1 + src/components/com_tjucm/media/js/load_js.php | 23 ---- .../com_tjucm/media/js/services/item.min.js | 1 + .../assets/js => media/js/ui}/itemform.js | 0 .../com_tjucm/media/js/ui/itemform.min.js | 1 + .../js/vendor/jquery}/jquery.are-you-sure.js | 0 .../js/vendor/jquery}/jquery.form.js | 0 .../js/vendor/shim}/ays-beforeunload-shim.js | 0 .../site/controllers/itemform.json.php | 4 +- .../com_tjucm/site/includes/tjucm.php | 37 +++++- .../com_tjucm/site/includes/version.php | 103 ++++++++++++++++ .../com_tjucm/site/models/itemform.php | 110 +----------------- src/components/com_tjucm/site/tjucm.php | 27 +---- .../site/views/itemform/tmpl/default.php | 41 +++---- .../site/views/items/tmpl/default.php | 2 +- 30 files changed, 195 insertions(+), 327 deletions(-) delete mode 100644 src/components/com_tjucm/administrator/assets/js/tjucm_type.js delete mode 100644 src/components/com_tjucm/administrator/classes/funlist.php create mode 100755 src/components/com_tjucm/media/.htaccess create mode 100755 src/components/com_tjucm/media/css/.htaccess create mode 100644 src/components/com_tjucm/media/css/index.html create mode 100644 src/components/com_tjucm/media/css/tjucm.css create mode 100755 src/components/com_tjucm/media/js/com_tjucm.min.js create mode 100755 src/components/com_tjucm/media/js/core/base.min.js create mode 100755 src/components/com_tjucm/media/js/core/class.min.js delete mode 100644 src/components/com_tjucm/media/js/form.js create mode 100644 src/components/com_tjucm/media/js/index.html delete mode 100755 src/components/com_tjucm/media/js/load_js.php create mode 100755 src/components/com_tjucm/media/js/services/item.min.js rename src/components/com_tjucm/{administrator/assets/js => media/js/ui}/itemform.js (100%) create mode 100644 src/components/com_tjucm/media/js/ui/itemform.min.js rename src/components/com_tjucm/{administrator/assets/js => media/js/vendor/jquery}/jquery.are-you-sure.js (100%) rename src/components/com_tjucm/{administrator/assets/js => media/js/vendor/jquery}/jquery.form.js (100%) rename src/components/com_tjucm/{administrator/assets/js => media/js/vendor/shim}/ays-beforeunload-shim.js (100%) create mode 100644 src/components/com_tjucm/site/includes/version.php diff --git a/src/components/com_tjucm/administrator/assets/css/tjucm.css b/src/components/com_tjucm/administrator/assets/css/tjucm.css index 7ae82a71..c323376d 100644 --- a/src/components/com_tjucm/administrator/assets/css/tjucm.css +++ b/src/components/com_tjucm/administrator/assets/css/tjucm.css @@ -1,33 +1,3 @@ -.icon-48-types { -background-image: url(../images/l_types.png); -padding-left:60px!important; -} - -.icon-48-type { -background-image: url(../images/l_types.png); -padding-left:60px!important; -} - -.color-box-types { -float: left;width: 15px;height: 15px;margin-right: 5px;border: 1px solid rgba(0, 0, 0, .2);} - -.icon-48-items { -background-image: url(../images/l_items.png); -padding-left:60px!important; -} - -.icon-48-item { -background-image: url(../images/l_items.png); -padding-left:60px!important; -} - -.color-box-items { -float: left;width: 15px;height: 15px;margin-right: 5px;border: 1px solid rgba(0, 0, 0, .2);} - -.other-filters{ - padding: 0 14px; -} - /* CSS for frontend*/ #item-form .radio input{ margin-left:5px !important; diff --git a/src/components/com_tjucm/administrator/assets/js/tjucm_type.js b/src/components/com_tjucm/administrator/assets/js/tjucm_type.js deleted file mode 100644 index 442914a5..00000000 --- a/src/components/com_tjucm/administrator/assets/js/tjucm_type.js +++ /dev/null @@ -1,3 +0,0 @@ -js = jQuery.noConflict(); -js(document).ready(function () { -}); diff --git a/src/components/com_tjucm/administrator/classes/funlist.php b/src/components/com_tjucm/administrator/classes/funlist.php deleted file mode 100644 index 33c7ffe4..00000000 --- a/src/components/com_tjucm/administrator/classes/funlist.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. - * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL - */ - -defined('_JEXEC') or die('Restricted access'); -jimport('joomla.form.form'); - -/** - * Extra function list. - * - * @package Joomla.site - * @subpackage com_tjucm - * - * @since 1.0 - */ -class TjucmFunList -{ - /** - * Function to get data - * - * @param STRING $table Name of database table - * @param STRING $selectList Selected value colume name - * @param STRING $where Query where condition - * @param STRING $returnObject Selecting data using JDatabase - link https://docs.joomla.org/Selecting_data_using_JDatabase - * @param STRING $joinType LEFT, RIGHT etc - * @param STRING $joinTable Name of database table - * - * @return true - * - * @since 1.0.0 - */ - public function getDataValues($table, $selectList = "*", $where = "", $returnObject = "", $joinType = "", $joinTable = "") - { - // Ref - link https://docs.joomla.org/Selecting_data_using_JDatabase - - $db = JFactory::getDbo(); - $query = $db->getQuery(true); - - $query->select($selectList); - $query->from($table); - - if ($joinTable) - { - $query->join($joinType, $joinTable); - } - - if ($where) - { - $query->where($where); - } - - $db->setQuery($query); - - return $db->$returnObject(); - } -} diff --git a/src/components/com_tjucm/administrator/models/item.php b/src/components/com_tjucm/administrator/models/item.php index 1a6bf330..0c3b54d0 100644 --- a/src/components/com_tjucm/administrator/models/item.php +++ b/src/components/com_tjucm/administrator/models/item.php @@ -55,9 +55,6 @@ class TjucmModelItem extends JModelAdmin */ public function __construct($config = array()) { - JLoader::import('components.com_tjucm.classes.funlist', JPATH_ADMINISTRATOR); - $this->common = new TjucmFunList; - parent::__construct($config); } @@ -290,7 +287,10 @@ public function save($data, $extra_jform_data = '', $post = '') $input = JFactory::getApplication()->input; $filter = JFilterInput::getInstance(); - $data['type_id'] = $this->common->getDataValues('#__tj_ucm_types', 'id AS type_id', 'unique_identifier = "' . $this->client . '"', 'loadResult'); + JLoader::import('components.com_tjucm.tables.type', JPATH_ADMINISTRATOR); + $tjUcmTypeTable = JTable::getInstance('TjucmTableType', 'JTable', array('dbo', JFactory::getDbo())); + $tjUcmTypeTable->load(array('unique_identifier' => $this->client)); + $data['type_id'] = $tjUcmTypeTable->id; if (parent::save($data)) { diff --git a/src/components/com_tjucm/administrator/models/type.php b/src/components/com_tjucm/administrator/models/type.php index 782c53a2..f9cf2ad5 100644 --- a/src/components/com_tjucm/administrator/models/type.php +++ b/src/components/com_tjucm/administrator/models/type.php @@ -48,9 +48,6 @@ class TjucmModelType extends JModelAdmin */ public function __construct($config = array()) { - JLoader::import('components.com_tjucm.classes.funlist', JPATH_ADMINISTRATOR); - $this->common = new TjucmFunList; - parent::__construct($config); } @@ -313,11 +310,7 @@ public function save($data) if (!empty($data['id'])) { $field_group = $this->getGroupCount($data['unique_identifier']); - - // Not able to get count using getTotal method of category model - $field_category = $this->common->getDataValues('#__categories', 'count(*)', 'extension = "' . $data['unique_identifier'] . '"', 'loadResult'); - - // $field_category = $this->getCategoryCount($data['unique_identifier']); + $field_category = $this->getCategoryCount($data['unique_identifier']); if ($field_group == 0 && $field_category == 0) { @@ -417,10 +410,10 @@ public function getGroupCount($client) public function getCategoryCount($client) { JLoader::import('components.com_categories.models.categories', JPATH_ADMINISTRATOR); - $categories_model = JModelLegacy::getInstance('Categories', 'CategoriesModel'); - $categories_model->setState('filter.extension', $client); + $categoryModel = JModelLegacy::getInstance('Categories', 'CategoriesModel', array('ignore_request' => true)); + $categoryModel->setState('filter.extension', $client); - return $categories_model->getTotal(); + return $categoryModel->getTotal(); } /** diff --git a/src/components/com_tjucm/administrator/tjucm.php b/src/components/com_tjucm/administrator/tjucm.php index 0bfd57c3..fd288f3f 100644 --- a/src/components/com_tjucm/administrator/tjucm.php +++ b/src/components/com_tjucm/administrator/tjucm.php @@ -20,15 +20,6 @@ // Include dependancies jimport('joomla.application.component.controller'); -$path = JPATH_COMPONENT_ADMINISTRATOR . '/classes/' . 'funlist.php'; - -if (!class_exists('TjucmFunList')) -{ - // Require_once $path; - JLoader::register('TjucmFunList', $path); - JLoader::load('TjucmFunList'); -} - // Load backend helper $path = JPATH_ADMINISTRATOR . '/components/com_tjucm/helpers/tjucm.php'; diff --git a/src/components/com_tjucm/administrator/views/type/tmpl/edit.php b/src/components/com_tjucm/administrator/views/type/tmpl/edit.php index 21ec84bd..7482dbaf 100644 --- a/src/components/com_tjucm/administrator/views/type/tmpl/edit.php +++ b/src/components/com_tjucm/administrator/views/type/tmpl/edit.php @@ -14,15 +14,8 @@ JHtml::_('behavior.formvalidation'); JHtml::_('formbehavior.chosen', 'select'); JHtml::_('behavior.keepalive'); - -JHtml::script(JUri::root() . 'administrator/components/com_tjucm/assets/js/tjucm_type.js'); ?>