Source for file legacy.php
Documentation is available at legacy.php
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Base class for a Joomla Model
* Acts as a Factory class for application specific objects and
* provides many supporting API functions.
* Indicates if the internal state has been set
* The URL option for the component.
* The event to trigger when cleaning cache.
* Add a directory where JModelLegacy should search for models. You may
* either pass a string or an array of directories.
* @param mixed $path A path or array[sting] of paths to search.
* @param string $prefix A prefix for models.
* @return array An array with directory elements. If prefix is equal to '', all directories are returned.
if (!isset
($paths[$prefix]))
$paths[$prefix] =
array();
* Adds to the stack of model table paths in LIFO order.
* @param mixed $path The directory as a string or directories as an array to add.
* Create the filename for a resource
* @param string $type The resource type to create the filename for.
* @param array $parts An associative array of filename information.
* @return string The filename
* Returns a Model object, always creating it
* @param string $type The model type to instantiate
* @param string $prefix Prefix for the model class name. Optional.
* @param array $config Configuration array for model. Optional.
* @return mixed A model object or false on failure
public static function getInstance($type, $prefix =
'', $config =
array())
$modelClass =
$prefix .
ucfirst($type);
$path =
JPath::find(self::addIncludePath(null, $prefix), self::_createFileName('model', array('name' =>
$type)));
$path =
JPath::find(self::addIncludePath(null, ''), self::_createFileName('model', array('name' =>
$type)));
return new $modelClass($config);
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
// Guess the option from the class name (Option)Model(View).
throw
new Exception(JText::_('JLIB_APPLICATION_ERROR_MODEL_GET_NAME'), 500);
$this->name =
$config['name'];
$this->state =
$config['state'];
$this->_db =
$config['dbo'];
// Set the default view search path
elseif (defined('JPATH_COMPONENT_ADMINISTRATOR'))
$this->addTablePath(JPATH_COMPONENT_ADMINISTRATOR .
'/tables');
$this->addTablePath(JPATH_COMPONENT_ADMINISTRATOR .
'/table');
// Set the internal state marker - used to ignore setting state from the request
if (!empty($config['ignore_request']))
// Set the clean cache event
if (isset
($config['event_clean_cache']))
* Gets an array of objects from the results of database query.
* @param string $query The query.
* @param integer $limitstart Offset.
* @param integer $limit The number of records.
* @return array An array of results.
* @throws RuntimeException
protected function _getList($query, $limitstart =
0, $limit =
0)
$this->_db->setQuery($query, $limitstart, $limit);
$result =
$this->_db->loadObjectList();
* Returns a record count for the query.
* @param JDatabaseQuery|string $query The query.
* @return integer Number of rows for query.
// Use fast COUNT(*) on JDatabaseQuery objects if there no GROUP BY or HAVING clause:
&&
$query->type ==
'select'
&&
$query->group ===
null
&&
$query->having ===
null)
$query->clear('select')->clear('order')->select('COUNT(*)');
$this->_db->setQuery($query);
return (int)
$this->_db->loadResult();
// Otherwise fall back to inefficient way of counting all results.
$this->_db->setQuery($query);
return (int)
$this->_db->getNumRows();
* Method to load and return a model object.
* @param string $name The name of the view
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration settings to pass to JTable::getInstance
* @return mixed Model object or boolean false if failed
* @see JTable::getInstance()
protected function _createTable($name, $prefix =
'Table', $config =
array())
// Make sure we are returning a DBO object
$config['dbo'] =
$this->getDbo();
* Method to get the database driver object
* @return JDatabaseDriver
* Method to get the model name
* The model name. By default parsed using the classname or it can be set
* by passing a $config['name'] in the class constructor
* @return string The name of the model
throw
new Exception(JText::_('JLIB_APPLICATION_ERROR_MODEL_GET_NAME'), 500);
* Method to get model state variables
* @param string $property Optional parameter name
* @param mixed $default Optional default value
* @return object The property where specified, the state object where omitted
public function getState($property =
null, $default =
null)
// Protected method to auto-populate the model state.
// Set the model state set flag to true.
return $property ===
null ?
$this->state :
$this->state->get($property, $default);
* Method to get a table object, load it if necessary.
* @param string $name The table name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $options Configuration array for model. Optional.
* @return JTable A JTable object
public function getTable($name =
'', $prefix =
'Table', $options =
array())
throw
new Exception(JText::sprintf('JLIB_APPLICATION_ERROR_TABLE_NAME_NOT_SUPPORTED', $name), 0);
* Method to load a row for editing from the version history table.
* @param integer $version_id Key to the version history table.
* @param JTable &$table Content table object being loaded.
* @return boolean False on failure or error, true otherwise.
public function loadHistory($version_id, JTable &$table)
// Only attempt to check the row in if it exists.
// Get an instance of the row to checkout.
if (!$historyTable->load($version_id))
$this->setError($historyTable->getError());
if ($historyTable->ucm_type_id !=
$typeId)
$this->setError(JText::_('JLIB_APPLICATION_ERROR_HISTORY_ID_MISMATCH'));
$key =
$table->getKeyName();
if (isset
($rowArray[$key]))
$table->checkIn($rowArray[$key]);
$this->setState('save_date', $historyTable->save_date);
$this->setState('version_note', $historyTable->version_note);
return $table->bind($rowArray);
* Method to auto-populate the model state.
* This method should only be called once per instantiation and is designed
* to be called on the first call to the getState() method unless the model
* configuration flag to ignore the request is set.
* @note Calling getState in this method will result in recursion.
* Method to set the database driver object
* @param JDatabaseDriver $db A JDatabaseDriver based object
* Method to set model state variables
* @param string $property The name of the property.
* @param mixed $value The value of the property to set or null.
* @return mixed The previous value of the property or null if not set.
public function setState($property, $value =
null)
return $this->state->set($property, $value);
* @param string $group The cache group
* @param integer $client_id The ID of the client
protected function cleanCache($group =
null, $client_id =
0)
// Trigger the onContentCleanCache event.
Documentation generated on Tue, 19 Nov 2013 15:06:49 +0100 by phpDocumentor 1.4.3