Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
 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;
 }