Esempio n. 1
0
 /**
  * Convert an array to an instance of the specified scheme
  *
  * @param One_Scheme $scheme
  * @param array $row
  * @return One_Model
  */
 private function &arrayToInstance(&$scheme, &$row)
 {
     // check the scheme cache
     $idAttribute = $scheme->getIdentityAttribute();
     $id = $row[$idAttribute->getName()];
     $cached = One_Model_IdentityMap::find($scheme->getName(), $id);
     if ($cached) {
         return $cached;
     }
     // not found : create a new instance
     // @TODO: use a specific class specified in the scheme
     $model = One::make($scheme->getName());
     $model->fromArray($row);
     // fire afterLoad event for model
     $model->afterLoad();
     One_Model_IdentityMap::add($model);
     return $model;
 }
Esempio n. 2
0
 /**
  * Select a single instance.
  *
  * @param One_Scheme $scheme
  * @param mixed $identityValue
  * @return One_Model
  */
 public function selectOne(One_Scheme $scheme, $identityValue)
 {
     $cached = One_Model_IdentityMap::find($scheme->getName(), $identityValue);
     if ($cached) {
         return $cached;
     }
     $db = $this->db($scheme);
     $renderer = $this->getRenderer();
     $query = One_Repository::selectQuery($scheme);
     $idAttr = $scheme->getIdentityAttribute();
     $column = $idAttr->getName();
     $value = $idAttr->toString($identityValue);
     $query->where($column, 'eq', $value);
     $result = $this->executeSchemeQuery($query);
     if (count($result) > 0) {
         $model = $result[0];
         One_Model_IdentityMap::add($model);
         return $model;
     }
     return NULL;
 }