diff --git a/admin_language/en-GB/en-GB.com_tjfields.ini b/admin_language/en-GB/en-GB.com_tjfields.ini index a859cf27..92dd7594 100755 --- a/admin_language/en-GB/en-GB.com_tjfields.ini +++ b/admin_language/en-GB/en-GB.com_tjfields.ini @@ -554,3 +554,25 @@ 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_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" diff --git a/administrator/controllers/condition.php b/administrator/controllers/condition.php new file mode 100644 index 00000000..f7da2cae --- /dev/null +++ b/administrator/controllers/condition.php @@ -0,0 +1,129 @@ + + * @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\Factory; +use Joomla\CMS\Response\JsonResponse; +use Joomla\CMS\MVC\Controller\FormController; +use Joomla\CMS\Table\Table; + +/** + * 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'); + + 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->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/controllers/conditions.php b/administrator/controllers/conditions.php new file mode 100644 index 00000000..6502e398 --- /dev/null +++ b/administrator/controllers/conditions.php @@ -0,0 +1,155 @@ + + * @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\Factory; +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; + +/** + * 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 = ArrayHelper::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 + ArrayHelper::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'; + } + + // 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))); + } + catch (Exception $e) + { + $this->setMessage($e->getMessage(), 'error'); + } + } + + $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/helpers/tjfields.php b/administrator/helpers/tjfields.php index 28c88cd2..7be0290e 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) { @@ -319,6 +324,68 @@ public function createXml($data, $fields, $category = null) $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); + + 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 (json_decode($fieldTable->params)->other && empty($optionValue)) + { + $optionValue = $jsonDecoded->option; + } + + if ($condition->show == 1) + { + $operator = ($jsonDecoded->operator == 1) ? ":" : "!:"; + } + else + { + $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) { $field->addAttribute('required', 'true'); diff --git a/administrator/models/condition.php b/administrator/models/condition.php new file mode 100644 index 00000000..69e712b5 --- /dev/null +++ b/administrator/models/condition.php @@ -0,0 +1,207 @@ + + * @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\MVC\Model\AdminModel; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Factory; + +/** + * 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]; + + $dataOfClient = array(); + $dataOfClient['client'] = $client; + $dataOfClient['client_type'] = $client_type; + $TjfieldsHelper->generateXml($dataOfClient); + + // End xml + + return true; + } + + return false; + } +} diff --git a/administrator/models/conditions.php b/administrator/models/conditions.php new file mode 100644 index 00000000..0ff12693 --- /dev/null +++ b/administrator/models/conditions.php @@ -0,0 +1,203 @@ + + * @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\MVC\Model\ListModel; +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; + +/** + * 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; + } + + /** + * Get conditional fields. + * + * @return array of option for the particular field + */ + 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(); + + return $conditionalFields; + } + + /** + * Get conditions. + * + * @param int $id id. + * + * @return array of option for the particular field + */ + public function getConditions($id) + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $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(); + + return $conditions; + } + + /** + * Get conditional fields data. + * + * @param string $client client. + * + * @return array of option for the particular field + */ + 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/models/fields/conditionalfields.php b/administrator/models/fields/conditionalfields.php new file mode 100644 index 00000000..9da82f03 --- /dev/null +++ b/administrator/models/fields/conditionalfields.php @@ -0,0 +1,94 @@ + + * @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\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($db->qn(array('tf.id', 'tf.label'))); + $query->from('`#__tjfields_fields` AS tf'); + $query->where($db->quoteName('tf.state') . ' = ' . $db->quote('1')); + + if ($client) + { + $query->where($db->quoteName('tf.client') . ' = ' . $db->quote($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..d418bf32 --- /dev/null +++ b/administrator/models/fields/spcialfields.php @@ -0,0 +1,96 @@ + + * @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\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($db->qn(array('tf.id', 'tf.label'))); + $query->from('`#__tjfields_fields` AS tf'); + + $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) + { + $query->where($db->quoteName('tf.client') . ' = ' . $db->quote($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..5124596e --- /dev/null +++ b/administrator/models/fields/specialfieldsoptions.php @@ -0,0 +1,86 @@ + + * @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\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')); + + $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..074fe6e1 --- /dev/null +++ b/administrator/models/forms/condition.xml @@ -0,0 +1,54 @@ + +
+
+ + + + + + + + + + + + + + + + + + +
+
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..4b2ed525 100755 --- a/administrator/sql/install.mysql.utf8.sql +++ b/administrator/sql/install.mysql.utf8.sql @@ -63,3 +63,20 @@ 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, + `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 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' , + `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..00912534 100644 --- a/administrator/sql/updates/mysql/2.0.2.sql +++ b/administrator/sql/updates/mysql/2.0.2.sql @@ -1 +1,18 @@ -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, + `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 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' , + `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..3d85962f --- /dev/null +++ b/administrator/tables/condition.php @@ -0,0 +1,74 @@ + + * @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('Restricted access'); + +use Joomla\CMS\Table\Table; +use Joomla\CMS\Factory; + +/** + * Table class for selfassessment + * + * @package Emc + * + * @since __DEPLOY_VERSION__ + */ +class TjfieldsTableCondition extends Table +{ + /** + * Constructor + * + * @param \JDatabaseDriver &$db \JDatabaseDriver object. + */ + public function __construct(&$db) + { + parent::__construct('#__tjfields_fields_conditions', 'id', $db); + $this->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..e97d4434 --- /dev/null +++ b/administrator/views/condition/tmpl/edit.php @@ -0,0 +1,21 @@ + + * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +// 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/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..91cbbe6e --- /dev/null +++ b/administrator/views/condition/view.html.php @@ -0,0 +1,127 @@ + + * @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\MVC\View\HtmlView; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; + +/** + * 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') + { + ToolbarHelper::title($viewTitle, 'pencil-2'); + } + else + { + ToolbarHelper::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')))) + { + ToolbarHelper::apply('condition.apply', 'JTOOLBAR_APPLY'); + ToolbarHelper::save('condition.save', 'JTOOLBAR_SAVE'); + } + + if (empty($this->item->id)) + { + ToolbarHelper::cancel('condition.cancel', 'JTOOLBAR_CANCEL'); + } + else + { + ToolbarHelper::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..e97d4434 --- /dev/null +++ b/administrator/views/conditions/tmpl/default.php @@ -0,0 +1,21 @@ + + * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +// 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/conditions/tmpl/default_bs2.php b/administrator/views/conditions/tmpl/default_bs2.php new file mode 100644 index 00000000..9d5a0a28 --- /dev/null +++ b/administrator/views/conditions/tmpl/default_bs2.php @@ -0,0 +1,182 @@ + + * @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_to_show); + $fieldName = $fieldTable->label; + + echo $showHide . ' - ' . $fieldName; ?> +
+
+
    +
  • + condition) as $condition) { ?> + operator == 1) + { + $operator = "Is"; + } + else + { + $operator = "Is Not"; + } + ?> + 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'; + } + ?> +
  • + +
  • + +
