From 8b7aca003badc0ccde501f5a287e08cf7e6ffef2 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Thu, 5 Jan 2023 16:08:09 +0530 Subject: [PATCH 01/13] Feature #184273 feat: Conditional fields implementation --- admin_language/en-GB/en-GB.com_tjfields.ini | 17 ++ administrator/controllers/condition.php | 119 +++++++++ administrator/controllers/conditions.php | 102 ++++++++ administrator/helpers/tjfields.php | 46 ++++ administrator/models/condition.php | 210 ++++++++++++++++ administrator/models/conditions.php | 235 ++++++++++++++++++ .../models/fields/conditionalfields.php | 95 +++++++ administrator/models/fields/spcialfields.php | 97 ++++++++ .../models/fields/specialfieldsoptions.php | 89 +++++++ administrator/models/forms/condition.xml | 52 ++++ administrator/models/forms/sub_condition.xml | 31 +++ administrator/sql/install.mysql.utf8.sql | 16 ++ administrator/sql/updates/mysql/2.0.2.sql | 18 +- administrator/tables/condition.php | 75 ++++++ administrator/views/condition/index.html | 1 + administrator/views/condition/tmpl/edit.php | 139 +++++++++++ administrator/views/condition/tmpl/index.html | 1 + administrator/views/condition/view.html.php | 129 ++++++++++ administrator/views/conditions/index.html | 1 + .../views/conditions/tmpl/default.php | 161 ++++++++++++ .../views/conditions/tmpl/index.html | 1 + administrator/views/conditions/view.html.php | 150 +++++++++++ 22 files changed, 1784 insertions(+), 1 deletion(-) create mode 100644 administrator/controllers/condition.php create mode 100644 administrator/controllers/conditions.php create mode 100644 administrator/models/condition.php create mode 100644 administrator/models/conditions.php create mode 100644 administrator/models/fields/conditionalfields.php create mode 100644 administrator/models/fields/spcialfields.php create mode 100644 administrator/models/fields/specialfieldsoptions.php create mode 100644 administrator/models/forms/condition.xml create mode 100644 administrator/models/forms/sub_condition.xml create mode 100644 administrator/tables/condition.php create mode 100644 administrator/views/condition/index.html create mode 100644 administrator/views/condition/tmpl/edit.php create mode 100644 administrator/views/condition/tmpl/index.html create mode 100644 administrator/views/condition/view.html.php create mode 100644 administrator/views/conditions/index.html create mode 100644 administrator/views/conditions/tmpl/default.php create mode 100644 administrator/views/conditions/tmpl/index.html create mode 100644 administrator/views/conditions/view.html.php diff --git a/admin_language/en-GB/en-GB.com_tjfields.ini b/admin_language/en-GB/en-GB.com_tjfields.ini index a859cf27..0f2b3c63 100755 --- a/admin_language/en-GB/en-GB.com_tjfields.ini +++ b/admin_language/en-GB/en-GB.com_tjfields.ini @@ -554,3 +554,20 @@ COM_TJFIELDS_FORM_LBL_ITEM_CATEGORY_FIELD_STATE="State" COM_TJFIELDS_FORM_DESC_ITEM_CATEGORY_FIELD_STATE="(1/0/2/-2) is whether the drop down will show only published (1), unpublished (0), archived (2) or trashed (-2) categories. It is possible to combine different publishing status by entering the list of the corresponding numbers separated by comma (e.g. "0,2,-2" will display only unpublished, archived and trashed categories in the drop-down)" COM_TJFIELDS_CAPTURE_IMAGE="Capture Image" COM_TJFIELDS_LBL_ACCORDION="Accordion Tag" + + +COM_TJFIELDS_CONDITION_SELCET_FIELD="Select Field" +COM_TJFIELDS_CONDITION_SELCET_FIELD_OPTIONS="Select Option" +COM_TJFIELDS_TITLE_CONDITIONS="Conditions" +COM_TJFIELDS_ADD_CONDITION="Add" +COM_TJFIELDS_EDIT_CONDITION="Edit Condition" +COM_TJFIELDS_N_CONDITIONS_UNPUBLISHED="%d conditions successfully unpublished" +COM_TJFIELDS_N_CONDITIONS_PUBLISHED="%d conditions successfully published" +COM_TJFIELDS_CONDITIONAL_FIELDS="Conditional Fields" +COM_TJFIELDS_FORM_LBL_CONDITION_SHOW="Show/Hide" +COM_TJFIELDS_FORM_LBL_CONDITION_FIELD_TO_SHOW="Select the field to show/hide" +COM_TJFIELDS_FORM_LBL_CONDITION_CONDITION_MATCH="Select All/Any of the defined condition matches" +COM_TJFIELDS_FORM_LBL_CONDITION_FIELD_ON_SHOW="Select the field on which you want to add condition" +COM_TJFIELDS_FORM_LBL_CONDITION_OPERATOR="Is/Is Not" +COM_TJFIELDS_FORM_LBL_CONDITION_OPTION="Select the option" +COM_TJFIELDS_FORM_LBL_CONDITION="Condition" diff --git a/administrator/controllers/condition.php b/administrator/controllers/condition.php new file mode 100644 index 00000000..86dec1ce --- /dev/null +++ b/administrator/controllers/condition.php @@ -0,0 +1,119 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\Factory; +use Joomla\CMS\Response\JsonResponse; +use Joomla\CMS\MVC\Controller\FormController; + +jimport('joomla.application.component.controllerform'); + +/** + * Country form controller class. + * + * @package Tjfields + * @subpackage com_tjfields + * @since 2.2 + */ +class TjfieldsControllerCondition extends FormController +{ + /** + * The extension for which the countries apply. + * + * @var string + * @since 1.6 + */ + protected $client; + + /** + * Constructor. + * + * @param array $config An optional associative array of configuration settings. + * + * @since 1.6 + * @see JController + */ + public function __construct($config = array()) + { + parent::__construct($config); + $this->view_list = 'conditions'; + + $this->input = Factory::getApplication()->input; + + if (empty($this->client)) + { + $this->client = $this->input->get('client', ''); + } + } + + /** + * Gets the URL arguments to append to an item redirect. + * + * @param integer $recordId The primary key id for the item. + * @param string $urlVar The name of the URL variable for the id. + * + * @return string The arguments to append to the redirect URL. + * + * @since 1.6 + */ + protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') + { + $append = parent::getRedirectToItemAppend($recordId); + $append .= '&client=' . $this->client; + + return $append; + } + + /** + * Gets the URL arguments to append to a list redirect. + * + * @return string The arguments to append to the redirect URL. + * + * @since 1.6 + */ + protected function getRedirectToListAppend() + { + $append = parent::getRedirectToListAppend(); + $append .= '&client=' . $this->client; + + return $append; + } + + /** + * Gets the URL arguments to append to a list redirect. + * + * @return string The arguments to append to the redirect URL. + * + * @since 1.6 + */ + public function getFieldsOptions() + { + $app = Factory::getApplication(); + $fieldId = $app->input->get('fieldId', 0, 'INT'); + + $db = Factory::getDbo(); + $query = $db->getQuery(true); + + // Select the required fields from the table. + $query->select('t.id AS value, t.options AS text'); + $query->from('`#__tjfields_options` AS t'); + $query->order($db->escape('t.ordering ASC')); + $query->where('t.field_id = ' . (int) $fieldId); + + $db->setQuery($query); + + // Get all countries. + $fieldOptions = $db->loadObjectList(); + + echo new JsonResponse($fieldOptions); + $app->close(); + + } +} diff --git a/administrator/controllers/conditions.php b/administrator/controllers/conditions.php new file mode 100644 index 00000000..fea4001c --- /dev/null +++ b/administrator/controllers/conditions.php @@ -0,0 +1,102 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access. +defined('_JEXEC') or die(); +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\Log\Log; +use Joomla\CMS\Language\Text; + +jimport('joomla.application.component.controlleradmin'); + +/** + * Countries list controller class. + * + * @package Tjfields + * @subpackage com_tjfields + * @since 2.2 + */ +class TjfieldsControllerConditions extends AdminController +{ + /** + * Proxy for getModel. + * + * @param string $name The name of the model. + * @param string $prefix The prefix for the PHP class name. + * @param array $config A named array of configuration variables. + * + * @return JModel + * + * @since 1.6 + */ + public function getModel($name = 'Condition', $prefix = 'TjfieldsModel', $config = array('ignore_request' => true)) + { + $model = parent::getModel($name, $prefix, $config); + + return $model; + } + + /** + * Method to publish records. + * + * @return void + * + * @since 3.0 + */ + public function publish() + { + $client = Factory::getApplication()->input->get('client', '', 'STRING'); + $cid = Factory::getApplication()->input->get('cid', array(), 'array'); + $data = array( + 'publish' => 1, + 'unpublish' => 0 + ); + + $task = $this->getTask(); + $value = JArrayHelper::getValue($data, $task, 0, 'int'); + + // Get some variables from the request + if (empty($cid)) + { + Log::add(Text::_('COM_TJFIELDS_NO_CONDITIONS_SELECTED'), Log::WARNING, 'jerror'); + } + else + { + // Get the model. + $model = $this->getModel(); + + // Make sure the item ids are integers + JArrayHelper::toInteger($cid); + + // Publish the items. + try + { + $model->publish($cid, $value); + + if ($value === 1) + { + $ntext = 'COM_TJFIELDS_N_CONDITIONS_PUBLISHED'; + } + elseif ($value === 0) + { + $ntext = 'COM_TJFIELDS_N_CONDITIONS_UNPUBLISHED'; + } + + $this->setMessage(Text::plural($ntext, count($cid))); + } + catch (Exception $e) + { + $this->setMessage($e->getMessage(), 'error'); + } + } + + $this->setRedirect('index.php?option=com_tjfields&view=conditions&client=' . $client); + } +} diff --git a/administrator/helpers/tjfields.php b/administrator/helpers/tjfields.php index 28c88cd2..9e357531 100755 --- a/administrator/helpers/tjfields.php +++ b/administrator/helpers/tjfields.php @@ -18,6 +18,7 @@ use Joomla\CMS\Filesystem\File; use Joomla\CMS\Language\Text; use Joomla\CMS\Table\Table; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; /** * Helper class for tjfields @@ -298,6 +299,10 @@ public function createXml($data, $fields, $category = null) // To store added field groups to the JForm $addedFieldGroups = array(); + + JLoader::import('components.com_tjfields.models.conditions', JPATH_ADMINISTRATOR); + $conditionsModel = BaseDatabaseModel::getInstance('Conditions', 'TjfieldsModel'); + $conditionalFields = $conditionsModel->getConditionalFields(); foreach ($fields as $f) { @@ -318,6 +323,47 @@ public function createXml($data, $fields, $category = null) $field->addAttribute('type', $f->type); $field->addAttribute('label', $f->label); $field->addAttribute('description', $f->description); + + if (in_array($f->id, $conditionalFields)) + { + $conditions = $conditionsModel->getConditions($f->id); + + $showonCondition = ""; + $flag = 1; + + foreach ($conditions as $condition) + { + $conditionMatch = $condition->condition_match; + $matchCase = ($conditionMatch == 1) ? "[AND]" : "[OR]" ; + $index = 1; + + foreach (json_decode($condition->condition) as $condition1) + { + $jsonDecoded = json_decode($condition1); + $fieldName = $conditionsModel->getFieldNameById($jsonDecoded->field_on_show); + $optionValue = $conditionsModel->getOptionName($jsonDecoded->field_on_show, $jsonDecoded->option); + $operator = ($jsonDecoded->operator == 1) ? ":" : "!:"; + + $showonCondition .= $fieldName . $operator . $optionValue; + + if (count((array) json_decode($condition->condition)) > $index) + { + $showonCondition .= $matchCase; + } + + $index ++; + } + + if (count((array) $conditions) > $flag) + { + $showonCondition .= $matchCase; + } + + $flag ++; + } + + $field->addAttribute('showon', $showonCondition); + } if ($f->required == 1) { diff --git a/administrator/models/condition.php b/administrator/models/condition.php new file mode 100644 index 00000000..01ec1949 --- /dev/null +++ b/administrator/models/condition.php @@ -0,0 +1,210 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\MVC\Model\AdminModel; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Factory; + +jimport('joomla.application.component.modeladmin'); + +/** + * Item Model for Condition. + * + * @package Tjfields + * @subpackage com_tjfields + * @since 2.2 + */ +class TjfieldsModelCondition extends AdminModel +{ + /** + * @var string The prefix to use with controller messages. + * @since 1.6 + */ + protected $text_prefix = 'COM_TJFIELDS'; + + /** + * Returns a Table object, always creating it. + * + * @param string $type The table type to instantiate + * @param string $prefix A prefix for the table class name. Optional. + * @param array $config Configuration array for model. Optional. + * + * @return JTable A database object + */ + public function getTable($type = 'Condition', $prefix = 'TjfieldsTable', $config = array()) + { + return Table::getInstance($type, $prefix, $config); + } + + /** + * Method to get the record form. + * + * @param array $data An optional ordering field. + * @param boolean $loadData An optional direction (asc|desc). + * + * @return JForm $form A JForm object on success, false on failure + * + * @since 2.2 + */ + public function getForm($data = array(), $loadData = true) + { + // Initialise variables. + $app = Factory::getApplication(); + + // Get the form. + $form = $this->loadForm('com_tjfields.condition', 'condition', array('control' => 'jform', 'load_data' => $loadData)); + + if (empty($form)) + { + return false; + } + + return $form; + } + + /** + * Method to get the data that should be injected in the form. + * + * @return mixed $data The data for the form. + * + * @since 1.6 + */ + protected function loadFormData() + { + // Check the session for previously entered form data. + $data = Factory::getApplication()->getUserState('com_tjfields.edit.condition.data', array()); + + if (empty($data)) + { + $data = $this->getItem(); + } + + return $data; + } + + /** + * Method to get a single record. + * + * @param integer $pk The id of the primary key. + * + * @return mixed $item Object on success, false on failure. + */ + public function getItem($pk = null) + { + if ($item = parent::getItem($pk)) + { + $allConditions = new stdClass; + + foreach (json_decode($item->condition) as $key => $data) + { + $allConditions->$key = json_decode($data); + } + + $item->condition = $allConditions; + // Do any procesing on fields here if needed + } + + return $item; + } + + /** + * Prepare and sanitise the table data prior to saving. + * + * @param JTable $table A JTable object. + * + * @return void + * + * @since 1.6 + */ + protected function prepareTable($table) + { + jimport('joomla.filter.output'); + + if (empty($table->id)) + { + // Set ordering to the last item if not set + if (@$table->ordering === '') + { + $db = Factory::getDbo(); + $db->setQuery('SELECT MAX(ordering) FROM #__tjfields_fields_conditions'); + $max = $db->loadResult(); + $table->ordering = $max + 1; + } + } + } + + /** + * Method to save the form data. + * + * @param array $data The form data. + * + * @return mixed The user id on success, false on failure. + * + * @since 1.6 + */ + public function save($data) + { + $id = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('condition.id'); + + $user = Factory::getUser(); + $app = Factory::getApplication(); + $client = $app->input->get('client', '', 'STRING'); + + $table = $this->getTable(); + + $conditions = array(); + + foreach ($data['condition'] as $key => $item) + { + $conditions[$key] = json_encode($item); + } + + $data['condition'] = json_encode($conditions); + $data['type_id'] = $app->input->get('client', ''); + $data['client'] = $app->input->get('client', ''); + + // Bind data + if (!$table->bind($data)) + { + $this->setError($table->getError()); + + return false; + } + + // Validate Condition codes to check for duplication + if (!$table->check()) + { + $this->setError($table->getError()); + + return false; + } + + // Attempt to save data + if (parent::save($data)) + { + // Generate xml here + $TjfieldsHelper = new TjfieldsHelper; + $client_form = explode('.', $client); + $client_type = $client_form[1]; + + $data2 = array(); + $data2['client'] = $client; + $data2['client_type'] = $client_type; + $TjfieldsHelper->generateXml($data2); + + // End xml + + return true; + } + + return false; + } +} diff --git a/administrator/models/conditions.php b/administrator/models/conditions.php new file mode 100644 index 00000000..61a27b9a --- /dev/null +++ b/administrator/models/conditions.php @@ -0,0 +1,235 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; + +jimport('joomla.application.component.modellist'); + +/** + * Methods supporting a list of countries records. + * + * @package Tjfields + * @subpackage com_tjfields + * @since 2.2 + */ +class TjfieldsModelConditions extends ListModel +{ + /** + * Constructor. + * + * @param array $config An optional associative array of configuration settings. + * + * @since 1.6 + * @see JController + */ + public function __construct($config = array()) + { + if (empty($config['filter_fields'])) + { + $config['filter_fields'] = array( + 'id', 'a.id', + 'state', 'state', + 'show', 'a.show', + 'field_to_show', 'a.field_to_show', + 'condition_match', 'a.condition_match', + 'condition', 'a.condition' + ); + } + + parent::__construct($config); + } + + /** + * Method to auto-populate the model state. + * + * Note. Calling getState in this method will result in recursion. + * + * @param string $ordering An optional ordering field. + * @param string $direction An optional direction (asc|desc). + * + * @return void + * + * @since 1.6 + */ + protected function populateState($ordering = null, $direction = null) + { + // Initialise variables. + $app = Factory::getApplication('administrator'); + + // Load the filter search + $search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); + $this->setState('filter.search', $search); + + // Load the filter state + $published = $app->getUserStateFromRequest($this->context . '.filter.state', 'filter_published', '', 'string'); + $this->setState('filter.state', $published); + + // Load the parameters. + $params = ComponentHelper::getParams('com_tjfields'); + $this->setState('params', $params); + + // List state information. + parent::populateState('a.id', 'asc'); + } + + /** + * Method to get a store id based on model configuration state. + * + * This is necessary because the model is used by the component and + * different modules that might need different sets of data or different + * ordering requirements. + * + * @param string $id A prefix for the store id. + * + * @return string A store id. + * + * @since 1.6 + */ + protected function getStoreId($id = '') + { + // Compile the store id. + $id .= ':' . $this->getState('filter.search'); + $id .= ':' . $this->getState('filter.state'); + + return parent::getStoreId($id); + } + + /** + * Build an SQL query to load the list data. + * + * @return JDatabaseQuery + * + * @since 1.6 + */ + protected function getListQuery() + { + // Create a new query object. + $db = $this->getDbo(); + $query = $db->getQuery(true); + $client = Factory::getApplication()->input->get('client', '', 'STRING'); + + // Select the required fields from the table. + $query->select( + $this->getState( + 'list.select', 'a.*' + ) + ); + $query->from('`#__tjfields_fields_conditions` AS a'); + + if (!empty($client)) + { + $query->where('a.client = "'. $client . '"'); + } + + // Add the list ordering clause. + $orderCol = $this->state->get('list.ordering'); + $orderDirn = $this->state->get('list.direction'); + + if ($orderCol && $orderDirn) + { + $query->order($db->escape($orderCol . ' ' . $orderDirn)); + } + + return $query; + } + + /** + * Method to get a list of countries. + * + * @return mixed An array of data items on success, false on failure. + * + * @since 1.6.1 + */ + public function getItems() + { + $items = parent::getItems(); + + return $items; + } + + /** + * Get option which are stored in field option table. + * + * @param INT $field_id field id + * + * @return array of option for the particular field + */ + public function getFieldName($fieldId) + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query->select('label'); + $query->from('#__tjfields_fields AS tf'); + $query->where('tf.id=' . $fieldId); + $db->setQuery($query); + $name = $db->loadResult(); + + return $name; + } + + /** + * Get option which are stored in field option table. + * + * @param INT $field_id field id + * + * @return array of option for the particular field + */ + public function getOptionName($fieldId, $optionId) + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query->select('value FROM #__tjfields_options'); + $query->where('field_id=' . $fieldId); + $query->where('id=' . $optionId); + $db->setQuery($query); + $optionName = $db->loadResult(); + + return $optionName; + } + + public function getConditionalFields() + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query->select('field_to_show FROM #__tjfields_fields_conditions'); + $db->setQuery($query); + $conditionalFields = $db->loadColumn(); + + return $conditionalFields; + } + + public function getConditions($id) + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query->select($db->qn(array('condition','condition_match'))); + $query->from('#__tjfields_fields_conditions'); + $query->where('field_to_show=' . $id); + $db->setQuery($query); + $conditions = $db->loadObjectList(); + + return $conditions; + } + + public function getFieldNameById($id) + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query->select('name FROM #__tjfields_fields'); + $query->where('id=' . $id); + $db->setQuery($query); + $name = $db->loadResult(); + + return $name; + } +} diff --git a/administrator/models/fields/conditionalfields.php b/administrator/models/fields/conditionalfields.php new file mode 100644 index 00000000..e8715c94 --- /dev/null +++ b/administrator/models/fields/conditionalfields.php @@ -0,0 +1,95 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access. +defined('_JEXEC') or die(); +use Joomla\CMS\Factory; +use Joomla\CMS\Form\FormHelper; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; + +FormHelper::loadFieldClass('list'); + +/** + * Supports an HTML select list of categories + */ +class JFormFieldConditionalfields extends JFormFieldList +{ + /** + * The form field type. + * + * @var string + * @since 1.6 + */ + protected $type = 'conditionalfields'; + + /** + * Fiedd to decide if options are being loaded externally and from xml + * + * @var integer + * @since 2.2 + */ + protected $loadExternally = 0; + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + * + * @since 11.4 + */ + protected function getOptions() + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $client = Factory::getApplication()->input->get('client', '', 'STRING'); + + // Select the required fields from the table. + $query->select('tf.id, tf.label'); + $query->from('`#__tjfields_fields` AS tf'); + $query->where('tf.state = 1'); + + if ($client) + { + $query->where('tf.client = "' . $client . '"'); + } + + $query->order($db->escape('tf.ordering ASC')); + + $db->setQuery($query); + + // Get all countries. + $conditionalfields = $db->loadObjectList(); + + $options = array(); + + $options[] = HTMLHelper::_('select.option', '', Text::_('COM_TJFIELDS_CONDITION_SELCET_FIELD')); + + foreach ($conditionalfields as $c) + { + $options[] = HTMLHelper::_('select.option', $c->id, $c->label); + } + + return $options; + } + + /** + * Method to get a list of options for a list input externally and not from xml. + * + * @return array An array of JHtml options. + * + * @since 2.2 + */ + public function getOptionsExternally() + { + $this->loadExternally = 1; + + return $this->getOptions(); + } +} diff --git a/administrator/models/fields/spcialfields.php b/administrator/models/fields/spcialfields.php new file mode 100644 index 00000000..9275acd3 --- /dev/null +++ b/administrator/models/fields/spcialfields.php @@ -0,0 +1,97 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access. +defined('_JEXEC') or die(); +use Joomla\CMS\Factory; +use Joomla\CMS\Form\FormHelper; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; + +FormHelper::loadFieldClass('list'); + +/** + * Supports an HTML select list of categories + */ +class JFormFieldSpcialfields extends JFormFieldList +{ + /** + * The form field type. + * + * @var string + * @since 1.6 + */ + protected $type = 'spcialfields'; + + /** + * Fiedd to decide if options are being loaded externally and from xml + * + * @var integer + * @since 2.2 + */ + protected $loadExternally = 0; + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + * + * @since 11.4 + */ + protected function getOptions() + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $client = Factory::getApplication()->input->get('client', '', 'STRING'); + + // Select the required fields from the table. + $query->select('tf.id, tf.label'); + $query->from('`#__tjfields_fields` AS tf'); + + $query->where('tf.type IN ("tjlist","radio","checkbox")'); + $query->where('tf.state = 1'); + + if ($client) + { + $query->where('tf.client = "' . $client . '"'); + } + + $query->order($db->escape('tf.ordering ASC')); + + $db->setQuery($query); + + // Get all countries. + $spcialfields = $db->loadObjectList(); + + $options = array(); + + $options[] = HTMLHelper::_('select.option', '', Text::_('COM_TJFIELDS_CONDITION_SELCET_FIELD')); + + foreach ($spcialfields as $c) + { + $options[] = HTMLHelper::_('select.option', $c->id, $c->label); + } + + return $options; + } + + /** + * Method to get a list of options for a list input externally and not from xml. + * + * @return array An array of JHtml options. + * + * @since 2.2 + */ + public function getOptionsExternally() + { + $this->loadExternally = 1; + + return $this->getOptions(); + } +} diff --git a/administrator/models/fields/specialfieldsoptions.php b/administrator/models/fields/specialfieldsoptions.php new file mode 100644 index 00000000..2be7e89d --- /dev/null +++ b/administrator/models/fields/specialfieldsoptions.php @@ -0,0 +1,89 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access. +defined('_JEXEC') or die(); +use Joomla\CMS\Factory; +use Joomla\CMS\Form\FormHelper; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; + +FormHelper::loadFieldClass('list'); + +/** + * Supports an HTML select list of categories + */ +class JFormFieldSpecialfieldsoptions extends JFormFieldList +{ + /** + * The form field type. + * + * @var string + * @since 1.6 + */ + protected $type = 'specialfieldsoptions'; + + /** + * Fiedd to decide if options are being loaded externally and from xml + * + * @var integer + * @since 2.2 + */ + protected $loadExternally = 0; + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + * + * @since 11.4 + */ + protected function getOptions() + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + + // Select the required fields from the table. + $query->select('t.id, t.options'); + $query->from('`#__tjfields_options` AS t'); + $query->order($db->escape('t.ordering ASC')); + + //~ echo $query->dump();die; + + $db->setQuery($query); + + // Get all countries. + $specialFieldsOptions = $db->loadObjectList(); + + $options = array(); + + $options[] = HTMLHelper::_('select.option', '', Text::_('COM_TJFIELDS_CONDITION_SELCET_FIELD_OPTIONS')); + + foreach ($specialFieldsOptions as $c) + { + $options[] = HTMLHelper::_('select.option', $c->id, $c->options); + } + + return $options; + } + + /** + * Method to get a list of options for a list input externally and not from xml. + * + * @return array An array of JHtml options. + * + * @since 2.2 + */ + public function getOptionsExternally() + { + $this->loadExternally = 1; + + return $this->getOptions(); + } +} diff --git a/administrator/models/forms/condition.xml b/administrator/models/forms/condition.xml new file mode 100644 index 00000000..ba6b5223 --- /dev/null +++ b/administrator/models/forms/condition.xml @@ -0,0 +1,52 @@ + +
+
+ + + + + + + + + + + + + + + + +
+
diff --git a/administrator/models/forms/sub_condition.xml b/administrator/models/forms/sub_condition.xml new file mode 100644 index 00000000..68aa743d --- /dev/null +++ b/administrator/models/forms/sub_condition.xml @@ -0,0 +1,31 @@ + +
+
+ + + + + + + + + + +
+
diff --git a/administrator/sql/install.mysql.utf8.sql b/administrator/sql/install.mysql.utf8.sql index 0d213538..9af89e54 100755 --- a/administrator/sql/install.mysql.utf8.sql +++ b/administrator/sql/install.mysql.utf8.sql @@ -63,3 +63,19 @@ CREATE TABLE IF NOT EXISTS `#__tjfields_category_mapping` ( `category_id` INT(11) NOT NULL COMMENT 'CATEGORY ID FROM JOOMLA CATEGORY TABLE FOR CLIENTS EG CLIENT=COM_QUICK2CART.PRODUCT' DEFAULT 0, PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1; + +CREATE TABLE IF NOT EXISTS `#__tjfields_fields_conditions` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `show` int(11) NOT NULL, + `field_to_show` int(11) NOT NULL, + `condition_match` int(11) NOT NULL, + `field_on_show` int(11) NOT NULL, + `operator` int(11) NOT NULL, + `option` int(11) NOT NULL, + `state` tinyint(1) NOT NULL, + `created_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , + `created_by` INT(10) NOT NULL DEFAULT '0' , + `modified_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , + `modified_by` INT(10) NOT NULL DEFAULT '0' , + PRIMARY KEY (`id`) +) DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1; diff --git a/administrator/sql/updates/mysql/2.0.2.sql b/administrator/sql/updates/mysql/2.0.2.sql index faf9f378..48dd297d 100644 --- a/administrator/sql/updates/mysql/2.0.2.sql +++ b/administrator/sql/updates/mysql/2.0.2.sql @@ -1 +1,17 @@ -ALTER TABLE `#__tjfields_fields_value` CHANGE `value` `value` mediumtext DEFAULT NULL; \ No newline at end of file +ALTER TABLE `#__tjfields_fields_value` CHANGE `value` `value` mediumtext DEFAULT NULL; + +CREATE TABLE IF NOT EXISTS `#__tjfields_fields_conditions` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `show` int(11) NOT NULL, + `field_to_show` int(11) NOT NULL, + `condition_match` int(11) NOT NULL, + `field_on_show` int(11) NOT NULL, + `operator` int(11) NOT NULL, + `option` int(11) NOT NULL, + `state` tinyint(1) NOT NULL, + `created_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , + `created_by` INT(10) NOT NULL DEFAULT '0' , + `modified_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , + `modified_by` INT(10) NOT NULL DEFAULT '0' , + PRIMARY KEY (`id`) +) DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1; diff --git a/administrator/tables/condition.php b/administrator/tables/condition.php new file mode 100644 index 00000000..9917e7c8 --- /dev/null +++ b/administrator/tables/condition.php @@ -0,0 +1,75 @@ +setColumnAlias('published', 'state'); + } + + /** + * Method to store a row in the database from the Table instance properties. + * + * If a primary key value is set the row with that primary key value will be updated with the instance property values. + * If no primary key value is set a new row will be inserted into the database with the properties from the Table instance. + * + * @param boolean $updateNulls True to update fields even if they are null. + * + * @return boolean True on success. + * + * @since 1.7.0 + */ + public function store($updateNulls = false) + { + $date = Factory::getDate(); + $user = Factory::getUser(); + + if ($this->id) + { + // Existing item + $this->modified_date = $date->toSql(); + $this->modified_by = $user->get('id'); + } + else + { + // So we don't touch either of these if they are set. + if (!(int) $this->created_date) + { + $this->created_date = $date->toSql(); + } + + if (empty($this->created_by)) + { + $this->created_by = $user->get('id'); + } + } + + return parent::store($updateNulls); + } +} diff --git a/administrator/views/condition/index.html b/administrator/views/condition/index.html new file mode 100644 index 00000000..42682b47 --- /dev/null +++ b/administrator/views/condition/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/administrator/views/condition/tmpl/edit.php b/administrator/views/condition/tmpl/edit.php new file mode 100644 index 00000000..4c09f246 --- /dev/null +++ b/administrator/views/condition/tmpl/edit.php @@ -0,0 +1,139 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + +HTMLHelper::_('behavior.formvalidation'); +HTMLHelper::_('behavior.keepalive'); +?> + + + +
+
+ +
+
+
+
+ + + + +
+
form->getLabel('show'); ?>
+
form->getInput('show'); ?>
+
+
+
form->getLabel('field_to_show'); ?>
+
form->getInput('field_to_show'); ?>
+
+
+
form->getLabel('condition_match'); ?>
+
form->getInput('condition_match'); ?>
+
+
+
form->getLabel('condition'); ?>
+
form->getInput('condition'); ?>
+
+ +
+
+
+ + + + + +
+
+
+ diff --git a/administrator/views/condition/tmpl/index.html b/administrator/views/condition/tmpl/index.html new file mode 100644 index 00000000..42682b47 --- /dev/null +++ b/administrator/views/condition/tmpl/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/administrator/views/condition/view.html.php b/administrator/views/condition/view.html.php new file mode 100644 index 00000000..b377cf0b --- /dev/null +++ b/administrator/views/condition/view.html.php @@ -0,0 +1,129 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; + +jimport('joomla.application.component.view'); + +/** + * View class for editing condition. + * + * @package Tjfields + * @subpackage com_tjfields + * @since 2.2 + */ +class TjfieldsViewCondition extends HtmlView +{ + protected $state; + + protected $item; + + protected $form; + + /** + * Display the view + * + * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * + * @return void + */ + public function display ($tpl = null) + { + $this->state = $this->get('State'); + $this->item = $this->get('Item'); + $this->form = $this->get('Form'); + $this->input = Factory::getApplication()->input; + + // Check for errors. + if (count($errors = $this->get('Errors'))) + { + throw new Exception(implode("\n", $errors)); + } + + $this->addToolbar(); + + parent::display($tpl); + } + + /** + * Add the page title and toolbar. + * + * @return void + * + * @since 1.6 + */ + protected function addToolbar() + { + Factory::getApplication()->input->set('hidemainmenu', true); + + $user = Factory::getUser(); + $isNew = ($this->item->id == 0); + + // Let's get the extension name + $client = Factory::getApplication()->input->get('client', '', 'STRING'); + $extensionName = strtoupper($client); + + // Need to load the menu language file as mod_menu hasn't been loaded yet. + $lang = Factory::getLanguage(); + $lang->load($client, JPATH_ADMINISTRATOR, null, false, true); + + $viewTitle = Text::_($extensionName); + + if ($isNew) + { + $viewTitle = $viewTitle . ': ' . Text::_('COM_TJFIELDS_ADD_CONDITION'); + } + else + { + $viewTitle = $viewTitle . ': ' . Text::_('COM_TJFIELDS_EDIT_CONDITION'); + } + + if (JVERSION >= '3.0') + { + JToolBarHelper::title($viewTitle, 'pencil-2'); + } + else + { + JToolBarHelper::title($viewTitle, 'condition.png'); + } + + if (isset($this->item->checked_out)) + { + $checkedOut = ! ($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id')); + } + else + { + $checkedOut = false; + } + + $extention = explode('.', $client); + + $canDo = TjfieldsHelper::getActions($extention[0], 'condition'); + + // If not checked out, can save the item. + if (! $checkedOut && ($canDo->get('core.edit') || ($canDo->get('core.create')))) + { + JToolBarHelper::apply('condition.apply', 'JTOOLBAR_APPLY'); + JToolBarHelper::save('condition.save', 'JTOOLBAR_SAVE'); + } + + if (empty($this->item->id)) + { + JToolBarHelper::cancel('condition.cancel', 'JTOOLBAR_CANCEL'); + } + else + { + JToolBarHelper::cancel('condition.cancel', 'JTOOLBAR_CLOSE'); + } + } +} diff --git a/administrator/views/conditions/index.html b/administrator/views/conditions/index.html new file mode 100644 index 00000000..42682b47 --- /dev/null +++ b/administrator/views/conditions/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/administrator/views/conditions/tmpl/default.php b/administrator/views/conditions/tmpl/default.php new file mode 100644 index 00000000..46f45ac6 --- /dev/null +++ b/administrator/views/conditions/tmpl/default.php @@ -0,0 +1,161 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Factory; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + +// Load lang file for countries +$lang = Factory::getLanguage(); +$lang->load('tjgeo.countries', JPATH_SITE, null, false, true); +$listOrder = $this->state->get('list.ordering'); +$listDirn = $this->state->get('list.direction'); +$user = Factory::getUser(); +?> +extra_sidebar)) +{ + $this->sidebar .= $this->extra_sidebar; +} +?> + +
+ sidebar)): ?> +
+ sidebar; ?> +
+
+ + +
+ +
+ + items)) : ?> +
 
