/** * Initializes a resultset collection. * * @param array $records an array of records to add to the ResultSet */ public function __construct($records = array()) { try { if($records) { foreach($records as $record) { $this->add($record); } } parent::__construct(); } catch(\Exception $ex) { \Bedrock\Common\Logger::exception($ex); throw new \Bedrock\Model\ResultSet\Exception('A result set cound not be initialized.'); } }
/** * Initializes the table object. * * @param array $tableConfig the table configuration * @param \Bedrock\Model\Database $database the Database object to use */ public function __construct($tableConfig = array(), $database = NULL) { try { parent::__construct($database); $this->_name = $tableConfig['name']; $this->_properties = $tableConfig['properties']; // @todo handle column details in tableConfig $this->_state = self::STATE_NEW; } catch(\PDOException $ex) { \Bedrock\Common\Logger::exception($ex); throw new \Bedrock\Model\Exception('The table object could not be initialized.'); } catch(\Exception $ex) { \Bedrock\Common\Logger::exception($ex); throw new \Bedrock\Model\Exception('The table object could not be initialized.'); } }
/** * Initializes the record object. * * @param \PDO $connection the database connection to use * @param \Bedrock\Model\Table the record's corresponding table * @param array $values the record's values */ public function __construct($table, $values = array(), $database = NULL) { try { parent::__construct($database); $this->_table = new \Bedrock\Model\Table(array('name' => $table)); $this->_table->load(); $this->_columns = $this->_table->getColumns(); $this->_state = self::STATE_UNCHANGED; foreach($this->_columns as $column) { switch($column->type) { case \Bedrock\Model\Column::FIELD_TYPE_BOOL: if(is_bool($values[$column->name])) { $this->_data[$column->name] = $values[$column->name]; } else { $this->_data[$column->name] = ($values[$column->name] == 1 ? true : false); } break; default: $this->_data[$column->name] = $values[$column->name]; break; } if($column->primary_key) { $this->_key_primary = $column; if(!$values[$column->name]) { $this->_state = self::STATE_NEW; } } // Foreign Key Reference? } } catch(\Exception $ex) { \Bedrock\Common\Logger::exception($ex); throw new \Bedrock\Model\Record\Exception('A record object could not be initialized.'); } }
/** * Used to initialize a query. See the static from() method for public * initialization. * * @param string $targetName the name of the table/view/procedure to be queried * @param integer $targetType the type of target being queried * @param \PDO $database an optional database connection to use, the default will be used otherwise */ public function __construct($targetName = '', $targetType = self::TARGET_TABLE, $database = NULL) { try { parent::__construct($database); switch($targetType) { default: case self::TARGET_TABLE: case self::TARGET_VIEW: $this->_target = self::TARGET_TABLE; $this->_table = $targetName; $this->_query['from'] = 'SELECT * FROM ' . self::sanitize($targetName); break; case self::TARGET_PROCEDURE: $this->_target = self::TARGET_PROCEDURE; $this->_procedure = $targetName; break; } } catch(\Exception $ex) { \Bedrock\Common\Logger::exception($ex); throw new \Bedrock\Model\Query\Exception('The query could not be initialized for "' . $targetName . '"'); } }