コード例 #1
0
ファイル: EntityCollection.php プロジェクト: matak/dbrecord
 /**
  * Load all items defined by fluent.
  *
  * 
  * @return DbRecordCollection
  */
 public function load()
 {
     if ($this->isLoaded()) {
         return $this;
     }
     if (!$this->isLoadable()) {
         throw new Exception('This collection is not loadable! Maybe items were set manualy before load!');
     }
     if (!$this->query) {
         // pokud neni fluent set, nastav defaultni
         $this->query();
         #throw new Exception('Fluent is not set');
     }
     foreach ($this->query->toArray() as $values) {
         $this->repository->createObjectFromValues($values);
         // map by IdentityMap
         if ($this->options['mapped']) {
             $item = $class::identity()->map($item);
         }
         $this->append($item);
     }
     $this->setLoaded(true);
     return $this;
 }
コード例 #2
0
ファイル: Query.php プロジェクト: matak/dbrecord
 /**
  * Fetch single row from database based on defined fluent and obligatory conditions defined in array.
  *
  * @param mixed $primary
  * @return DbRecord
  */
 public function findBy(array $conditions)
 {
     $metadata = $this->repository->getMetadata();
     foreach ($conditions as $key => $value) {
         $this->where('#.' . $key . ' = %' . $metadata->getType($key), $value);
     }
     $values = $this->limit(1)->toArray();
     /* 		
     //no more exceptions on not founded item in dtb
     if ( !$values ) {
     	throw new NotFoundException("Item was not found!");
     } 
     */
     if ($values) {
         return $this->repository->createObjectFromValues($values[0]);
     }
     return NULL;
 }