/library/Ecart/Db/Table/Row.php
PHP | 154 lines | 51 code | 11 blank | 92 comment | 4 complexity | afdac06f28899e848055a3dffa42a22e MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
- <?php
- /**
- * Ecart
- *
- * This file is part of Ecart.
- *
- * Ecart is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Ecart is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Ecart. If not, see <http://www.gnu.org/licenses/>.
- *
- * @category Ecart
- * @package Ecart_Db
- * @copyright Copyright 2008-2009 E-Cart LLC
- * @license GNU Public License V3.0
- */
- /**
- *
- * @category Ecart
- * @package Ecart_Db
- * @author Ecart Core Team <core@ecartcommerce.com>
- */
- class Ecart_Db_Table_Row extends Zend_Db_Table_Row_Abstract
- {
- // /**
- // * @var array
- // */
- // protected $_dataTypes = array(
- // 'bit' => 'int',
- // 'tinyint' => 'int',
- // 'bool' => 'bool',
- // 'boolean' => 'bool',
- // 'smallint' => 'int',
- // 'mediumint' => 'int',
- // 'int' => 'int',
- // 'integer' => 'int',
- // 'bigint' => 'float',
- // 'serial' => 'int',
- // 'float' => 'float',
- // 'double' => 'float',
- // 'decimal' => 'float',
- // 'dec' => 'float',
- // 'fixed' => 'float',
- // 'year' => 'int'
- // );
- /**
- *
- * @var string
- */
- protected $_prefix;
-
- /**
- * Initialize object
- *
- * Called from {@link __construct()} as final step of object instantiation.
- *
- * @return void
- */
- public function init()
- {
- parent::init();
-
- $this->_prefix = $this->getTable()->info(Ecart_Db_Table::PREFIX);
- // // auto type converting
- // $cols = $this->getTable()->info(Zend_Db_Table_Abstract::METADATA);
- // foreach ($cols as $name => $col) {
- // $dataType = strtolower($col['DATA_TYPE']);
- // if (array_key_exists($dataType, $this->_dataTypes)) {
- // settype($this->_data[$name], $this->_dataTypes[$dataType]);
- // }
- // }
- }
- /**
- * Sets all data in the row from an array.
- *
- * @param array $data
- * @return Ecart_Db_Table_Row Provides a fluent interface
- */
- public function setFromArray(array $data)
- {
- foreach ($this->getTable()->info('cols') as $fieldName) {
- if (isset($data[$fieldName])) {
- $this->$fieldName = $data[$fieldName];
- }
- }
- return $this;
- }
- /**
- * Returns the table object, or null if this is disconnected row
- *
- * @return Zend_Db_Table_Abstract|null
- */
- public function getTable()
- {
- $table = $this->_table;
- if (null === $table && !empty($this->_tableClass)) {
- $tableClass = $this->_tableClass;
- $table = Ecart::single($tableClass);
- $this->setTable($table);
- }
- return $table;
- }
-
- /**
- * Retrun current datebase adapter
- *
- * @return Zend_Db_Adapter_Abstract
- */
- public function getAdapter()
- {
- return $this->getTable()->getAdapter();
- }
- /**
- * @return mixed The primary key value(s), as an associative array if the
- * key is compound, or a scalar if the key is single-column.
- */
- public function save()
- {
- try {
- return parent::save();
- } catch (Exception $e) {
- Ecart::message()->addError($e->getMessage());
- return false;
- }
- }
- /**
- * @return Ecart_Db_Table_Row
- */
- public function cache()
- {
- $frontend = Ecart::single('Ecart_Cache_Frontend_Query');
- if (func_num_args()) {
- $args = serialize(func_get_args());
- return $frontend->setInstance($this, $args);
- }
- return $frontend->setInstance($this);
- }
- }