/** * _getTableFromString * * @param string $tableName * @return JO_Db_Table_Abstract */ protected function _getTableFromString($tableName) { if ($this->_table instanceof JO_Db_Table_Abstract) { $tableDefinition = $this->_table->getDefinition(); if ($tableDefinition !== null && $tableDefinition->hasTableConfig($tableName)) { return new JO_Db_Table($tableName, $tableDefinition); } } // assume the tableName is the class name if (!class_exists($tableName)) { try { require_once 'JO/Loader.php'; JO_Loader::loadClass($tableName); } catch (JO_Exception $e) { require_once 'JO/Db/Table/Row/Exception.php'; throw new JO_Db_Table_Row_Exception($e->getMessage(), $e->getCode(), $e); } } $options = array(); if ($table = $this->_getTable()) { $options['db'] = $table->getAdapter(); } if (isset($tableDefinition) && $tableDefinition !== null) { $options[JO_Db_Table_Abstract::DEFINITION] = $tableDefinition; } return new $tableName($options); }
/** * __construct() - For concrete implementation of JO_Db_Table * * @param string|array $config string can reference a JO_Registry key for a db adapter * OR it can reference the name of a table * @param array|JO_Db_Table_Definition $definition */ public function __construct($config = array(), $definition = null) { if ($definition !== null && is_array($definition)) { $definition = new JO_Db_Table_Definition($definition); } if (is_string($config)) { if (JO_Registry::isRegistered($config)) { trigger_error(__CLASS__ . '::' . __METHOD__ . '(\'registryName\') is not valid usage of JO_Db_Table, ' . 'try extending JO_Db_Table_Abstract in your extending classes.', E_USER_NOTICE); $config = array(self::ADAPTER => $config); } else { // process this as table with or without a definition if ($definition instanceof JO_Db_Table_Definition && $definition->hasTableConfig($config)) { // this will have DEFINITION_CONFIG_NAME & DEFINITION $config = $definition->getTableConfig($config); } else { $config = array(self::NAME => $config); } } } parent::__construct($config); }
/** * Sets the default metadata cache for information returned by JO_Db_Adapter_Abstract::describeTable(). * * If $defaultMetadataCache is null, then no metadata cache is used by default. * * @param mixed $metadataCache Either a Cache object, or a string naming a Registry key * @return void */ public static function setDefaultMetadataCache($metadataCache = null) { self::$_defaultMetadataCache = self::_setupMetadataCache($metadataCache); }
/** * Adds a FROM table and optional columns to the query. * * The table name can be expressed * * @param array|string|JO_Db_Expr|JO_Db_Table_Abstract $name The table name or an associative array relating table name to correlation name. * @param array|string|JO_Db_Expr $cols The columns to select from this table. * @param string $schema The schema name to specify, if any. * @return JO_Db_Table_Select This JO_Db_Table_Select object. */ public function from($name, $cols = self::SQL_WILDCARD, $schema = null) { if ($name instanceof JO_Db_Table_Abstract) { $info = $name->info(); $name = $info[JO_Db_Table_Abstract::NAME]; if (isset($info[JO_Db_Table_Abstract::SCHEMA])) { $schema = $info[JO_Db_Table_Abstract::SCHEMA]; } } return $this->joinInner($name, null, $cols, $schema); }