+
+ +
+ + + + + + items[0]->state)): ?> + + + + + + + + + + items as $i => $item): + $canChange = $user->authorise('core.edit.state', 'com_tjfields'); + ?> + + = '3.0'): ?> + + items[0]->state)): ?> + + + + + + + + +
+ + + + + + + +
+ id); ?> + + state, $i, 'conditions.', $canChange, 'cb'); ?> + + show == 1) + { + $showHide = "Show"; + } + else + { + $showHide = "Hide"; + } + + if ($item->condition_match == 1) + { + $conditionMatch = "All"; + } + else + { + $conditionMatch = "Any"; + } + ?> +
+ model->getFieldName($item->field_to_show); ?> +
+
+
    +
  • + condition) as $condition) { ?> + operator == 1) + { + $operator = "Is"; + } + else + { + $operator = "Is Not"; + } + ?> +
  • model->getFieldName($conditionObj->field_on_show) . ' '; ?> + + model->getOptionName($conditionObj->field_on_show, $conditionObj->option); ?>
  • + +
+
+
+ + + +
+ + + +
+ + + + + + + +
+ +
diff --git a/administrator/views/conditions/tmpl/index.html b/administrator/views/conditions/tmpl/index.html new file mode 100644 index 00000000..42682b47 --- /dev/null +++ b/administrator/views/conditions/tmpl/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/administrator/views/conditions/view.html.php b/administrator/views/conditions/view.html.php new file mode 100644 index 00000000..4af24cec --- /dev/null +++ b/administrator/views/conditions/view.html.php @@ -0,0 +1,150 @@ + + * @package Tjfields + * @author Techjoomla + * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; + +jimport('joomla.application.component.view'); + +/** + * View class for a list of countries. + * + * @package Tjfields + * @subpackage com_tjfields + * @since 2.2 + */ +class TjfieldsViewConditions extends HtmlView +{ + protected $items; + + protected $pagination; + + protected $state; + + /** + * Display the view + * + * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * + * @return void + */ + public function display ($tpl = null) + { + $this->state = $this->get('State'); + $this->items = $this->get('Items'); + $this->pagination = $this->get('Pagination'); + $this->input = Factory::getApplication()->input; + $this->model = $this->getModel(); + + // Check for errors. + $errors = $this->get('Errors'); + + if (count($errors)) + { + throw new Exception(implode("\n", $errors)); + } + + TjfieldsHelper::addSubmenu('conditions'); + + if (JVERSION >= '3.0') + { + $this->sidebar = JHtmlSidebar::render(); + } + + $this->addToolbar(); + parent::display($tpl); + } + + /** + * Add the page title and toolbar. + * + * @return void + * + * @since 1.6 + */ + protected function addToolbar () + { + require_once JPATH_COMPONENT . '/helpers/tjfields.php'; + + // Let's get the extension name + $client = Factory::getApplication()->input->get('client', '', 'STRING'); + + $extention = explode('.', $client); + + $canDo = TjfieldsHelper::getActions($extention[0], 'condition'); + $state = $this->get('State'); + $extensionName = strtoupper($client); + + // Need to load the menu language file as mod_menu hasn't been loaded yet. + $lang = Factory::getLanguage(); + $lang->load($client, JPATH_ADMINISTRATOR, null, false, true); + + if (JVERSION >= '3.0') + { + JToolBarHelper::title(Text::_('COM_TJFIELDS_TITLE_CONDITIONS'), 'list'); + } + else + { + JToolBarHelper::title(Text::_('COM_TJFIELDS_TITLE_CONDITIONS'), 'conditions.png'); + } + + // Check if the form exists before showing the add/edit buttons + $formPath = JPATH_COMPONENT_ADMINISTRATOR . '/views/condition'; + + if (file_exists($formPath)) + { + if ($canDo->get('core.create')) + { + JToolBarHelper::addNew('condition.add', 'JTOOLBAR_NEW'); + } + + if ($canDo->get('core.edit') && isset($this->items[0])) + { + JToolBarHelper::editList('condition.edit', 'JTOOLBAR_EDIT'); + } + } + + if ($canDo->get('core.edit.state')) + { + if (isset($this->items[0]->state)) + { + JToolBarHelper::divider(); + JToolBarHelper::custom('conditions.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true); + JToolBarHelper::custom('conditions.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true); + } + } + + // Show trash and delete for components that uses the state field + if (isset($this->items[0]->state)) + { + if ($canDo->get('core.delete')) + { + JToolBarHelper::deleteList('', 'conditions.delete', 'JTOOLBAR_DELETE'); + JToolBarHelper::divider(); + } + } + + + if ($canDo->get('core.admin')) + { + JToolBarHelper::preferences('com_tjfields'); + } + + if (JVERSION >= '3.0') + { + // Set sidebar action + JHtmlSidebar::setAction('index.php?option=com_tjfields&view=conditions&client=' . $client); + } + + $this->extra_sidebar = ''; + } +} From a65fffc8ca0ec1c9bbd6ccd3c8f95cfc26484562 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Fri, 6 Jan 2023 16:09:42 +0530 Subject: [PATCH 02/13] Feature #184273 feat: Conditional fields implementation --- administrator/views/fields/view.html.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/administrator/views/fields/view.html.php b/administrator/views/fields/view.html.php index c40f7caf..490461d1 100755 --- a/administrator/views/fields/view.html.php +++ b/administrator/views/fields/view.html.php @@ -165,6 +165,10 @@ protected function addToolbar() { JToolBarHelper::preferences('com_tjfields'); } + + $btnAddCondtionalFields = '' . Text::_('COM_TJFIELDS_CONDITIONAL_FIELDS') . ''; + $toolbar->appendButton('Custom', $btnAddCondtionalFields); + $this->extra_sidebar = ''; $this->filterForm = $this->get('FilterForm'); From a11d817066d75dd51a738cbcca2fb0146dfd75c0 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Fri, 6 Jan 2023 16:52:42 +0530 Subject: [PATCH 03/13] Feature #184273 feat: Conditional fields implementation --- administrator/sql/install.mysql.utf8.sql | 7 ++++--- administrator/sql/updates/mysql/2.0.2.sql | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/administrator/sql/install.mysql.utf8.sql b/administrator/sql/install.mysql.utf8.sql index 9af89e54..7add8027 100755 --- a/administrator/sql/install.mysql.utf8.sql +++ b/administrator/sql/install.mysql.utf8.sql @@ -66,13 +66,14 @@ CREATE TABLE IF NOT EXISTS `#__tjfields_category_mapping` ( CREATE TABLE IF NOT EXISTS `#__tjfields_fields_conditions` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `state` tinyint(1) NOT NULL, `show` int(11) NOT NULL, `field_to_show` int(11) NOT NULL, `condition_match` int(11) NOT NULL, `field_on_show` int(11) NOT NULL, - `operator` int(11) NOT NULL, - `option` int(11) NOT NULL, - `state` tinyint(1) NOT NULL, + `condition` text CHARACTER NOT NULL, + `type_id` int NOT NULL, + `client` varchar(255) NOT NULL, `created_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , `created_by` INT(10) NOT NULL DEFAULT '0' , `modified_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , diff --git a/administrator/sql/updates/mysql/2.0.2.sql b/administrator/sql/updates/mysql/2.0.2.sql index 48dd297d..629ecbfe 100644 --- a/administrator/sql/updates/mysql/2.0.2.sql +++ b/administrator/sql/updates/mysql/2.0.2.sql @@ -2,13 +2,14 @@ ALTER TABLE `#__tjfields_fields_value` CHANGE `value` `value` mediumtext DEFAULT CREATE TABLE IF NOT EXISTS `#__tjfields_fields_conditions` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `state` tinyint(1) NOT NULL, `show` int(11) NOT NULL, `field_to_show` int(11) NOT NULL, `condition_match` int(11) NOT NULL, `field_on_show` int(11) NOT NULL, - `operator` int(11) NOT NULL, - `option` int(11) NOT NULL, - `state` tinyint(1) NOT NULL, + `condition` text CHARACTER NOT NULL, + `type_id` int NOT NULL, + `client` varchar(255) NOT NULL, `created_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , `created_by` INT(10) NOT NULL DEFAULT '0' , `modified_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , From 314f34a9aba8cddc47aaf88736b03ed7577b482d Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Mon, 9 Jan 2023 12:09:25 +0530 Subject: [PATCH 04/13] Feature #184273 feat: Conditional fields implementation --- administrator/controllers/condition.php | 3 +-- administrator/controllers/conditions.php | 3 +-- administrator/models/condition.php | 3 +-- administrator/models/conditions.php | 3 +-- administrator/models/fields/conditionalfields.php | 3 +-- administrator/models/fields/spcialfields.php | 3 +-- administrator/models/fields/specialfieldsoptions.php | 3 +-- administrator/tables/condition.php | 9 ++++----- administrator/views/condition/tmpl/edit.php | 3 +-- administrator/views/condition/view.html.php | 3 +-- administrator/views/conditions/tmpl/default.php | 5 ++--- administrator/views/conditions/view.html.php | 3 +-- 12 files changed, 16 insertions(+), 28 deletions(-) diff --git a/administrator/controllers/condition.php b/administrator/controllers/condition.php index 86dec1ce..38d07b69 100644 --- a/administrator/controllers/condition.php +++ b/administrator/controllers/condition.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/controllers/conditions.php b/administrator/controllers/conditions.php index fea4001c..36128146 100644 --- a/administrator/controllers/conditions.php +++ b/administrator/controllers/conditions.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/models/condition.php b/administrator/models/condition.php index 01ec1949..ea679c00 100644 --- a/administrator/models/condition.php +++ b/administrator/models/condition.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/models/conditions.php b/administrator/models/conditions.php index 61a27b9a..8f14797e 100644 --- a/administrator/models/conditions.php +++ b/administrator/models/conditions.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/models/fields/conditionalfields.php b/administrator/models/fields/conditionalfields.php index e8715c94..35238d1f 100644 --- a/administrator/models/fields/conditionalfields.php +++ b/administrator/models/fields/conditionalfields.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/models/fields/spcialfields.php b/administrator/models/fields/spcialfields.php index 9275acd3..15f06079 100644 --- a/administrator/models/fields/spcialfields.php +++ b/administrator/models/fields/spcialfields.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/models/fields/specialfieldsoptions.php b/administrator/models/fields/specialfieldsoptions.php index 2be7e89d..26b81cad 100644 --- a/administrator/models/fields/specialfieldsoptions.php +++ b/administrator/models/fields/specialfieldsoptions.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/tables/condition.php b/administrator/tables/condition.php index 9917e7c8..3d85962f 100644 --- a/administrator/tables/condition.php +++ b/administrator/tables/condition.php @@ -1,10 +1,9 @@ + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. */ // No direct access diff --git a/administrator/views/condition/tmpl/edit.php b/administrator/views/condition/tmpl/edit.php index 4c09f246..33039da6 100644 --- a/administrator/views/condition/tmpl/edit.php +++ b/administrator/views/condition/tmpl/edit.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/views/condition/view.html.php b/administrator/views/condition/view.html.php index b377cf0b..89685aa4 100644 --- a/administrator/views/condition/view.html.php +++ b/administrator/views/condition/view.html.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/views/conditions/tmpl/default.php b/administrator/views/conditions/tmpl/default.php index 46f45ac6..5c27e704 100644 --- a/administrator/views/conditions/tmpl/default.php +++ b/administrator/views/conditions/tmpl/default.php @@ -1,9 +1,8 @@ - * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ diff --git a/administrator/views/conditions/view.html.php b/administrator/views/conditions/view.html.php index 4af24cec..6ef83c4b 100644 --- a/administrator/views/conditions/view.html.php +++ b/administrator/views/conditions/view.html.php @@ -1,9 +1,8 @@ * @package Tjfields * @author Techjoomla - * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ From 342c143f1d2b4dd938aa29b5d628db778da35703 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Mon, 9 Jan 2023 12:18:27 +0530 Subject: [PATCH 05/13] Feature #184273 feat: Conditional fields implementation --- administrator/views/condition/view.html.php | 13 ++++++------ administrator/views/conditions/view.html.php | 21 ++++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/administrator/views/condition/view.html.php b/administrator/views/condition/view.html.php index 89685aa4..3c506e84 100644 --- a/administrator/views/condition/view.html.php +++ b/administrator/views/condition/view.html.php @@ -11,6 +11,7 @@ use Joomla\CMS\MVC\View\HtmlView; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; jimport('joomla.application.component.view'); @@ -89,11 +90,11 @@ protected function addToolbar() if (JVERSION >= '3.0') { - JToolBarHelper::title($viewTitle, 'pencil-2'); + ToolbarHelper::title($viewTitle, 'pencil-2'); } else { - JToolBarHelper::title($viewTitle, 'condition.png'); + ToolbarHelper::title($viewTitle, 'condition.png'); } if (isset($this->item->checked_out)) @@ -112,17 +113,17 @@ protected function addToolbar() // If not checked out, can save the item. if (! $checkedOut && ($canDo->get('core.edit') || ($canDo->get('core.create')))) { - JToolBarHelper::apply('condition.apply', 'JTOOLBAR_APPLY'); - JToolBarHelper::save('condition.save', 'JTOOLBAR_SAVE'); + ToolbarHelper::apply('condition.apply', 'JTOOLBAR_APPLY'); + ToolbarHelper::save('condition.save', 'JTOOLBAR_SAVE'); } if (empty($this->item->id)) { - JToolBarHelper::cancel('condition.cancel', 'JTOOLBAR_CANCEL'); + ToolbarHelper::cancel('condition.cancel', 'JTOOLBAR_CANCEL'); } else { - JToolBarHelper::cancel('condition.cancel', 'JTOOLBAR_CLOSE'); + ToolbarHelper::cancel('condition.cancel', 'JTOOLBAR_CLOSE'); } } } diff --git a/administrator/views/conditions/view.html.php b/administrator/views/conditions/view.html.php index 6ef83c4b..f23bbd14 100644 --- a/administrator/views/conditions/view.html.php +++ b/administrator/views/conditions/view.html.php @@ -11,6 +11,7 @@ use Joomla\CMS\MVC\View\HtmlView; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; jimport('joomla.application.component.view'); @@ -89,11 +90,11 @@ protected function addToolbar () if (JVERSION >= '3.0') { - JToolBarHelper::title(Text::_('COM_TJFIELDS_TITLE_CONDITIONS'), 'list'); + ToolbarHelper::title(Text::_('COM_TJFIELDS_TITLE_CONDITIONS'), 'list'); } else { - JToolBarHelper::title(Text::_('COM_TJFIELDS_TITLE_CONDITIONS'), 'conditions.png'); + ToolbarHelper::title(Text::_('COM_TJFIELDS_TITLE_CONDITIONS'), 'conditions.png'); } // Check if the form exists before showing the add/edit buttons @@ -103,12 +104,12 @@ protected function addToolbar () { if ($canDo->get('core.create')) { - JToolBarHelper::addNew('condition.add', 'JTOOLBAR_NEW'); + ToolbarHelper::addNew('condition.add', 'JTOOLBAR_NEW'); } if ($canDo->get('core.edit') && isset($this->items[0])) { - JToolBarHelper::editList('condition.edit', 'JTOOLBAR_EDIT'); + ToolbarHelper::editList('condition.edit', 'JTOOLBAR_EDIT'); } } @@ -116,9 +117,9 @@ protected function addToolbar () { if (isset($this->items[0]->state)) { - JToolBarHelper::divider(); - JToolBarHelper::custom('conditions.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true); - JToolBarHelper::custom('conditions.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true); + ToolbarHelper::divider(); + ToolbarHelper::custom('conditions.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true); + ToolbarHelper::custom('conditions.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true); } } @@ -127,15 +128,15 @@ protected function addToolbar () { if ($canDo->get('core.delete')) { - JToolBarHelper::deleteList('', 'conditions.delete', 'JTOOLBAR_DELETE'); - JToolBarHelper::divider(); + ToolbarHelper::deleteList('', 'conditions.delete', 'JTOOLBAR_DELETE'); + ToolbarHelper::divider(); } } if ($canDo->get('core.admin')) { - JToolBarHelper::preferences('com_tjfields'); + ToolbarHelper::preferences('com_tjfields'); } if (JVERSION >= '3.0') From 835426cb7f945ef34eb24aca0cfac42194b4a847 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Tue, 17 Jan 2023 12:31:33 +0530 Subject: [PATCH 06/13] Feature #184273 feat: Updated MR --- administrator/controllers/conditions.php | 56 +++++++++++++++++++ administrator/models/condition.php | 8 +-- administrator/models/conditions.php | 1 + administrator/models/forms/condition.xml | 2 + administrator/sql/install.mysql.utf8.sql | 2 +- administrator/sql/updates/mysql/2.0.2.sql | 2 +- .../views/conditions/tmpl/default.php | 2 +- 7 files changed, 66 insertions(+), 7 deletions(-) diff --git a/administrator/controllers/conditions.php b/administrator/controllers/conditions.php index 36128146..848a1111 100644 --- a/administrator/controllers/conditions.php +++ b/administrator/controllers/conditions.php @@ -12,6 +12,8 @@ use Joomla\CMS\MVC\Controller\AdminController; use Joomla\CMS\Log\Log; use Joomla\CMS\Language\Text; +use Joomla\CMS\Session\Session; +use Joomla\Utilities\ArrayHelper; jimport('joomla.application.component.controlleradmin'); @@ -87,6 +89,16 @@ public function publish() { $ntext = 'COM_TJFIELDS_N_CONDITIONS_UNPUBLISHED'; } + + // Generate xml here + $TjfieldsHelper = new TjfieldsHelper; + $client_form = explode('.', $client); + $client_type = $client_form[1]; + + $data = array(); + $data['client'] = $client; + $data['client_type'] = $client_type; + $TjfieldsHelper->generateXml($data); $this->setMessage(Text::plural($ntext, count($cid))); } @@ -98,4 +110,48 @@ public function publish() $this->setRedirect('index.php?option=com_tjfields&view=conditions&client=' . $client); } + + public function delete() + { + //GET CLIENT AND CLIENT TYPE + $app = Factory::getApplication(); + $input = $app->input; + $client = $input->get('client','','STRING'); + $client_form = explode('.',$client); + $client_type = $client_form[1]; + + // Get items to remove from the request. + $cid = $app->input->get('cid', array(), 'array'); + + if (!is_array($cid) || count($cid) < 1) + { + Log::add(Text::_($this->text_prefix . '_NO_ITEM_SELECTED'), Log::WARNING, 'jerror'); + } + else + { + // Get the model. + $model = $this->getModel(); + + // Make sure the item ids are integers + ArrayHelper::toInteger($cid); + + // Remove the items. + if ($model->delete($cid)) + { + $TjfieldsHelper = new TjfieldsHelper(); + $data = array(); + $data['client'] = $client; + $data['client_type'] = $client_type; + $TjfieldsHelper->generateXml($data); + $ntext = $this->text_prefix . '_N_ITEMS_DELETED'; + } + else + { + $this->setMessage($model->getError()); + } + } + + $this->setMessage(Text::plural($ntext, count($cid))); + $this->setRedirect('index.php?option=com_tjfields&view=conditions&client='.$client, false); + } } diff --git a/administrator/models/condition.php b/administrator/models/condition.php index ea679c00..9b170556 100644 --- a/administrator/models/condition.php +++ b/administrator/models/condition.php @@ -194,10 +194,10 @@ public function save($data) $client_form = explode('.', $client); $client_type = $client_form[1]; - $data2 = array(); - $data2['client'] = $client; - $data2['client_type'] = $client_type; - $TjfieldsHelper->generateXml($data2); + $dataOfClient = array(); + $dataOfClient['client'] = $client; + $dataOfClient['client_type'] = $client_type; + $TjfieldsHelper->generateXml($dataOfClient); // End xml diff --git a/administrator/models/conditions.php b/administrator/models/conditions.php index 8f14797e..b9e69913 100644 --- a/administrator/models/conditions.php +++ b/administrator/models/conditions.php @@ -201,6 +201,7 @@ public function getConditionalFields() $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select('field_to_show FROM #__tjfields_fields_conditions'); + $query->where('state = 1'); $db->setQuery($query); $conditionalFields = $db->loadColumn(); diff --git a/administrator/models/forms/condition.xml b/administrator/models/forms/condition.xml index ba6b5223..074fe6e1 100644 --- a/administrator/models/forms/condition.xml +++ b/administrator/models/forms/condition.xml @@ -5,6 +5,8 @@ label="COM_TJFIELDS_FORM_LBL_CONDITION_ID" description="COM_TJFIELDS_FORM_DESC_CONDITION_ID" filter="safehtml" /> + +
- + From 6014e20ff7917eabcf9f9b8e6aa6376f6848bcbb Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Wed, 25 Jan 2023 13:04:22 +0530 Subject: [PATCH 07/13] Task #192634 chore: Updated MR for hide functionality --- administrator/helpers/tjfields.php | 12 ++++++++++-- administrator/models/conditions.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/administrator/helpers/tjfields.php b/administrator/helpers/tjfields.php index 9e357531..2cce5466 100755 --- a/administrator/helpers/tjfields.php +++ b/administrator/helpers/tjfields.php @@ -323,7 +323,7 @@ public function createXml($data, $fields, $category = null) $field->addAttribute('type', $f->type); $field->addAttribute('label', $f->label); $field->addAttribute('description', $f->description); - + if (in_array($f->id, $conditionalFields)) { $conditions = $conditionsModel->getConditions($f->id); @@ -342,7 +342,15 @@ public function createXml($data, $fields, $category = null) $jsonDecoded = json_decode($condition1); $fieldName = $conditionsModel->getFieldNameById($jsonDecoded->field_on_show); $optionValue = $conditionsModel->getOptionName($jsonDecoded->field_on_show, $jsonDecoded->option); - $operator = ($jsonDecoded->operator == 1) ? ":" : "!:"; + + if ($condition->show == 1) + { + $operator = ($jsonDecoded->operator == 1) ? ":" : "!:"; + } + else + { + $operator = ($jsonDecoded->operator == 1) ? "!:" : ":"; + } $showonCondition .= $fieldName . $operator . $optionValue; diff --git a/administrator/models/conditions.php b/administrator/models/conditions.php index b9e69913..21c2783a 100644 --- a/administrator/models/conditions.php +++ b/administrator/models/conditions.php @@ -212,7 +212,7 @@ public function getConditions($id) { $db = Factory::getDbo(); $query = $db->getQuery(true); - $query->select($db->qn(array('condition','condition_match'))); + $query->select($db->qn(array('condition','condition_match','show'))); $query->from('#__tjfields_fields_conditions'); $query->where('field_to_show=' . $id); $db->setQuery($query); From 7ff577867623bddd0793666815709497c9284237 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Thu, 2 Feb 2023 11:16:16 +0530 Subject: [PATCH 08/13] Feature #184273 feat: Resolved comments --- administrator/controllers/condition.php | 2 -- administrator/controllers/conditions.php | 2 -- administrator/models/condition.php | 2 -- administrator/models/conditions.php | 18 ++++++++++++++++-- administrator/views/condition/view.html.php | 2 -- administrator/views/conditions/view.html.php | 2 -- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/administrator/controllers/condition.php b/administrator/controllers/condition.php index 38d07b69..5a40601b 100644 --- a/administrator/controllers/condition.php +++ b/administrator/controllers/condition.php @@ -12,8 +12,6 @@ use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\MVC\Controller\FormController; -jimport('joomla.application.component.controllerform'); - /** * Country form controller class. * diff --git a/administrator/controllers/conditions.php b/administrator/controllers/conditions.php index 848a1111..7a974e8c 100644 --- a/administrator/controllers/conditions.php +++ b/administrator/controllers/conditions.php @@ -15,8 +15,6 @@ use Joomla\CMS\Session\Session; use Joomla\Utilities\ArrayHelper; -jimport('joomla.application.component.controlleradmin'); - /** * Countries list controller class. * diff --git a/administrator/models/condition.php b/administrator/models/condition.php index 9b170556..69e712b5 100644 --- a/administrator/models/condition.php +++ b/administrator/models/condition.php @@ -12,8 +12,6 @@ use Joomla\CMS\Table\Table; use Joomla\CMS\Factory; -jimport('joomla.application.component.modeladmin'); - /** * Item Model for Condition. * diff --git a/administrator/models/conditions.php b/administrator/models/conditions.php index 21c2783a..a2bf359f 100644 --- a/administrator/models/conditions.php +++ b/administrator/models/conditions.php @@ -12,8 +12,6 @@ use Joomla\CMS\Factory; use Joomla\CMS\Component\ComponentHelper; -jimport('joomla.application.component.modellist'); - /** * Methods supporting a list of countries records. * @@ -232,4 +230,20 @@ public function getFieldNameById($id) return $name; } + + public function getConditionalFieldsData($client) + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query->select('tfc.*,tf.name'); + $query->from('`#__tjfields_fields_conditions` AS tfc'); + $query->join('LEFT', '`#__tjfields_fields` AS tf ON tf.id=tfc.field_to_show'); + $query->where($db->quoteName('tfc.state') . ' = ' . $db->quote('1')); + $query->where($db->quoteName('tfc.client') . ' = ' . $db->quote($client)); + + $db->setQuery($query); + $conditionalFields = $db->loadColumn(); + + return $conditionalFields; + } } diff --git a/administrator/views/condition/view.html.php b/administrator/views/condition/view.html.php index 3c506e84..91cbbe6e 100644 --- a/administrator/views/condition/view.html.php +++ b/administrator/views/condition/view.html.php @@ -13,8 +13,6 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Toolbar\ToolbarHelper; -jimport('joomla.application.component.view'); - /** * View class for editing condition. * diff --git a/administrator/views/conditions/view.html.php b/administrator/views/conditions/view.html.php index f23bbd14..73b5361c 100644 --- a/administrator/views/conditions/view.html.php +++ b/administrator/views/conditions/view.html.php @@ -13,8 +13,6 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Toolbar\ToolbarHelper; -jimport('joomla.application.component.view'); - /** * View class for a list of countries. * From a01d66365bc336dc2615e5a9677b3045a3f08a48 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Thu, 2 Feb 2023 16:09:19 +0530 Subject: [PATCH 09/13] Feature #184273 feat: comments resolved --- administrator/controllers/conditions.php | 4 +- administrator/helpers/tjfields.php | 11 ++- administrator/models/conditions.php | 79 ++++--------------- .../models/fields/conditionalfields.php | 8 +- administrator/models/fields/spcialfields.php | 8 +- administrator/sql/install.mysql.utf8.sql | 14 ++-- administrator/sql/updates/mysql/2.0.2.sql | 14 ++-- .../views/conditions/tmpl/default.php | 25 +++++- 8 files changed, 70 insertions(+), 93 deletions(-) diff --git a/administrator/controllers/conditions.php b/administrator/controllers/conditions.php index 7a974e8c..6502e398 100644 --- a/administrator/controllers/conditions.php +++ b/administrator/controllers/conditions.php @@ -59,7 +59,7 @@ public function publish() ); $task = $this->getTask(); - $value = JArrayHelper::getValue($data, $task, 0, 'int'); + $value = ArrayHelper::getValue($data, $task, 0, 'int'); // Get some variables from the request if (empty($cid)) @@ -72,7 +72,7 @@ public function publish() $model = $this->getModel(); // Make sure the item ids are integers - JArrayHelper::toInteger($cid); + ArrayHelper::toInteger($cid); // Publish the items. try diff --git a/administrator/helpers/tjfields.php b/administrator/helpers/tjfields.php index 2cce5466..f9e91598 100755 --- a/administrator/helpers/tjfields.php +++ b/administrator/helpers/tjfields.php @@ -340,9 +340,16 @@ public function createXml($data, $fields, $category = null) foreach (json_decode($condition->condition) as $condition1) { $jsonDecoded = json_decode($condition1); - $fieldName = $conditionsModel->getFieldNameById($jsonDecoded->field_on_show); - $optionValue = $conditionsModel->getOptionName($jsonDecoded->field_on_show, $jsonDecoded->option); + + Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/tables'); + $fieldTable = Table::getInstance('field', 'TjfieldsTable'); + $fieldTable->load((int) $jsonDecoded->field_on_show); + $fieldName = $fieldTable->name; + $optionTable = Table::getInstance('Option', 'TjfieldsTable'); + $optionTable->load(array('field_id' => $jsonDecoded->field_on_show, 'id' => $jsonDecoded->option)); + $optionValue = $optionTable->value; + if ($condition->show == 1) { $operator = ($jsonDecoded->operator == 1) ? ":" : "!:"; diff --git a/administrator/models/conditions.php b/administrator/models/conditions.php index a2bf359f..d0a65822 100644 --- a/administrator/models/conditions.php +++ b/administrator/models/conditions.php @@ -139,61 +139,12 @@ protected function getListQuery() return $query; } - - /** - * Method to get a list of countries. - * - * @return mixed An array of data items on success, false on failure. - * - * @since 1.6.1 - */ - public function getItems() - { - $items = parent::getItems(); - - return $items; - } - - /** - * Get option which are stored in field option table. - * - * @param INT $field_id field id - * - * @return array of option for the particular field - */ - public function getFieldName($fieldId) - { - $db = Factory::getDbo(); - $query = $db->getQuery(true); - $query->select('label'); - $query->from('#__tjfields_fields AS tf'); - $query->where('tf.id=' . $fieldId); - $db->setQuery($query); - $name = $db->loadResult(); - - return $name; - } /** - * Get option which are stored in field option table. - * - * @param INT $field_id field id - * + * Get conditional fields. + * * @return array of option for the particular field */ - public function getOptionName($fieldId, $optionId) - { - $db = Factory::getDbo(); - $query = $db->getQuery(true); - $query->select('value FROM #__tjfields_options'); - $query->where('field_id=' . $fieldId); - $query->where('id=' . $optionId); - $db->setQuery($query); - $optionName = $db->loadResult(); - - return $optionName; - } - public function getConditionalFields() { $db = Factory::getDbo(); @@ -206,6 +157,13 @@ public function getConditionalFields() return $conditionalFields; } + /** + * Get conditions. + * + * @param int $id id. + * + * @return array of option for the particular field + */ public function getConditions($id) { $db = Factory::getDbo(); @@ -218,19 +176,14 @@ public function getConditions($id) return $conditions; } - - public function getFieldNameById($id) - { - $db = Factory::getDbo(); - $query = $db->getQuery(true); - $query->select('name FROM #__tjfields_fields'); - $query->where('id=' . $id); - $db->setQuery($query); - $name = $db->loadResult(); - - return $name; - } + /** + * Get conditional fields data. + * + * @param string $client client. + * + * @return array of option for the particular field + */ public function getConditionalFieldsData($client) { $db = Factory::getDbo(); diff --git a/administrator/models/fields/conditionalfields.php b/administrator/models/fields/conditionalfields.php index 35238d1f..9da82f03 100644 --- a/administrator/models/fields/conditionalfields.php +++ b/administrator/models/fields/conditionalfields.php @@ -48,15 +48,15 @@ protected function getOptions() $db = Factory::getDbo(); $query = $db->getQuery(true); $client = Factory::getApplication()->input->get('client', '', 'STRING'); - + // Select the required fields from the table. - $query->select('tf.id, tf.label'); + $query->select($db->qn(array('tf.id', 'tf.label'))); $query->from('`#__tjfields_fields` AS tf'); - $query->where('tf.state = 1'); + $query->where($db->quoteName('tf.state') . ' = ' . $db->quote('1')); if ($client) { - $query->where('tf.client = "' . $client . '"'); + $query->where($db->quoteName('tf.client') . ' = ' . $db->quote($client)); } $query->order($db->escape('tf.ordering ASC')); diff --git a/administrator/models/fields/spcialfields.php b/administrator/models/fields/spcialfields.php index 15f06079..d1c5a549 100644 --- a/administrator/models/fields/spcialfields.php +++ b/administrator/models/fields/spcialfields.php @@ -50,15 +50,15 @@ protected function getOptions() $client = Factory::getApplication()->input->get('client', '', 'STRING'); // Select the required fields from the table. - $query->select('tf.id, tf.label'); + $query->select($db->qn(array('tf.id', 'tf.label'))); $query->from('`#__tjfields_fields` AS tf'); - $query->where('tf.type IN ("tjlist","radio","checkbox")'); - $query->where('tf.state = 1'); + $query->where($db->quoteName('tf.type') . ' IN ("tjlist","radio","checkbox")'); + $query->where($db->quoteName('tf.state') . ' = ' . $db->quote('1')); if ($client) { - $query->where('tf.client = "' . $client . '"'); + $query->where($db->quoteName('tf.client') . ' = ' . $db->quote($client)); } $query->order($db->escape('tf.ordering ASC')); diff --git a/administrator/sql/install.mysql.utf8.sql b/administrator/sql/install.mysql.utf8.sql index 80ef5328..4b2ed525 100755 --- a/administrator/sql/install.mysql.utf8.sql +++ b/administrator/sql/install.mysql.utf8.sql @@ -66,14 +66,14 @@ CREATE TABLE IF NOT EXISTS `#__tjfields_category_mapping` ( CREATE TABLE IF NOT EXISTS `#__tjfields_fields_conditions` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `state` tinyint(1) NOT NULL, - `show` int(11) NOT NULL, - `field_to_show` int(11) NOT NULL, - `condition_match` int(11) NOT NULL, - `field_on_show` int(11) NOT NULL, + `state` tinyint(1) NOT NULL DEFAULT 1, + `show` int(11) NOT NULL DEFAULT 1, + `field_to_show` int(11) NOT NULL DEFAULT 0, + `condition_match` int(11) NOT NULL DEFAULT 1, + `field_on_show` int(11) NOT NULL DEFAULT 0, `condition` text NOT NULL, - `type_id` int NOT NULL, - `client` varchar(255) NOT NULL, + `type_id` int NOT NULL DEFAULT 0, + `client` varchar(255) NOT NULL DEFAULT '', `created_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , `created_by` INT(10) NOT NULL DEFAULT '0' , `modified_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , diff --git a/administrator/sql/updates/mysql/2.0.2.sql b/administrator/sql/updates/mysql/2.0.2.sql index 587c460a..00912534 100644 --- a/administrator/sql/updates/mysql/2.0.2.sql +++ b/administrator/sql/updates/mysql/2.0.2.sql @@ -2,14 +2,14 @@ ALTER TABLE `#__tjfields_fields_value` CHANGE `value` `value` mediumtext DEFAULT CREATE TABLE IF NOT EXISTS `#__tjfields_fields_conditions` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `state` tinyint(1) NOT NULL, - `show` int(11) NOT NULL, - `field_to_show` int(11) NOT NULL, - `condition_match` int(11) NOT NULL, - `field_on_show` int(11) NOT NULL, + `state` tinyint(1) NOT NULL DEFAULT 1, + `show` int(11) NOT NULL DEFAULT 1, + `field_to_show` int(11) NOT NULL DEFAULT 0, + `condition_match` int(11) NOT NULL DEFAULT 1, + `field_on_show` int(11) NOT NULL DEFAULT 0, `condition` text NOT NULL, - `type_id` int NOT NULL, - `client` varchar(255) NOT NULL, + `type_id` int NOT NULL DEFAULT 0, + `client` varchar(255) NOT NULL DEFAULT '', `created_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , `created_by` INT(10) NOT NULL DEFAULT '0' , `modified_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , diff --git a/administrator/views/conditions/tmpl/default.php b/administrator/views/conditions/tmpl/default.php index c9ab11f2..b3b5e17e 100644 --- a/administrator/views/conditions/tmpl/default.php +++ b/administrator/views/conditions/tmpl/default.php @@ -12,6 +12,7 @@ use Joomla\CMS\Router\Route; use Joomla\CMS\Language\Text; use Joomla\CMS\Factory; +use Joomla\CMS\Table\Table; HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); @@ -109,7 +110,13 @@ } ?>
- model->getFieldName($item->field_to_show); ?> + load((int) $item->field_on_show); + $fieldName = $fieldTable->name; + + echo $showHide . ' - ' . $fieldName; ?>
    @@ -126,10 +133,20 @@ { $operator = "Is Not"; } - ?> -
  • model->getFieldName($conditionObj->field_on_show) . ' '; ?> + ?> + load(array('field_id' => $conditionObj->field_on_show, 'id' => $conditionObj->option)); + $optionValue = $optionTable->value; + ?> +
  • load((int) $conditionObj->field_on_show); + $fieldsName = $fieldsTable->name; + + echo $fieldsName . ' '; ?> - model->getOptionName($conditionObj->field_on_show, $conditionObj->option); ?>
  • +
From e1d44a03bacbe75cba5e57707c15a1728abf460e Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Thu, 2 Feb 2023 16:39:51 +0530 Subject: [PATCH 10/13] Feature #184273 feat: comments resolved --- administrator/views/condition/tmpl/edit.php | 151 ++------------ .../views/condition/tmpl/edit_bs2.php | 138 +++++++++++++ .../views/condition/tmpl/edit_bs5.php | 138 +++++++++++++ .../views/conditions/tmpl/default.php | 184 ++---------------- .../views/conditions/tmpl/default_bs2.php | 177 +++++++++++++++++ .../views/conditions/tmpl/default_bs5.php | 177 +++++++++++++++++ 6 files changed, 661 insertions(+), 304 deletions(-) create mode 100644 administrator/views/condition/tmpl/edit_bs2.php create mode 100644 administrator/views/condition/tmpl/edit_bs5.php create mode 100644 administrator/views/conditions/tmpl/default_bs2.php create mode 100644 administrator/views/conditions/tmpl/default_bs5.php diff --git a/administrator/views/condition/tmpl/edit.php b/administrator/views/condition/tmpl/edit.php index 33039da6..e97d4434 100644 --- a/administrator/views/condition/tmpl/edit.php +++ b/administrator/views/condition/tmpl/edit.php @@ -1,138 +1,21 @@ - * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. - * @license GNU General Public License version 2 or later. + * @package TJ-Fields + * @subpackage com_tjfields + * + * @author Techjoomla + * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access -defined('_JEXEC') or die(); -use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Router\Route; -use Joomla\CMS\Language\Text; - -HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); - -HTMLHelper::_('behavior.formvalidation'); -HTMLHelper::_('behavior.keepalive'); -?> - - - -
-
- -
-
-
-
- - - - -
-
form->getLabel('show'); ?>
-
form->getInput('show'); ?>
-
-
-
form->getLabel('field_to_show'); ?>
-
form->getInput('field_to_show'); ?>
-
-
-
form->getLabel('condition_match'); ?>
-
form->getInput('condition_match'); ?>
-
-
-
form->getLabel('condition'); ?>
-
form->getInput('condition'); ?>
-
- -
-
-
- - - - - -
-
-
- +// Do not allow direct access +defined('_JEXEC') or die('Restricted access'); + +if (JVERSION < '4.0.0') +{ + echo $this->loadTemplate('bs2'); +} +else +{ + echo $this->loadTemplate('bs5'); +} diff --git a/administrator/views/condition/tmpl/edit_bs2.php b/administrator/views/condition/tmpl/edit_bs2.php new file mode 100644 index 00000000..33039da6 --- /dev/null +++ b/administrator/views/condition/tmpl/edit_bs2.php @@ -0,0 +1,138 @@ + + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + +HTMLHelper::_('behavior.formvalidation'); +HTMLHelper::_('behavior.keepalive'); +?> + + + +
+
+ +
+
+
+
+ + + + +
+
form->getLabel('show'); ?>
+
form->getInput('show'); ?>
+
+
+
form->getLabel('field_to_show'); ?>
+
form->getInput('field_to_show'); ?>
+
+
+
form->getLabel('condition_match'); ?>
+
form->getInput('condition_match'); ?>
+
+
+
form->getLabel('condition'); ?>
+
form->getInput('condition'); ?>
+
+ +
+
+
+ + + + + +
+
+
+ diff --git a/administrator/views/condition/tmpl/edit_bs5.php b/administrator/views/condition/tmpl/edit_bs5.php new file mode 100644 index 00000000..33039da6 --- /dev/null +++ b/administrator/views/condition/tmpl/edit_bs5.php @@ -0,0 +1,138 @@ + + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + +HTMLHelper::_('behavior.formvalidation'); +HTMLHelper::_('behavior.keepalive'); +?> + + + +
+
+ +
+
+
+
+ + + + +
+
form->getLabel('show'); ?>
+
form->getInput('show'); ?>
+
+
+
form->getLabel('field_to_show'); ?>
+
form->getInput('field_to_show'); ?>
+
+
+
form->getLabel('condition_match'); ?>
+
form->getInput('condition_match'); ?>
+
+
+
form->getLabel('condition'); ?>
+
form->getInput('condition'); ?>
+
+ +
+
+
+ + + + + +
+
+
+ diff --git a/administrator/views/conditions/tmpl/default.php b/administrator/views/conditions/tmpl/default.php index b3b5e17e..e97d4434 100644 --- a/administrator/views/conditions/tmpl/default.php +++ b/administrator/views/conditions/tmpl/default.php @@ -1,177 +1,21 @@ - * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. - * @license GNU General Public License version 2 or later. + * @package TJ-Fields + * @subpackage com_tjfields + * + * @author Techjoomla + * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ -// No direct access -defined('_JEXEC') or die(); -use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Router\Route; -use Joomla\CMS\Language\Text; -use Joomla\CMS\Factory; -use Joomla\CMS\Table\Table; +// Do not allow direct access +defined('_JEXEC') or die('Restricted access'); -HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); - -// Load lang file for countries -$lang = Factory::getLanguage(); -$lang->load('tjgeo.countries', JPATH_SITE, null, false, true); -$listOrder = $this->state->get('list.ordering'); -$listDirn = $this->state->get('list.direction'); -$user = Factory::getUser(); -?> -extra_sidebar)) +if (JVERSION < '4.0.0') { - $this->sidebar .= $this->extra_sidebar; + echo $this->loadTemplate('bs2'); +} +else +{ + echo $this->loadTemplate('bs5'); } -?> - -
- sidebar)): ?> -
- sidebar; ?> -
-
- - -
- -
- - items)) : ?> -
 
