Пример #1
0
 /**
  * retrieve array of XoopsBlock objects meeting certain conditions
  *
  * @param CriteriaElement|null $criteria  criteria to match
  * @param bool                 $id_as_key should the blocks' bid be the key for the returned array?
  *
  * @return XoopsBlock[]
  **/
 public function getDistinctObjects(CriteriaElement $criteria = null, $id_as_key = false)
 {
     $ret = array();
     $qb = $this->db2->createXoopsQueryBuilder();
     $eb = $qb->expr();
     $qb->select('DISTINCT(b.bid)')->addSelect('b.*')->fromPrefix('system_block', 'b')->leftJoinPrefix('b', 'system_blockmodule', 'l', $eb->eq('b.bid', 'l.block_id'));
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         $criteria->renderQb($qb);
     }
     $result = $qb->execute();
     if (!$result) {
         return $ret;
     }
     while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) {
         $block = new XoopsBlock();
         $block->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] = $block;
         } else {
             $ret[$myrow['bid']] = $block;
         }
         unset($block);
     }
     return $ret;
 }