/** * @testdox Ensure addModelPath() adds a model path to the internal array * * @covers JControllerLegacy::addModelPath */ public function testAddModelPath() { $path = JPath::clean(JPATH_ROOT . '/addmodelpath'); JControllerLegacy::addModelPath($path); // The default path is the class file folder/forms $valid = JPATH_PLATFORM . '/joomla/form/fields'; $this->assertTrue(in_array($path, JModelLegacy::addIncludePath()), 'Line:' . __LINE__ . ' The path should be added to the JModel paths.'); }
/** * An ajax connector for QuickAdd JS. */ public function quickAddAjax() { // Init Variables $input = JFactory::getApplication()->input; $data = $input->post->get($input->get('formctrl'), array(), 'array'); $result = new JRegistry(); $result->set('Result', false); $model_name = $input->get('model_name'); $component = $input->get('component'); $extension = $input->get('extension'); // Include Needed Classes JControllerLegacy::addModelPath(JPATH_BASE . "/components/com_{$component}/models"); JForm::addFormPath(JPATH_BASE . "/components/com_{$component}/models/forms"); JForm::addFieldPath(JPATH_BASE . "/components/com_{$component}/models/fields"); JTable::addIncludePath(JPATH_BASE . "/components/com_{$component}/tables"); AKHelper::_('lang.loadLanguage', $extension, null); // Get Model $model = $this->getModel(ucfirst($model_name), ucfirst($component) . 'Model', array('ignore_request' => true)); // For WindWalker Component only if (is_callable(array($model, 'getFieldsName'))) { $fields_name = $model->getFieldsName(); $data = AKHelper::_('array.pivotToTwoDimension', $data, $fields_name); } // Get Form $form = $model->getForm($data, false); if (!$form) { $result->set('errorMsg', $model->getError()); jexit($result); } // Test whether the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { // Get the validation messages. $errors = $model->getErrors(); $errorMsg = is_string($errors[0]) ? $errors[0] : $errors[0]->getMessage(); $result->set('errorMsg', $errorMsg); jexit($result); } // Do Save if (!$model->save($validData)) { // Return Error Message. $result->set('errorMsg', JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError())); jexit($result); } // Set ID $data['id'] = $model->getstate($model_name . '.id'); // Set Result $result->set('Result', true); $result->set('data', $data); jexit($result); }
/** * * @param type $params */ public static function saveSettings($params) { $oPlugin = JchPlatformPlugin::getPlugin(); $oPlugin->params = $params->toArray(); $oData = new JRegistry($oPlugin); $aData = $oData->toArray(); $oController = new JControllerLegacy(); $oController->addModelPath(JPATH_ADMINISTRATOR . '/components/com_plugins/models', 'PluginsModel'); $oPluginModel = $oController->getModel('Plugin', 'PluginsModel'); if ($oPluginModel->save($aData) === FALSE) { JchOptimizeLogger::log(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $oPluginModel->getError()), $params); } }
/** * * @return type */ protected function orderPlugins() { $aOrder = array('jscsscontrol', 'eorisis_jquery', 'jqueryeasy', 'jch_optimize', 'plugin_googlemap3', 'cdnforjoomla', 'bigshotgoogleanalytics', 'GoogleAnalytics', 'jat3', 'cache', 'jSGCache', 'jotcache', 'vmcache_last'); $aPlugins = $this->getPlugins(); $aLowerPlugins = array_values(array_filter($aOrder, function ($aVal) use($aPlugins) { return array_key_exists($aVal, $aPlugins); })); $iNoPlugins = count($aPlugins); $iNoLowerPlugins = count($aLowerPlugins); $iBaseOrder = $iNoPlugins - $iNoLowerPlugins; $cid = array(); $order = array(); foreach ($aPlugins as $key => $value) { if (in_array($key, $aLowerPlugins)) { $value['ordering'] = $iBaseOrder + 1 + array_search($key, $aLowerPlugins); } elseif ($value['ordering'] >= $iBaseOrder) { $value['ordering'] = $iBaseOrder - 1; } $cid[] = $value['extension_id']; $order[] = $value['ordering']; } JArrayHelper::toInteger($cid); JArrayHelper::toInteger($order); $aOrder = array(); $aOrder['cid'] = $cid; $aOrder['order'] = $order; $oController = new JControllerLegacy(); $oController->addModelPath(JPATH_ADMINISTRATOR . '/components/com_plugins/models', 'PluginsModel'); $oPluginModel = $oController->getModel('Plugin', 'PluginsModel'); if ($oPluginModel->saveorder($aOrder['cid'], $aOrder['order']) === FALSE) { $oController->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_REORDER_FAILED', $oPluginModel->getError()), 'error'); } else { $oController->setMessage(JText::_('JLIB_APPLICATION_SUCCESS_ORDERING_SAVED')); } $this->display($oController); }