info() public method

You can elect to return only a part of this information by supplying its key name, otherwise all information is returned as an array.
public info ( string $key = null ) : mixed
$key string The specific info part to return OPTIONAL
return mixed
Example #1
0
 /**
  * Construct Dataset Table from Zend_Db_Table object
  *
  * @param Zend_Db_Table_Abstract        $table
  * @param string|Zend_Db_Select|null    $where
  * @param string|null                   $order
  * @param int                           $count
  * @param int                           $offset
  */
 public function __construct(Zend_Db_Table_Abstract $table, $where = null, $order = null, $count = null, $offset = null)
 {
     $this->tableName = $table->info('name');
     $this->_columns = $table->info('cols');
     $this->_table = $table;
     $this->_where = $where;
     $this->_order = $order;
     $this->_count = $count;
     $this->_offset = $offset;
 }
Example #2
0
 public function setModel(Zend_Db_Table_Abstract $model)
 {
     $this->_model = $model;
     $this->_setPrimaryIndex($this->_model->getPrimaryIndex());
     $info = $model->info();
     $this->_columns = $info['cols'];
 }
 /**
  * Set the table object, to re-establish a live connection
  * to the database for a Row that has been de-serialized.
  *
  * @param Zend_Db_Table_Abstract $table
  * @return boolean
  * @throws Zend_Db_Table_Row_Exception
  */
 public function setTable(Zend_Db_Table_Abstract $table = null)
 {
     if ($table == null) {
         $this->_table = null;
         $this->_connected = false;
         return false;
     }
     $tableClass = get_class($table);
     if (!$table instanceof $this->_tableClass) {
         require_once 'Zend/Db/Table/Row/Exception.php';
         throw new Zend_Db_Table_Row_Exception("The specified Table is of class {$tableClass}, expecting class to be instance of {$this->_tableClass}");
     }
     $this->_table = $table;
     $this->_tableClass = $tableClass;
     $info = $this->_table->info();
     if ($info['cols'] != array_keys($this->_data)) {
         require_once 'Zend/Db/Table/Row/Exception.php';
         throw new Zend_Db_Table_Row_Exception('The specified Table does not have the same columns as the Row');
     }
     if (!array_intersect((array) $this->_primary, $info['primary']) == (array) $this->_primary) {
         require_once 'Zend/Db/Table/Row/Exception.php';
         throw new Zend_Db_Table_Row_Exception("The specified Table '{$tableClass}' does not have the same primary key as the Row");
     }
     $this->_connected = true;
     return true;
 }
Example #4
0
 /**
  * Creating a query using a Model.
  *
  * @param Zend_Db_Table_Abstract $model
  * @param array                  $relationmap Relation map for joins
  *
  * @return $this
  */
 public function __construct(Zend_Db_Table_Abstract $model, array $relationMap = array())
 {
     $this->_model = $model;
     $this->_relationMap = $relationMap;
     $info = $model->info();
     $select = $model->select();
     $map = $info['referenceMap'];
     $map = array_merge_recursive($map, $this->_relationMap);
     if (is_array($map) && count($map) > 0) {
         $select->setIntegrityCheck(false);
         $columnsToRemove = array();
         foreach ($map as $sel) {
             if (is_array($sel['columns'])) {
                 $columnsToRemove = array_merge($columnsToRemove, $sel['columns']);
             } else {
                 $columnsToRemove[] = $sel['columns'];
             }
         }
         $columnsMainTable = array_diff($info['cols'], $columnsToRemove);
         $select->from($info['name'], $columnsMainTable, $info['schema']);
         $tAlias = array($info['name'] => 1);
         $this->_setJoins($info['name'], $map, $select, $tAlias);
     } else {
         $select->from($info['name'], $info['cols'], $info['schema']);
     }
     parent::__construct($select);
     return $this;
 }
 /**
  * Start analyzer
  *
  * @param Zend_Db_Table_Abstract $table
  *
  * @return array
  */
 public function analyzeTable(Zend_Db_Table_Abstract $table)
 {
     $info = $table->info();
     $info['uniques'] = array();
     unset($info['sequence'], $info['schema'], $info['rowClass'], $info['rowsetClass'], $info['dependentTables'], $info['referenceMap']);
     $adapter = $table->getAdapter();
     foreach ($info['metadata'] as $property => $details) {
         // match php types
         $info['phptypes'][$property] = $this->convertMysqlTypeToPhp($details['DATA_TYPE']);
         // find uniques
         $tmp = $adapter->fetchRow('DESCRIBE `' . $info['name'] . '` `' . $property . '`;');
         if (!empty($tmp['Key']) && $tmp['Key'] != 'MUL') {
             $info['uniques'][$property] = $property;
         }
     }
     // get f-keys
     $result = $adapter->fetchAll('SHOW CREATE TABLE `' . $info['name'] . '`');
     $query = $result[0]['Create Table'];
     $lines = explode("\n", $query);
     $tblinfo = array();
     $keys = array();
     foreach ($lines as $line) {
         preg_match('/^\\s*CONSTRAINT `(\\w+)` FOREIGN KEY \\(`(\\w+)`\\) REFERENCES `(\\w+)` \\(`(\\w+)`\\)/', $line, $tblinfo);
         if (sizeof($tblinfo) > 0) {
             $keys[] = $tmp = array('key' => $tblinfo[1], 'column' => $tblinfo[2], 'fk_table' => $tblinfo[3], 'fk_column' => $tblinfo[4]);
             $this->getDependencyChecker()->isChild($info['name'], $tmp['column'], $tmp['key'], $tmp['fk_table'], $tmp['fk_column']);
         }
     }
     $info['foreign_keys'] = $keys;
     return $info;
 }
