Ejemplo n.º 1
0
 /**
  * Fetches all SQL result rows as a sequential array.
  *
  * @param Zend_Db_Select $sql An SQL SELECT statement.
  * @param array $bind Data to bind into SELECT placeholders.
  * @return array
  */
 public function fetchObjects($class, $sql = null, $bind = array(), $authRole = null)
 {
     $tmp = new DbResultSet();
     $this->typeManager->includeType($class);
     $map = $this->typeManager->getTypeMap($class);
     $class = strtolower($class);
     if ($sql == null) {
         $sql = $this->select();
         $sql->from($class, '*');
     }
     if (!is_null($authRole)) {
         $itemtype = $class;
         $currentUser = za()->getUser()->getUsername();
         $sql->joinInner('userrole', 'userrole.itemid=' . $itemtype . '.id', new Zend_Db_Expr('userrole.itemtype as userrole_itemtype'));
         // $select->joinInner($usertable, $usertable.'.username=userrole.authority', new Zend_Db_Expr('userrole.authority as userrole_authority'));
         $sql->where('userrole.authority = ?', $currentUser);
         $sql->where(new Zend_Db_Expr('userrole.role & ' . $authRole));
     }
     $result = $this->query($sql, $bind);
     while ($row = $result->fetch(Zend_Db::FETCH_ASSOC)) {
         $obj = new $class();
         $obj = $this->unwrapRowToObject($obj, $row, $map);
         za()->inject($obj);
         $tmp[$obj->id] = $obj;
         // $tmp->append($obj);
     }
     if ($sql instanceof CountableSelect && $sql->isLimited()) {
         $countSql = $sql->getCountQuery();
         $count = $this->fetchOne($countSql);
         $tmp->setTotalResults($count);
     }
     return $tmp;
 }