+
+
+ + + +
+ + + +
+ + + + + + + +
+ +
diff --git a/administrator/views/conditions/tmpl/default_bs5.php b/administrator/views/conditions/tmpl/default_bs5.php new file mode 100644 index 00000000..9d5a0a28 --- /dev/null +++ b/administrator/views/conditions/tmpl/default_bs5.php @@ -0,0 +1,182 @@ + + * @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_to_show); + $fieldName = $fieldTable->label; + + echo $showHide . ' - ' . $fieldName; ?> +
+
+
    +
  • + condition) as $condition) { ?> + operator == 1) + { + $operator = "Is"; + } + else + { + $operator = "Is Not"; + } + ?> + 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'; + } + ?> +
  • + +
  • + +
+
+
+ + + +
+ + + +
+ + + + + + + +
+ +
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..73b5361c --- /dev/null +++ b/administrator/views/conditions/view.html.php @@ -0,0 +1,148 @@ + + * @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\MVC\View\HtmlView; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; + +/** + * 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') + { + ToolbarHelper::title(Text::_('COM_TJFIELDS_TITLE_CONDITIONS'), 'list'); + } + else + { + ToolbarHelper::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')) + { + ToolbarHelper::addNew('condition.add', 'JTOOLBAR_NEW'); + } + + if ($canDo->get('core.edit') && isset($this->items[0])) + { + ToolbarHelper::editList('condition.edit', 'JTOOLBAR_EDIT'); + } + } + + if ($canDo->get('core.edit.state')) + { + if (isset($this->items[0]->state)) + { + 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); + } + } + + // Show trash and delete for components that uses the state field + if (isset($this->items[0]->state)) + { + if ($canDo->get('core.delete')) + { + ToolbarHelper::deleteList('', 'conditions.delete', 'JTOOLBAR_DELETE'); + ToolbarHelper::divider(); + } + } + + + if ($canDo->get('core.admin')) + { + ToolbarHelper::preferences('com_tjfields'); + } + + if (JVERSION >= '3.0') + { + // Set sidebar action + JHtmlSidebar::setAction('index.php?option=com_tjfields&view=conditions&client=' . $client); + } + + $this->extra_sidebar = ''; + } +} 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');