public function load(MagicObject $object, $id) { if (!is_array($id) && count($this->_keyField) == 1) { $id = array($this->_keyField[0] => $id); } if (count($id) != ($fieldsCount = count($this->_keyField))) { throw new \Exception("Invalid ID specified (should have {$fieldsCount} fields)"); } foreach ($this->_keyField as $kf) { $object->setData($kf, $id[$kf]); } $select = $this->getSql()->select(); $select->columns(array('*')); foreach ($this->_keyField as $field) { if (!isset($id[$field])) { throw new \Exception('Missing field "' . $field . '" in ID'); } $select->where(array($field => $id[$field])); } $select->limit(1); $result = $this->getDb()->query($this->getSql()->buildSqlString($select), Adapter::QUERY_MODE_EXECUTE); $data = $result->current(); if ($data) { $object->addData((array) $data); } return $this; }
public function addItem(MagicObject $item) { if ($this->_keyField !== null && ($key = $item->getDataUsingMethod($this->_keyField)) !== null) { $this->_items[$key] = $item; } else { $this->_items[] = $item; } $this->_isLoaded = false; return $this; }
public function __construct($data = array()) { //FIXME Date patterns used by Chart.js are different from PHP's... :( //$this->_defaultData['scale_date_time_format'] = I18n::instance()->getDateFormatterInstance()->getPattern(); $this->_defaultData['scale_date_time_format'] = 'yyyy-mm-dd'; $this->_defaultData['scale_date_format'] = 'yyyy-mm-dd'; parent::__construct(array_merge(self::$_commonDefaultData, $this->_defaultData, $data)); }
public function getValue() { $useRequest = true; // TODO Use config $useDefault = true; // TODO Use config if (!($v = parent::getValue())) { if (!$useRequest || !($v = \Base::instance()->get('REQUEST.' . $this->getName()))) { if (!$useDefault || !($v = parent::getDefaultValue())) { $v = null; } } } return $v; }