-
- -
- - - - - - items[0]->state)): ?> - - - - - - - - - - items as $i => $item): - $canChange = $user->authorise('core.edit.state', 'com_tjfields'); - ?> - - = '3.0'): ?> - - items[0]->state)): ?> - - - - - - - - -
- - - - - - - -
- id); ?> - - state, $i, 'conditions.', $canChange, 'cb'); ?> - - show == 1) - { - $showHide = "Show"; - } - else - { - $showHide = "Hide"; - } - - if ($item->condition_match == 1) - { - $conditionMatch = "All"; - } - else - { - $conditionMatch = "Any"; - } - ?> -
- load((int) $item->field_on_show); - $fieldName = $fieldTable->name; - - echo $showHide . ' - ' . $fieldName; ?> -
-
-
    -
  • - condition) as $condition) { ?> - operator == 1) - { - $operator = "Is"; - } - else - { - $operator = "Is Not"; - } - ?> - load(array('field_id' => $conditionObj->field_on_show, 'id' => $conditionObj->option)); - $optionValue = $optionTable->value; - ?> -
  • load((int) $conditionObj->field_on_show); - $fieldsName = $fieldsTable->name; - - echo $fieldsName . ' '; ?> - -
  • - -
-
-
- - - -
- - - -
- - - - - - - -
- -
diff --git a/administrator/views/conditions/tmpl/default_bs2.php b/administrator/views/conditions/tmpl/default_bs2.php new file mode 100644 index 00000000..b3b5e17e --- /dev/null +++ b/administrator/views/conditions/tmpl/default_bs2.php @@ -0,0 +1,177 @@ + + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Factory; +use Joomla\CMS\Table\Table; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + +// Load lang file for countries +$lang = Factory::getLanguage(); +$lang->load('tjgeo.countries', JPATH_SITE, null, false, true); +$listOrder = $this->state->get('list.ordering'); +$listDirn = $this->state->get('list.direction'); +$user = Factory::getUser(); +?> +extra_sidebar)) +{ + $this->sidebar .= $this->extra_sidebar; +} +?> + +
+ sidebar)): ?> +
+ sidebar; ?> +
+
+ + +
+ +
+ + items)) : ?> +
 
