/**
  * 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.' . F0FInflector::singularize($this->view) . '.acl.unpublish', 'core.edit.state');
     return $this->checkACL($privilege);
 }
Example #2
0
File: model.php Project: 01J/topm
 /**
  * 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 F0FInput) {
             $this->input = $config['input'];
         } else {
             $this->input = new F0FInput($config['input']);
         }
     } else {
         $this->input = new F0FInput();
     }
     // Load the configuration provider
     $this->configProvider = new F0FConfigProvider();
     // Load the behavior dispatcher
     $this->modelDispatcher = new F0FModelDispatcherBehavior();
     // 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 == 'F0FModel') {
         if (array_key_exists('view', $config)) {
             $view = $config['view'];
         }
         if (empty($view)) {
             $view = $this->input->getCmd('view', 'cpanel');
         }
     } else {
         if (array_key_exists('view', $config)) {
             $view = $config['view'];
         }
         if (empty($view)) {
             $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 F0FUtilsObject();
     }
     // Set the model dbo
     if (array_key_exists('dbo', $config)) {
         $this->_db = $config['dbo'];
     } else {
         $this->_db = F0FPlatform::getInstance()->getDbo();
     }
     // Set the default view search path
     if (array_key_exists('table_path', $config)) {
         $this->addTablePath($config['table_path']);
     } else {
         $componentPaths = F0FPlatform::getInstance()->getComponentBaseDirs($this->option);
         $path = $componentPaths['admin'] . '/tables';
         $altPath = $this->configProvider->get($this->option . '.views.' . F0FInflector::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.' . F0FInflector::singularize($this->name) . '.config.table', F0FInflector::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.' . F0FInflector::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 (F0FPlatform::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.' . F0FInflector::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.' . F0FInflector::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.' . F0FInflector::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);
         }
     }
 }
Example #3
0
 /**
  * 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 F0FInput();
     }
     // 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 F0FConfigProvider();
     $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);
 }
Example #4
0
 /**
  * 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   F0FInput  $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 = F0FInflector::pluralize($view);
     $component = $this->input->get('option', 'com_foobar', 'cmd');
     $configProvider = new F0FConfigProvider();
     $toolbar = $configProvider->get($component . '.views.' . $view . '.toolbar.' . $task);
     // 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;
     }
 }
Example #5
0
 /**
  * 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   F0FDatabaseDriver  &$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 F0F cache information is in the config
     if (!array_key_exists('use_table_cache', $config)) {
         $config['use_table_cache'] = F0FPlatform::getInstance()->isGlobalF0FCacheEnabled();
     }
     $this->config = $config;
     // Load the configuration provider
     $this->configProvider = new F0FConfigProvider();
     // Load the behavior dispatcher
     $this->tableDispatcher = new F0FTableDispatcherBehavior();
     // 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 F0FInput) {
             $this->input = $config['input'];
         } else {
             $this->input = new F0FInput($config['input']);
         }
     } else {
         $this->input = new F0FInput();
     }
     // 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.' . F0FInflector::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) F0FPlatform::getInstance()->getConfig()->get('access');
     }
     $this->config = $config;
 }