/** * Renders the toolbar for the current view and task * * @param string $view The view of the component * @param string $task The exact task of the view * @param FOFInput $input An optional input object used to determine the defaults * * @return void */ public function renderToolbar($view = null, $task = null, $input = null) { if (!empty($input)) { $saveInput = $this->input; $this->input = $input; } // If tmpl=component the default behaviour is to not render the toolbar if ($this->input->getCmd('tmpl', '') == 'component') { $render_toolbar = false; } else { $render_toolbar = true; } // If there is a render_toolbar=0 in the URL, do not render a toolbar $render_toolbar = $this->input->getBool('render_toolbar', $render_toolbar); if (!$render_toolbar) { return; } // Get the view and task if (empty($view)) { $view = $this->input->getCmd('view', 'cpanel'); } if (empty($task)) { $task = $this->input->getCmd('task', 'default'); } $this->view = $view; $this->task = $task; $view = FOFInflector::pluralize($view); $component = $input->get('option', 'com_foobar', 'cmd'); $configProvider = new FOFConfigProvider(); $toolbar = $configProvider->get($component . '.views.' . '.toolbar'); // If we have a toolbar config specified if (!empty($toolbar)) { return $this->renderFromConfig($toolbar); } // Check for an onViewTask method $methodName = 'on' . ucfirst($view) . ucfirst($task); if (method_exists($this, $methodName)) { return $this->{$methodName}(); } // Check for an onView method $methodName = 'on' . ucfirst($view); if (method_exists($this, $methodName)) { return $this->{$methodName}(); } // Check for an onTask method $methodName = 'on' . ucfirst($task); if (method_exists($this, $methodName)) { return $this->{$methodName}(); } if (!empty($input)) { $this->input = $saveInput; } }
/** * Class Constructor. * * @param string $table Name of the database table to model. * @param string $key Name of the primary key field in the table. * @param JDatabaseDriver &$db Database driver * @param array $config The configuration parameters array */ public function __construct($table, $key, &$db, $config = array()) { $this->_tbl = $table; $this->_tbl_key = $key; $this->_db = $db; // Make sure the use FOF cache information is in the config if (!array_key_exists('use_table_cache', $config)) { $config['use_table_cache'] = FOFPlatform::getInstance()->isGlobalFOFCacheEnabled(); } $this->config = $config; // Load the configuration provider $this->configProvider = new FOFConfigProvider(); // Load the behavior dispatcher $this->tableDispatcher = new FOFTableDispatcherBehavior(); // Initialise the table properties. if ($fields = $this->getTableFields()) { // Do I have anything joined? $j_fields = $this->getQueryJoinFields(); if ($j_fields) { $fields = array_merge($fields, $j_fields); } $this->setKnownFields(array_keys($fields), true); $this->reset(); } else { $this->_tableExists = false; } // Get the input if (array_key_exists('input', $config)) { if ($config['input'] instanceof FOFInput) { $this->input = $config['input']; } else { $this->input = new FOFInput($config['input']); } } else { $this->input = new FOFInput(); } // Set the $name/$_name variable $component = $this->input->getCmd('option', 'com_foobar'); if (array_key_exists('option', $config)) { $component = $config['option']; } $this->input->set('option', $component); // Apply table behaviors $type = explode("_", $this->_tbl); $type = $type[count($type) - 1]; $this->_configProviderKey = $component . '.tables.' . FOFInflector::singularize($type); $configKey = $this->_configProviderKey . '.behaviors'; if (isset($config['behaviors'])) { $behaviors = (array) $config['behaviors']; } elseif ($behaviors = $this->configProvider->get($configKey, null)) { $behaviors = explode(',', $behaviors); } else { $behaviors = $this->default_behaviors; } if (is_array($behaviors) && count($behaviors)) { foreach ($behaviors as $behavior) { $this->addBehavior($behavior); } } // If we are tracking assets, make sure an access field exists and initially set the default. $asset_id_field = $this->getColumnAlias('asset_id'); $access_field = $this->getColumnAlias('access'); if (in_array($asset_id_field, $this->getKnownFields())) { JLoader::import('joomla.access.rules'); $this->_trackAssets = true; } // If the access property exists, set the default. if (in_array($access_field, $this->getKnownFields())) { $this->{$access_field} = (int) FOFPlatform::getInstance()->getConfig()->get('access'); } $this->config = $config; }
/** * Public constructor * * @param array $config The configuration variables */ public function __construct($config = array()) { // Cache the config $this->config = $config; // Get the input for this MVC triad if (array_key_exists('input', $config)) { $this->input = $config['input']; } else { $this->input = new FOFInput(); } // Get the default values for the component name $this->component = $this->input->getCmd('option', 'com_foobar'); // Load the component's fof.xml configuration file $configProvider = new FOFConfigProvider(); $this->defaultView = $configProvider->get($this->component . '.dispatcher.default_view', $this->defaultView); // Get the default values for the view name $this->view = $this->input->getCmd('view', null); if (empty($this->view)) { // Do we have a task formatted as controller.task? $task = $this->input->getCmd('task', ''); if (!empty($task) && strstr($task, '.') !== false) { list($this->view, $task) = explode('.', $task, 2); $this->input->set('task', $task); } } if (empty($this->view)) { $this->view = $this->defaultView; } $this->layout = $this->input->getCmd('layout', null); // Overrides from the config if (array_key_exists('option', $config)) { $this->component = $config['option']; } if (array_key_exists('view', $config)) { $this->view = empty($config['view']) ? $this->view : $config['view']; } if (array_key_exists('layout', $config)) { $this->layout = $config['layout']; } $this->input->set('option', $this->component); $this->input->set('view', $this->view); $this->input->set('layout', $this->layout); }
/** * Public class constructor * * @param array $config The configuration array */ public function __construct($config = array()) { // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } // Get the input if (array_key_exists('input', $config)) { if ($config['input'] instanceof FOFInput) { $this->input = $config['input']; } else { $this->input = new FOFInput($config['input']); } } else { $this->input = new FOFInput(); } // Load the configuration provider $this->configProvider = new FOFConfigProvider(); // Load the behavior dispatcher $this->modelDispatcher = new FOFModelDispatcherBehavior(); // Set the $name/$_name variable $component = $this->input->getCmd('option', 'com_foobar'); if (array_key_exists('option', $config)) { $component = $config['option']; } // Set the $name variable $this->input->set('option', $component); $component = $this->input->getCmd('option', 'com_foobar'); if (array_key_exists('option', $config)) { $component = $config['option']; } $this->input->set('option', $component); $bareComponent = str_replace('com_', '', strtolower($component)); // Get the view name $className = get_class($this); if ($className == 'FOFModel') { if (array_key_exists('view', $config)) { $view = $config['view']; } if (empty($view)) { $view = $this->input->getCmd('view', 'cpanel'); } } else { $eliminatePart = ucfirst($bareComponent) . 'Model'; $view = strtolower(str_replace($eliminatePart, '', $className)); } if (array_key_exists('name', $config)) { $name = $config['name']; } else { $name = $view; } $this->name = $name; $this->option = $component; // Set the model state if (array_key_exists('state', $config)) { $this->state = $config['state']; } else { $this->state = new FOFUtilsObject(); } // Set the model dbo if (array_key_exists('dbo', $config)) { $this->_db = $config['dbo']; } else { $this->_db = FOFPlatform::getInstance()->getDbo(); } // Set the default view search path if (array_key_exists('table_path', $config)) { $this->addTablePath($config['table_path']); } else { $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($this->option); $path = $componentPaths['admin'] . '/tables'; $altPath = $this->configProvider->get($this->option . '.views.' . FOFInflector::singularize($this->name) . '.config.table_path', null); if ($altPath) { $path = $componentPaths['main'] . '/' . $altPath; } $this->addTablePath($path); } // Assign the correct table if (array_key_exists('table', $config)) { $this->table = $config['table']; } else { $table = $this->configProvider->get($this->option . '.views.' . FOFInflector::singularize($this->name) . '.config.table', FOFInflector::singularize($view)); $this->table = $table; } // Set the internal state marker - used to ignore setting state from the request if (!empty($config['ignore_request']) || !is_null($this->configProvider->get($this->option . '.views.' . FOFInflector::singularize($this->name) . '.config.ignore_request', null))) { $this->__state_set = true; } // Get and store the pagination request variables $defaultSaveState = array_key_exists('savestate', $config) ? $config['savestate'] : -999; $this->populateSavestate($defaultSaveState); if (FOFPlatform::getInstance()->isCli()) { $limit = 20; $limitstart = 0; } else { $app = JFactory::getApplication(); if (method_exists($app, 'getCfg')) { $default_limit = $app->getCfg('list_limit'); } else { $default_limit = 20; } $limit = $this->getUserStateFromRequest($component . '.' . $view . '.limit', 'limit', $default_limit, 'int', $this->_savestate); $limitstart = $this->getUserStateFromRequest($component . '.' . $view . '.limitstart', 'limitstart', 0, 'int', $this->_savestate); } $this->setState('limit', $limit); $this->setState('limitstart', $limitstart); // Get the ID or list of IDs from the request or the configuration if (array_key_exists('cid', $config)) { $cid = $config['cid']; } elseif ($cid = $this->configProvider->get($this->option . '.views.' . FOFInflector::singularize($this->name) . '.config.cid', null)) { $cid = explode(',', $cid); } else { $cid = $this->input->get('cid', array(), 'array'); } if (array_key_exists('id', $config)) { $id = $config['id']; } elseif ($id = $this->configProvider->get($this->option . '.views.' . FOFInflector::singularize($this->name) . '.config.id', null)) { $id = explode(',', $id); $id = array_shift($id); } else { $id = $this->input->getInt('id', 0); } if (is_array($cid) && !empty($cid)) { $this->setIds($cid); } else { $this->setId($id); } // Populate the event names from the $config array $configKey = $this->option . '.views.' . FOFInflector::singularize($view) . '.config.'; // Assign after delete event handler if (isset($config['event_after_delete'])) { $this->event_after_delete = $config['event_after_delete']; } else { $this->event_after_delete = $this->configProvider->get($configKey . 'event_after_delete', $this->event_after_delete); } // Assign after save event handler if (isset($config['event_after_save'])) { $this->event_after_save = $config['event_after_save']; } else { $this->event_after_save = $this->configProvider->get($configKey . 'event_after_save', $this->event_after_save); } // Assign before delete event handler if (isset($config['event_before_delete'])) { $this->event_before_delete = $config['event_before_delete']; } else { $this->event_before_delete = $this->configProvider->get($configKey . 'event_before_delete', $this->event_before_delete); } // Assign before save event handler if (isset($config['event_before_save'])) { $this->event_before_save = $config['event_before_save']; } else { $this->event_before_save = $this->configProvider->get($configKey . 'event_before_save', $this->event_before_save); } // Assign state change event handler if (isset($config['event_change_state'])) { $this->event_change_state = $config['event_change_state']; } else { $this->event_change_state = $this->configProvider->get($configKey . 'event_change_state', $this->event_change_state); } // Assign cache clean event handler if (isset($config['event_clean_cache'])) { $this->event_clean_cache = $config['event_clean_cache']; } else { $this->event_clean_cache = $this->configProvider->get($configKey . 'event_clean_cache', $this->event_clean_cache); } // Apply model behaviors if (isset($config['behaviors'])) { $behaviors = (array) $config['behaviors']; } elseif ($behaviors = $this->configProvider->get($configKey . 'behaviors', null)) { $behaviors = explode(',', $behaviors); } else { $behaviors = $this->default_behaviors; } if (is_array($behaviors) && count($behaviors)) { foreach ($behaviors as $behavior) { $this->addBehavior($behavior); } } }
/** * ACL check before changing the publish status of a record; override to customise * * @return boolean True to allow the method to run */ protected function onBeforeUnpublish() { $privilege = $this->configProvider->get($this->component . '.views.' . FOFInflector::singularize($this->view) . '.acl.unpublish', 'core.edit.state'); return $this->checkACL($privilege); }
/** * Returns a static object instance of a particular table type * * @param string $type The table name * @param string $prefix The prefix of the table class * @param array $config Optional configuration variables * * @return FOFTable */ public static function &getAnInstance($type = null, $prefix = 'JTable', $config = array()) { static $instances = array(); // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } // Guess the component name if (!array_key_exists('input', $config)) { $config['input'] = new FOFInput(); } if ($config['input'] instanceof FOFInput) { $tmpInput = $config['input']; } else { $tmpInput = new FOFInput($config['input']); } $option = $tmpInput->getCmd('option', ''); $tmpInput->set('option', $option); $config['input'] = $tmpInput; if (!in_array($prefix, array('Table', 'JTable'))) { preg_match('/(.*)Table$/', $prefix, $m); $option = 'com_' . strtolower($m[1]); } if (array_key_exists('option', $config)) { $option = $config['option']; } $config['option'] = $option; if (!array_key_exists('view', $config)) { $config['view'] = $config['input']->getCmd('view', 'cpanel'); } if (is_null($type)) { if ($prefix == 'JTable') { $prefix = 'Table'; } $type = $config['view']; } $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type); $tableClass = $prefix . ucfirst($type); $configProvider = new FOFConfigProvider(); $configProviderKey = $option . '.views.' . FOFInflector::singularize($type) . '.config.'; if (!array_key_exists($tableClass, $instances)) { if (!class_exists($tableClass)) { list($isCLI, $isAdmin) = FOFDispatcher::isCliAdmin(); if (!$isAdmin) { $basePath = JPATH_SITE; } else { $basePath = JPATH_ADMINISTRATOR; } $searchPaths = array($basePath . '/components/' . $config['option'] . '/tables', JPATH_ADMINISTRATOR . '/components/' . $config['option'] . '/tables'); if (array_key_exists('tablepath', $config)) { array_unshift($searchPaths, $config['tablepath']); } $altPath = $configProvider->get($configProviderKey . 'table_path', null); if ($altPath) { array_unshift($searchPaths, JPATH_ADMINISTRATOR . '/components/' . $option . '/' . $altPath); } JLoader::import('joomla.filesystem.path'); $path = JPath::find($searchPaths, strtolower($type) . '.php'); if ($path) { require_once $path; } } if (!class_exists($tableClass)) { $tableClass = 'FOFTable'; } $tbl_common = str_replace('com_', '', $config['option']) . '_'; if (!array_key_exists('tbl', $config)) { $config['tbl'] = strtolower('#__' . $tbl_common . strtolower(FOFInflector::pluralize($type))); } $altTbl = $configProvider->get($configProviderKey . 'tbl', null); if ($altTbl) { $config['tbl'] = $altTbl; } if (!array_key_exists('tbl_key', $config)) { $keyName = FOFInflector::singularize($type); $config['tbl_key'] = strtolower($tbl_common . $keyName . '_id'); } $altTblKey = $configProvider->get($configProviderKey . 'tbl_key', null); if ($altTblKey) { $config['tbl_key'] = $altTblKey; } if (!array_key_exists('db', $config)) { $config['db'] = JFactory::getDBO(); } $instance = new $tableClass($config['tbl'], $config['tbl_key'], $config['db']); $instance->setInput($tmpInput); if (array_key_exists('trigger_events', $config)) { $instance->setTriggerEvents($config['trigger_events']); } $instances[$tableClass] = $instance; } return $instances[$tableClass]; }