+
+ +
+ + + + + + items[0]->state)): ?> + + + + + + + + + + items as $i => $item): + $canChange = $user->authorise('core.edit.state', 'com_tjfields'); + ?> + + = '3.0'): ?> + + items[0]->state)): ?> + + + + + + + + +
+ + + + + + + +
+ id); ?> + + state, $i, 'conditions.', $canChange, 'cb'); ?> + + show == 1) + { + $showHide = "Show"; + } + else + { + $showHide = "Hide"; + } + + if ($item->condition_match == 1) + { + $conditionMatch = "All"; + } + else + { + $conditionMatch = "Any"; + } + ?> +
+ load((int) $item->field_on_show); + $fieldName = $fieldTable->name; + + echo $showHide . ' - ' . $fieldName; ?> +
+
+
    +
  • + condition) as $condition) { ?> + operator == 1) + { + $operator = "Is"; + } + else + { + $operator = "Is Not"; + } + ?> + load(array('field_id' => $conditionObj->field_on_show, 'id' => $conditionObj->option)); + $optionValue = $optionTable->value; + ?> +
  • load((int) $conditionObj->field_on_show); + $fieldsName = $fieldsTable->name; + + echo $fieldsName . ' '; ?> + +
  • + +
+
+
+ + + +
+ + + +
+ + + + + + + +
+ +
diff --git a/administrator/views/conditions/tmpl/default_bs5.php b/administrator/views/conditions/tmpl/default_bs5.php new file mode 100644 index 00000000..b3b5e17e --- /dev/null +++ b/administrator/views/conditions/tmpl/default_bs5.php @@ -0,0 +1,177 @@ + + * @copyright Copyright (c) 2009-2023 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die(); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Factory; +use Joomla\CMS\Table\Table; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + +// Load lang file for countries +$lang = Factory::getLanguage(); +$lang->load('tjgeo.countries', JPATH_SITE, null, false, true); +$listOrder = $this->state->get('list.ordering'); +$listDirn = $this->state->get('list.direction'); +$user = Factory::getUser(); +?> +extra_sidebar)) +{ + $this->sidebar .= $this->extra_sidebar; +} +?> + +
+ sidebar)): ?> +
+ sidebar; ?> +
+
+ + +
+ +
+ + items)) : ?> +
 
