/** * Loads in elements published validation objects * * @return array validation objects */ public function findAll() { if (isset($this->validations)) { return $this->validations; } $element = $this->elementModel->getElement(); $params = $this->elementModel->getParams(); $validations = (array) $params->get('validations', 'array'); $usedPlugins = (array) FArrayHelper::getValue($validations, 'plugin', array()); $published = FArrayHelper::getValue($validations, 'plugin_published', array()); $showIcon = FArrayHelper::getValue($validations, 'show_icon', array()); $validateIn = FArrayHelper::getValue($validations, 'validate_in', array()); $validationOn = FArrayHelper::getValue($validations, 'validation_on', array()); $pluginManager = FabrikWorker::getPluginManager(); $pluginManager->getPlugInGroup('validationrule'); $c = 0; $this->validations = array(); $dispatcher = JDispatcher::getInstance(); $ok = JPluginHelper::importPlugin('fabrik_validationrule'); $i = 0; foreach ($usedPlugins as $usedPlugin) { if ($usedPlugin !== '') { $isPublished = FArrayHelper::getValue($published, $i, true); if ($isPublished) { $class = 'PlgFabrik_Validationrule' . JString::ucfirst($usedPlugin); $conf = array(); $conf['name'] = JString::strtolower($usedPlugin); $conf['type'] = JString::strtolower('fabrik_Validationrule'); $plugIn = new $class($dispatcher, $conf); $oPlugin = JPluginHelper::getPlugin('fabrik_validationrule', $usedPlugin); $plugIn->elementModel = $this->elementModel; $this->validations[] = $plugIn; // Set params relative to plugin render order $plugIn->setParams($params, $i); $plugIn->getParams()->set('show_icon', FArrayHelper::getValue($showIcon, $i, true)); $plugIn->getParams()->set('validate_in', FArrayHelper::getValue($validateIn, $i, 'both')); $plugIn->getParams()->set('validation_on', FArrayHelper::getValue($validationOn, $i, 'both')); $c++; } } $i++; } return $this->validations; }
/** * When saving a table that links to a database for the first time we * need to create all the elements based on the database table fields and their * column type * * @param int $groupId group id * @param string $tableName table name - if not set then use jform's db_table_name (@since 3.1) * * @return void */ private function createLinkedElements($groupId, $tableName = '') { $db = FabrikWorker::getDbo(true); $app = JFactory::getApplication(); $input = $app->input; $user = JFactory::getUser(); $config = JFactory::getConfig(); $createdate = JFactory::getDate(); $createdate = $createdate->toSql(); if ($tableName === '') { $jform = $input->get('jform', array(), 'array'); $tableName = JArrayHelper::getValue($jform, 'db_table_name'); } $formModel = $this->getFormModel(); $pluginManager = FabrikWorker::getPluginManager(); $ordering = 0; $fabrikDb = $this->getFEModel()->getDb(); $groupTable = FabTable::getInstance('Group', 'FabrikTable'); $groupTable->load($groupId); // Here we're importing directly from the database schema $query = $db->getQuery(true); $query->select('id')->from('#__{package}_lists')->where('db_table_name = ' . $db->quote($tableName)); $db->setQuery($query); $id = $db->loadResult(); $dispatcher = JDispatcher::getInstance(); $elementModel = new PlgFabrik_Element($dispatcher); if ($id) { // A fabrik table already exists - so we can copy the formatting of its elements $groupListModel = JModelLegacy::getInstance('list', 'FabrikFEModel'); $groupListModel->setId($id); $groupListModel->getTable(); $groups = $groupListModel->getFormGroupElementData(); $newElements = array(); $ecount = 0; foreach ($groups as $groupModel) { /** * If we are saving a new table and the previously found tables group is a join * then don't add its elements to the table as they don't exist in the database table * we are linking to * $$$ hugh - why the test for task and new table? When creating elements for a copy of a table, * surely we NEVER want to include elements which were joined to the original, * regardless of whether this is a new List? Bearing in mind that this routine gets called from * the makeNewJoin() method, when adding a join to an existing list, to build the "Foo - [bar]" join * group, as well as from save() when creating a new List. * * if ($groupModel->isJoin() && $input->get('task') == 'save' && $input->getInt('id') == 0) */ if ($groupModel->isJoin()) { continue; } $elementModels =& $groupModel->getMyElements(); foreach ($elementModels as $elementModel) { $ecount++; $element = $elementModel->getElement(); $copy = $elementModel->copyRow($element->id, $element->label, $groupId); $newElements[$element->id] = $copy->id; } } foreach ($newElements as $origId => $newId) { $plugin = $pluginManager->getElementPlugin($newId); $plugin->finalCopyCheck($newElements); } // Hmm table with no elements - lets create them from the structure anyway if ($ecount == 0) { $this->makeElementsFromFields($groupId, $tableName); } } else { // No previously found fabrik list $this->makeElementsFromFields($groupId, $tableName); } }