Exemplo n.º 1
0
 /**
  * __construct() - For concrete implementation of Table
  *
  * @param string|array $config string can reference a \libDb\Registry key for a db adapter
  *                             OR it can reference the name of a table
  * @param array|Definition $definition
  */
 public function __construct($config = array(), $definition = null)
 {
     if ($definition !== null && is_array($definition)) {
         $definition = new Definition($definition);
     }
     if (is_string($config)) {
         if (\libDb\Registry::isRegistered($config)) {
             trigger_error(__CLASS__ . '::' . __METHOD__ . '(\'registryName\') is not valid usage of \\libDb\\Table, ' . 'try extending \\libDb\\AbstractTable 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 Definition && $definition->hasTableConfig($config)) {
                 // this will have DEFINITION_CONFIG_NAME & DEFINITION
                 $config = $definition->getTableConfig($config);
             } else {
                 $config = array(self::NAME => $config);
             }
         }
     }
     parent::__construct($config);
 }
Exemplo n.º 2
0
 protected function _loadAndReturnRow($position)
 {
     if (!isset($this->_data[$position])) {
         throw new Exception("Data for provided position does not exist");
     }
     // do we already have a row object for this position?
     if (empty($this->_rows[$position])) {
         $this->_rows[$position] = new $this->_rowClass(array('table' => $this->_table, 'data' => $this->_data[$position], 'stored' => $this->_stored, 'readOnly' => $this->_readOnly));
         if ($this->_table instanceof \libDb\Table\AbstractTable) {
             $info = $this->_table->info();
             if ($this->_rows[$position] instanceof \libDb\Table\Row\RowAbstract) {
                 if ($info['cols'] == array_keys($this->_data[$position])) {
                     $this->_rows[$position]->setTable($this->getTable());
                 }
             }
         } else {
             $this->_rows[$position]->setTable(null);
         }
     }
     // return the row object
     return $this->_rows[$position];
 }
Exemplo n.º 3
0
 /**
 * Adds a FROM table and optional columns to the query.
 *
 * The table name can be expressed
 *
 * @param  array|string|\libDb\Expr|AbstractTable $name The table name or an
                                                                  associative array relating
                                                                  table name to correlation
                                                                  name.
 * @param  array|string|\libDb\Expr $cols The columns to select from this table.
 * @param  string $schema The schema name to specify, if any.
 * @return Select This  object.
 */
 public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
 {
     if ($name instanceof AbstractTable) {
         $info = $name->info();
         $name = $info[AbstractTable::NAME];
         if (isset($info[AbstractTable::SCHEMA])) {
             $schema = $info[AbstractTable::SCHEMA];
         }
     }
     return $this->joinInner($name, null, $cols, $schema);
 }
Exemplo n.º 4
0
 public static function getTableFromString($tableName, \libDb\Table\AbstractTable $referenceTable = null)
 {
     if ($referenceTable instanceof \libDb\Table\AbstractTable) {
         $tableDefinition = $referenceTable->getDefinition();
         if ($tableDefinition !== null && $tableDefinition->hasTableConfig($tableName)) {
             return new \libDb\Table($tableName, $tableDefinition);
         }
     }
     $options = array();
     if ($referenceTable instanceof \libDb\Table\AbstractTable) {
         $options['db'] = $referenceTable->getAdapter();
     }
     if (isset($tableDefinition) && $tableDefinition !== null) {
         $options[\libDb\Table\AbstractTable::DEFINITION] = $tableDefinition;
     }
     return new $tableName($options);
 }
Exemplo n.º 5
0
 /**
  * _getTableFromString
  *
  * @param string $tableName
  * @return \libDb\Table\AbstractTable
  */
 protected function _getTableFromString($tableName)
 {
     return \libDb\Table\AbstractTable::getTableFromString($tableName, $this->_table);
 }