+
+ +
+ + + + + + items[0]->state)): ?> + + + + + + + + + + items as $i => $item): + $canChange = $user->authorise('core.edit.state', 'com_tjfields'); + ?> + + = '3.0'): ?> + + items[0]->state)): ?> + + + + + + + + +
+ + + + + + + +
+ id); ?> + + state, $i, 'conditions.', $canChange, 'cb'); ?> + + show == 1) + { + $showHide = "Show"; + } + else + { + $showHide = "Hide"; + } + + if ($item->condition_match == 1) + { + $conditionMatch = "All"; + } + else + { + $conditionMatch = "Any"; + } + ?> +
+ load((int) $item->field_on_show); + $fieldName = $fieldTable->name; + + echo $showHide . ' - ' . $fieldName; ?> +
+
+
    +
  • + condition) as $condition) { ?> + operator == 1) + { + $operator = "Is"; + } + else + { + $operator = "Is Not"; + } + ?> + load(array('field_id' => $conditionObj->field_on_show, 'id' => $conditionObj->option)); + $optionValue = $optionTable->value; + ?> +
  • load((int) $conditionObj->field_on_show); + $fieldsName = $fieldsTable->name; + + echo $fieldsName . ' '; ?> + +
  • + +
+
+
+ + + +
+ + + +
+ + + + + + + +
+ +
From de1a37e103e549b52c299f47af8774ee1d81c34c Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Fri, 3 Feb 2023 13:07:31 +0530 Subject: [PATCH 11/13] Feature #184273 feat: Conditional fields implementation --- administrator/views/conditions/tmpl/default_bs2.php | 6 +++--- administrator/views/conditions/tmpl/default_bs5.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/administrator/views/conditions/tmpl/default_bs2.php b/administrator/views/conditions/tmpl/default_bs2.php index b3b5e17e..3446ecb2 100644 --- a/administrator/views/conditions/tmpl/default_bs2.php +++ b/administrator/views/conditions/tmpl/default_bs2.php @@ -113,8 +113,8 @@ load((int) $item->field_on_show); - $fieldName = $fieldTable->name; + $fieldTable->load((int) $item->field_to_show); + $fieldName = $fieldTable->label; echo $showHide . ' - ' . $fieldName; ?>
@@ -142,7 +142,7 @@
  • load((int) $conditionObj->field_on_show); - $fieldsName = $fieldsTable->name; + $fieldsName = $fieldsTable->label; echo $fieldsName . ' '; ?> diff --git a/administrator/views/conditions/tmpl/default_bs5.php b/administrator/views/conditions/tmpl/default_bs5.php index b3b5e17e..3446ecb2 100644 --- a/administrator/views/conditions/tmpl/default_bs5.php +++ b/administrator/views/conditions/tmpl/default_bs5.php @@ -113,8 +113,8 @@ load((int) $item->field_on_show); - $fieldName = $fieldTable->name; + $fieldTable->load((int) $item->field_to_show); + $fieldName = $fieldTable->label; echo $showHide . ' - ' . $fieldName; ?>
  • @@ -142,7 +142,7 @@
  • load((int) $conditionObj->field_on_show); - $fieldsName = $fieldsTable->name; + $fieldsName = $fieldsTable->label; echo $fieldsName . ' '; ?> From 9224ede02823578fa2a72ce03278973b7e0f4fea Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Mon, 6 Feb 2023 21:32:35 +0530 Subject: [PATCH 12/13] Feature #184273 feat: Conditional fields implementation --- administrator/controllers/condition.php | 19 ++++++++++++++++--- administrator/helpers/tjfields.php | 6 ++++++ administrator/models/conditions.php | 1 + administrator/models/fields/spcialfields.php | 2 +- .../models/fields/specialfieldsoptions.php | 2 -- .../views/conditions/tmpl/default_bs2.php | 13 +++++++++---- .../views/conditions/tmpl/default_bs5.php | 13 +++++++++---- 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/administrator/controllers/condition.php b/administrator/controllers/condition.php index 5a40601b..f7da2cae 100644 --- a/administrator/controllers/condition.php +++ b/administrator/controllers/condition.php @@ -11,6 +11,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\MVC\Controller\FormController; +use Joomla\CMS\Table\Table; /** * Country form controller class. @@ -95,22 +96,34 @@ public function getFieldsOptions() $app = Factory::getApplication(); $fieldId = $app->input->get('fieldId', 0, 'INT'); + Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjfields/tables'); + $fieldTable = Table::getInstance('field', 'TjfieldsTable'); + $fieldTable->load((int) $fieldId); + $fieldParams = json_decode($fieldTable->params); + $db = Factory::getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select('t.id AS value, t.options AS text'); $query->from('`#__tjfields_options` AS t'); - $query->order($db->escape('t.ordering ASC')); $query->where('t.field_id = ' . (int) $fieldId); - + $query->order($db->escape('t.ordering ASC')); $db->setQuery($query); // Get all countries. $fieldOptions = $db->loadObjectList(); + + if ($fieldParams->other) + { + $object = new stdClass(); + $object->value = 'tjlistothervalue'; + $object->text = 'Other'; + + array_push($fieldOptions, $object); + } echo new JsonResponse($fieldOptions); $app->close(); - } } diff --git a/administrator/helpers/tjfields.php b/administrator/helpers/tjfields.php index f9e91598..7be0290e 100755 --- a/administrator/helpers/tjfields.php +++ b/administrator/helpers/tjfields.php @@ -333,6 +333,7 @@ public function createXml($data, $fields, $category = null) foreach ($conditions as $condition) { + $conditionMatch = $condition->condition_match; $matchCase = ($conditionMatch == 1) ? "[AND]" : "[OR]" ; $index = 1; @@ -349,6 +350,11 @@ public function createXml($data, $fields, $category = null) $optionTable = Table::getInstance('Option', 'TjfieldsTable'); $optionTable->load(array('field_id' => $jsonDecoded->field_on_show, 'id' => $jsonDecoded->option)); $optionValue = $optionTable->value; + + if (json_decode($fieldTable->params)->other && empty($optionValue)) + { + $optionValue = $jsonDecoded->option; + } if ($condition->show == 1) { diff --git a/administrator/models/conditions.php b/administrator/models/conditions.php index d0a65822..0ff12693 100644 --- a/administrator/models/conditions.php +++ b/administrator/models/conditions.php @@ -171,6 +171,7 @@ public function getConditions($id) $query->select($db->qn(array('condition','condition_match','show'))); $query->from('#__tjfields_fields_conditions'); $query->where('field_to_show=' . $id); + $query->where($db->quoteName('state') . ' = ' . $db->quote('1')); $db->setQuery($query); $conditions = $db->loadObjectList(); diff --git a/administrator/models/fields/spcialfields.php b/administrator/models/fields/spcialfields.php index d1c5a549..d418bf32 100644 --- a/administrator/models/fields/spcialfields.php +++ b/administrator/models/fields/spcialfields.php @@ -53,7 +53,7 @@ protected function getOptions() $query->select($db->qn(array('tf.id', 'tf.label'))); $query->from('`#__tjfields_fields` AS tf'); - $query->where($db->quoteName('tf.type') . ' IN ("tjlist","radio","checkbox")'); + $query->where($db->quoteName('tf.type') . ' IN ("tjlist","radio","checkbox","single_select","multi_select","sql","itemcategory","ownership")'); $query->where($db->quoteName('tf.state') . ' = ' . $db->quote('1')); if ($client) diff --git a/administrator/models/fields/specialfieldsoptions.php b/administrator/models/fields/specialfieldsoptions.php index 26b81cad..5124596e 100644 --- a/administrator/models/fields/specialfieldsoptions.php +++ b/administrator/models/fields/specialfieldsoptions.php @@ -52,8 +52,6 @@ protected function getOptions() $query->select('t.id, t.options'); $query->from('`#__tjfields_options` AS t'); $query->order($db->escape('t.ordering ASC')); - - //~ echo $query->dump();die; $db->setQuery($query); diff --git a/administrator/views/conditions/tmpl/default_bs2.php b/administrator/views/conditions/tmpl/default_bs2.php index 3446ecb2..9d5a0a28 100644 --- a/administrator/views/conditions/tmpl/default_bs2.php +++ b/administrator/views/conditions/tmpl/default_bs2.php @@ -135,15 +135,20 @@ } ?> load((int) $conditionObj->field_on_show); + $fieldsName = $fieldsTable->label; + $optionTable = Table::getInstance('Option', 'TjfieldsTable'); $optionTable->load(array('field_id' => $conditionObj->field_on_show, 'id' => $conditionObj->option)); $optionValue = $optionTable->value; + + if (json_decode($fieldsTable->params)->other && empty($optionValue) && $conditionObj->option == 'tjlistothervalue') + { + $optionValue = 'Other'; + } ?>
  • load((int) $conditionObj->field_on_show); - $fieldsName = $fieldsTable->label; - echo $fieldsName . ' '; ?>
  • diff --git a/administrator/views/conditions/tmpl/default_bs5.php b/administrator/views/conditions/tmpl/default_bs5.php index 3446ecb2..9d5a0a28 100644 --- a/administrator/views/conditions/tmpl/default_bs5.php +++ b/administrator/views/conditions/tmpl/default_bs5.php @@ -135,15 +135,20 @@ } ?> load((int) $conditionObj->field_on_show); + $fieldsName = $fieldsTable->label; + $optionTable = Table::getInstance('Option', 'TjfieldsTable'); $optionTable->load(array('field_id' => $conditionObj->field_on_show, 'id' => $conditionObj->option)); $optionValue = $optionTable->value; + + if (json_decode($fieldsTable->params)->other && empty($optionValue) && $conditionObj->option == 'tjlistothervalue') + { + $optionValue = 'Other'; + } ?>
  • load((int) $conditionObj->field_on_show); - $fieldsName = $fieldsTable->label; - echo $fieldsName . ' '; ?>
  • From 30972494d453824f85c55657898910b198bce6f2 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Wed, 8 Feb 2023 10:49:43 +0530 Subject: [PATCH 13/13] Feature #192755 feat: UCM - Conditional Fields Integration --- admin_language/en-GB/en-GB.com_tjfields.ini | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/admin_language/en-GB/en-GB.com_tjfields.ini b/admin_language/en-GB/en-GB.com_tjfields.ini index 0f2b3c63..92dd7594 100755 --- a/admin_language/en-GB/en-GB.com_tjfields.ini +++ b/admin_language/en-GB/en-GB.com_tjfields.ini @@ -555,7 +555,6 @@ COM_TJFIELDS_FORM_DESC_ITEM_CATEGORY_FIELD_STATE="(1/0/2/-2) is whether the drop COM_TJFIELDS_CAPTURE_IMAGE="Capture Image" COM_TJFIELDS_LBL_ACCORDION="Accordion Tag" - COM_TJFIELDS_CONDITION_SELCET_FIELD="Select Field" COM_TJFIELDS_CONDITION_SELCET_FIELD_OPTIONS="Select Option" COM_TJFIELDS_TITLE_CONDITIONS="Conditions" @@ -565,9 +564,15 @@ COM_TJFIELDS_N_CONDITIONS_UNPUBLISHED="%d conditions successfully unpublished" COM_TJFIELDS_N_CONDITIONS_PUBLISHED="%d conditions successfully published" COM_TJFIELDS_CONDITIONAL_FIELDS="Conditional Fields" COM_TJFIELDS_FORM_LBL_CONDITION_SHOW="Show/Hide" +COM_TJFIELDS_FORM_DESC_CONDITION_SHOW="Show/Hide" COM_TJFIELDS_FORM_LBL_CONDITION_FIELD_TO_SHOW="Select the field to show/hide" +COM_TJFIELDS_FORM_DESC_CONDITION_FIELD_TO_SHOW="Select the field to show/hide" COM_TJFIELDS_FORM_LBL_CONDITION_CONDITION_MATCH="Select All/Any of the defined condition matches" +COM_TJFIELDS_FORM_DESC_CONDITION_CONDITION_MATCH="Select All/Any of the defined condition matches" COM_TJFIELDS_FORM_LBL_CONDITION_FIELD_ON_SHOW="Select the field on which you want to add condition" +COM_TJFIELDS_FORM_DESC_CONDITION_FIELD_ON_SHOW="Select the field on which you want to add condition" COM_TJFIELDS_FORM_LBL_CONDITION_OPERATOR="Is/Is Not" +COM_TJFIELDS_FORM_DESC_CONDITION_OPERATOR="Is/Is Not" COM_TJFIELDS_FORM_LBL_CONDITION_OPTION="Select the option" +COM_TJFIELDS_FORM_DESC_CONDITION_OPTION="Select the option" COM_TJFIELDS_FORM_LBL_CONDITION="Condition"