Beispiel #1
0
 public function read(Query $query)
 {
     $metaclass = $query->getMetaclass();
     $table = $this->getTable($metaclass->getStorageName());
     $select = new Select(array($table));
     $conditions = array();
     foreach ($query->getConditions() as $condition) {
         $column = $this->getColumnFromProperty($table, $condition->subject);
         $newCondition = $column->op($condition->operator, $condition->value);
         if ($condition->negated) {
             $newCondition->negate();
         }
         $conditions[] = $newCondition;
     }
     if (count($conditions) !== 0) {
         call_user_func_array(array($select, 'where'), $conditions);
     }
     $sorts = array();
     foreach ($query->getSorts() as $sort) {
         $column = $this->getColumnFromProperty($table, $sort->subject);
         $newSort = $sort->ascending ? $column->asc() : $column->desc();
         $sorts[] = $newSort;
     }
     if (count($sorts) !== 0) {
         call_user_func_array(array($select, 'orderBy'), $sorts);
     }
     $limit = $query->getLimit();
     if ($limit) {
         $select->limit($limit);
     }
     $offset = $query->getOffset();
     if ($offset) {
         $select->offset($offset);
     }
     return $this->connection->execute($select);
 }
Beispiel #2
0
 public function read(Query $query)
 {
     return $query->getMetaclass()->load($this->getAdapter()->read($query));
 }