/** * retrieve a specific {@link XoopsBlock} * * @see XoopsBlock * @param int $id bid of the block to retrieve * @return object XoopsBlock reference to the block **/ function &get($id) { $id = (int) $id; if ($id > 0) { $sql = 'SELECT * FROM ' . $this->db->prefix('newblocks') . ' WHERE bid=' . $id; if (!($result = $this->db->query($sql))) { $ret = false; //< You may think this should be null. But this is the compatibility with X2. return $ret; } $numrows = $this->db->getRowsNum($result); if ($numrows == 1) { $block = new XoopsBlock(); $block->assignVars($this->db->fetchArray($result)); return $block; } } $ret = false; //< You may think this should be null. But this is the compatibility with X2. return $ret; }
/** * retrieve array of {@link XoopsBlock}s meeting certain conditions * @param CriteriaElement $criteria {@link CriteriaElement} with conditions for the blocks * @param bool $id_as_key should the blocks' bid be the key for the returned array? * @return array {@link XoopsBlock}s matching the conditions **/ public function getObjects(CriteriaElement $criteria = null, $id_as_key = false) { $ret = array(); $limit = $start = 0; $sql = 'SELECT DISTINCT(b.bid), b.* FROM ' . $this->db->prefix('newblocks') . ' b LEFT JOIN ' . $this->db->prefix('block_module_link') . ' l ON b.bid=l.block_id'; if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { $sql .= ' ' . $criteria->renderWhere(); $limit = $criteria->getLimit(); $start = $criteria->getStart(); } $result = $this->db->query($sql, $limit, $start); if (!$result) { return $ret; } while ($myrow = $this->db->fetchArray($result)) { $block = new XoopsBlock(); $block->assignVars($myrow); if (!$id_as_key) { $ret[] =& $block; } else { $ret[$myrow['bid']] =& $block; } unset($block); } return $ret; }
/** * retrieve array of {@link XoopsBlock}s meeting certain conditions * @param CriteriaElement|null $criteria {@link CriteriaElement} with conditions for the blocks * @param bool $id_as_key should the blocks' bid be the key for the returned array? * @return array {@link XoopsBlock}s matching the conditions **/ 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('newblocks', 'b')->leftJoinPrefix('b', 'block_module_link', '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; }