Example #6
0
 /**
  * Override parent info() method to allow returning default order configuration
  * option.
  * @param string $key The specific info part to return. OPTIONAL.
  * @return mixed
  */
 public function info($key = null)
 {
     if ($key == self::DEFAULT_ORDER) {
         return $this->getDefaultOrder();
     } else {
         return parent::info($key);
     }
 }
 /**
  * lockTable   
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0 
  */
 public function lockTable()
 {
     try {
         $this->objTable->getAdapter()->query('LOCK TABLES ' . $this->objTable->info(Zend_Db_Table_Abstract::NAME) . ' WRITE;');
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
Example #8
0
 /**
  * 
  * @access public
  * @param array $data
  * @return array
  */
 public function cleanData(array $data)
 {
     $fields = parent::info(parent::COLS);
     foreach ($data as $key => $value) {
         if (!in_array($key, $fields)) {
             unset($data[$key]);
         }
     }
     return $data;
 }
Example #9
0
 /**
  * Get basic select (select {$fields} from {$table}) and add filters, order and limit info from request
  * @param Zend_Db_Table_Abstract $table
  * @param string|array $fields array of fields or "*" Use as {@see Zend_Db_Select::from()} second params
  * @return Zend_Db_Select
  */
 public function getSelect(Zend_Db_Table_Abstract $table, $fields = "*")
 {
     //create basic selects
     $select = $table->getAdapter()->select()->from($table->info(Zend_Db_Table_Abstract::NAME), $fields);
     $cols = $table->info(Zend_Db_Table::COLS);
     //add filters support
     foreach ((array) $this->getRequest()->getParam('filter') as $value) {
         $field = $value['field'];
         if (in_array($field, $cols)) {
             $filter = System_Controller_Action_Helper_GridFilter_Abstract::factory($value['data']);
             $filter->setField($field);
             $filter->filter($select);
         }
     }
     //add sort
     $sortCol = $this->getRequest()->getParam('sort');
     if (in_array($sortCol, $cols)) {
         $select->order($sortCol . ' ' . $this->_getDirState('dir'));
     }
     //set limit
     $select->limit((int) $this->getRequest()->getParam('limit', 25), (int) $this->getRequest()->getParam('start'));
     return $select;
 }
 /**
  * Get configured database table
  * 
  * @return Zend_Db_Table_Abstract|string
  */
 public function getDbTable()
 {
     if (null === $this->_dbTable) {
         throw new Engine_ServiceLocator_Exception('Invalid database table');
     } else {
         if (is_string($this->_dbTable)) {
             return $this->_dbTable;
         } else {
             if ($this->_dbTable instanceof Zend_Db_Table_Abstract) {
                 return $this->_dbTable->info('name');
             } else {
                 throw new Engine_ServiceLocator_Exception('Invalid database table');
             }
         }
     }
 }
Example #11
0
 protected function _loadAndReturnRow($position)
 {
     if (!isset($this->_data[$position])) {
         throw new Zend_Db_Table_Rowset_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 Zend_Db_Table_Abstract) {
             $info = $this->_table->info();
             if ($this->_rows[$position] instanceof Zend_Db_Table_Row_Abstract) {
                 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];
 }
Example #12
0
 /**
  * @return string
  */
 private function _getTable()
 {
     return $this->obj->info('name');
 }
 /**
  * Return the name of a table object
  *
  * @param \Zend_Db_Table_Abstract $table
  * @return string
  */
 protected function _getTableName(\Zend_Db_Table_Abstract $table)
 {
     return $table->info(\Zend_Db_Table_Abstract::NAME);
 }
Example #14
0
 /**
 * Adds a FROM table and optional columns to the query.
 *
 * The table name can be expressed
 *
 * @param  array|string|Zend_Db_Expr|Zend_Db_Table_Abstract $name The table name or an 
                                                                  associative array relating 
                                                                  table name to correlation
                                                                  name.
 * @param  array|string|Zend_Db_Expr $cols The columns to select from this table.
 * @param  string $schema The schema name to specify, if any.
 * @return Zend_Db_Table_Select This Zend_Db_Table_Select object.
 */
 public function from($name, $cols = '*', $schema = null)
 {
     if ($name instanceof Zend_Db_Table_Abstract) {
         $info = $name->info();
         $name = $info[Zend_Db_Table_Abstract::NAME];
     }
     return $this->joinInner($name, null, $cols, $schema);
 }
Example #15
0
 /**
  * Prepares a table reference for lookup.
  *
  * Ensures all reference keys are set and properly formatted.
  *
  * @param Zend_Db_Table_Abstract $parentTable
  * @param string                 $tableClass
  * @param string                 $ruleKey
  * @return array
  */
 protected function _prepareReference(Zend_Db_Table_Abstract $table, $tableClass, $ruleKey)
 {
     $map = $table->getReference($tableClass, $ruleKey);
     if (!is_array($map[Zend_Db_Table_Abstract::COLUMNS])) {
         $map[Zend_Db_Table_Abstract::COLUMNS] = (array) $map[Zend_Db_Table_Abstract::COLUMNS];
     }
     if (!isset($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
         $info = $table->info();
         $map[Zend_Db_Table_Abstract::REF_COLUMNS] = $info['primary'];
     }
     if (!is_array($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
         $map[Zend_Db_Table_Abstract::REF_COLUMNS] = (array) $map[Zend_Db_Table_Abstract::REF_COLUMNS];
     }
     return $map;
 }
Example #16
0
 /**
 * Adds a FROM table and optional columns to the query.
 *
 * The table name can be expressed
 *
 * @param  array|string|Zend_Db_Expr|Zend_Db_Table_Abstract $name The table name or an
                                                                  associative array relating
                                                                  table name to correlation
                                                                  name.
 * @param  array|string|Zend_Db_Expr $cols The columns to select from this table.
 * @param  string $schema The schema name to specify, if any.
 * @return Zend_Db_Table_Select This Zend_Db_Table_Select object.
 */
 public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
 {
     if ($name instanceof Zend_Db_Table_Abstract) {
         $info = $name->info();
         $name = $info[Zend_Db_Table_Abstract::NAME];
         if (isset($info[Zend_Db_Table_Abstract::SCHEMA])) {
             $schema = $info[Zend_Db_Table_Abstract::SCHEMA];
         }
     }
     return $this->joinInner($name, null, $cols, $schema);
 }
Example #17
0
 /**
  * Retrieve information about attached table.
  *
  * @param string $key OPTIONAL Key
  */
 public function info($key = null)
 {
     $this->_setupPrimaryKey();
     if (null !== $key) {
         switch ($key) {
             case self::NAME:
                 return $this->_name;
             case self::COLS:
                 return $this->_getCols();
             case self::MANY_DEPENDENT_TABLES:
                 return $this->_manyDependentTables;
             case self::SCHEMA:
                 return $this->_schema;
             case self::PRIMARY:
                 $this->_setupPrimaryKey();
                 return (array) $this->_primary;
             case self::METADATA:
                 return $this->_metadata;
             case self::ROW_CLASS:
                 return $this->getRowClass();
             case self::ROWSET_CLASS:
                 return $this->getRowsetClass();
             case self::REFERENCE_MAP:
                 return $this->_referenceMap;
             case self::DEPENDENT_TABLES:
                 return $this->_dependentTables;
             case self::SEQUENCE:
                 return $this->_sequence;
         }
     }
     return parent::info($key);
 }
Example #18
0
 /**
  * Add a Table dataset representation by specifiying an arbitrary select query.
  *
  * By default a select * will be done on the given tablename.
  *
  * @param Zend_Db_Table_Abstract $table
  * @param string|Zend_Db_Select $query
  * @param string $where
  * @param string $order
  * @param string $count
  * @param string $offset
  */
 public function addTable(Zend_Db_Table_Abstract $table, $where = null, $order = null, $count = null, $offset = null)
 {
     $tableName = $table->info('name');
     $this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset);
 }
Example #19
0
 /**
  * Sets the primary table name and retrieves the table schema
  *
  * @param Zend_Db_Table_Abstract $adapter
  */
 public function setTable(Zend_Db_Table_Abstract $table)
 {
     $this->_adapter = $table->getAdapter();
     $this->_info = $table->info();
     return $this;
 }