PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Ecart/Db/Table/Row.php

https://code.google.com/p/ecartcommerce/
PHP | 154 lines | 51 code | 11 blank | 92 comment | 4 complexity | afdac06f28899e848055a3dffa42a22e MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Ecart
  4. *
  5. * This file is part of Ecart.
  6. *
  7. * Ecart is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Ecart is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Ecart. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @category Ecart
  21. * @package Ecart_Db
  22. * @copyright Copyright 2008-2009 E-Cart LLC
  23. * @license GNU Public License V3.0
  24. */
  25. /**
  26. *
  27. * @category Ecart
  28. * @package Ecart_Db
  29. * @author Ecart Core Team <core@ecartcommerce.com>
  30. */
  31. class Ecart_Db_Table_Row extends Zend_Db_Table_Row_Abstract
  32. {
  33. // /**
  34. // * @var array
  35. // */
  36. // protected $_dataTypes = array(
  37. // 'bit' => 'int',
  38. // 'tinyint' => 'int',
  39. // 'bool' => 'bool',
  40. // 'boolean' => 'bool',
  41. // 'smallint' => 'int',
  42. // 'mediumint' => 'int',
  43. // 'int' => 'int',
  44. // 'integer' => 'int',
  45. // 'bigint' => 'float',
  46. // 'serial' => 'int',
  47. // 'float' => 'float',
  48. // 'double' => 'float',
  49. // 'decimal' => 'float',
  50. // 'dec' => 'float',
  51. // 'fixed' => 'float',
  52. // 'year' => 'int'
  53. // );
  54. /**
  55. *
  56. * @var string
  57. */
  58. protected $_prefix;
  59. /**
  60. * Initialize object
  61. *
  62. * Called from {@link __construct()} as final step of object instantiation.
  63. *
  64. * @return void
  65. */
  66. public function init()
  67. {
  68. parent::init();
  69. $this->_prefix = $this->getTable()->info(Ecart_Db_Table::PREFIX);
  70. // // auto type converting
  71. // $cols = $this->getTable()->info(Zend_Db_Table_Abstract::METADATA);
  72. // foreach ($cols as $name => $col) {
  73. // $dataType = strtolower($col['DATA_TYPE']);
  74. // if (array_key_exists($dataType, $this->_dataTypes)) {
  75. // settype($this->_data[$name], $this->_dataTypes[$dataType]);
  76. // }
  77. // }
  78. }
  79. /**
  80. * Sets all data in the row from an array.
  81. *
  82. * @param array $data
  83. * @return Ecart_Db_Table_Row Provides a fluent interface
  84. */
  85. public function setFromArray(array $data)
  86. {
  87. foreach ($this->getTable()->info('cols') as $fieldName) {
  88. if (isset($data[$fieldName])) {
  89. $this->$fieldName = $data[$fieldName];
  90. }
  91. }
  92. return $this;
  93. }
  94. /**
  95. * Returns the table object, or null if this is disconnected row
  96. *
  97. * @return Zend_Db_Table_Abstract|null
  98. */
  99. public function getTable()
  100. {
  101. $table = $this->_table;
  102. if (null === $table && !empty($this->_tableClass)) {
  103. $tableClass = $this->_tableClass;
  104. $table = Ecart::single($tableClass);
  105. $this->setTable($table);
  106. }
  107. return $table;
  108. }
  109. /**
  110. * Retrun current datebase adapter
  111. *
  112. * @return Zend_Db_Adapter_Abstract
  113. */
  114. public function getAdapter()
  115. {
  116. return $this->getTable()->getAdapter();
  117. }
  118. /**
  119. * @return mixed The primary key value(s), as an associative array if the
  120. * key is compound, or a scalar if the key is single-column.
  121. */
  122. public function save()
  123. {
  124. try {
  125. return parent::save();
  126. } catch (Exception $e) {
  127. Ecart::message()->addError($e->getMessage());
  128. return false;
  129. }
  130. }
  131. /**
  132. * @return Ecart_Db_Table_Row
  133. */
  134. public function cache()
  135. {
  136. $frontend = Ecart::single('Ecart_Cache_Frontend_Query');
  137. if (func_num_args()) {
  138. $args = serialize(func_get_args());
  139. return $frontend->setInstance($this, $args);
  140. }
  141. return $frontend->setInstance($this);
  142. }
  143. }