コード例 #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;
 }
コード例 #2
0
ファイル: Read.php プロジェクト: redmexico/XoopsCore
 /**
  * getRandomObject - return a randomly selected object
  *
  * @param CriteriaElement|null $criteria criteria to match
  *
  * @return \Xoops\Core\Kernel\XoopsObject|null object or null if no matching object found
  */
 public function getRandomObject(CriteriaElement $criteria = null)
 {
     $qb = $this->handler->db2->createXoopsQueryBuilder();
     $qb->select('COUNT(*)')->from($this->handler->table, null);
     if (null !== $criteria) {
         $qb = $criteria->renderQb($qb);
     }
     $result = $qb->execute();
     $count = $result->fetchColumn();
     $offset = mt_rand(0, $count - 1);
     $qb = $this->handler->db2->createXoopsQueryBuilder();
     $qb->select($this->handler->keyName)->from($this->handler->table, null);
     if (null !== $criteria) {
         $qb = $criteria->renderQb($qb);
     }
     $qb->setFirstResult($offset)->setMaxResults(1);
     $result = $qb->execute();
     $randomKey = $result->fetchColumn();
     return $this->handler->get($randomKey);
 }
コード例 #3
0
 /**
  * Load some modules
  *
  * @param CriteriaElement|null $criteria  criteria to match
  * @param boolean              $id_as_key Use the ID as key into the array
  *
  * @return array
  */
 public function getObjectsArray(CriteriaElement $criteria = null, $id_as_key = false)
 {
     $ret = array();
     $qb = $this->db2->createXoopsQueryBuilder();
     $qb->select('*')->fromPrefix('system_module', null);
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         $criteria->setSort('weight');
         $criteria->renderQb($qb);
         $qb->addOrderBy('mid', 'ASC');
     }
     // During install, we start with no tables and no installed modules. We need to
     // handle the resulting exceptions and return an empty array.
     try {
         if (!($result = $qb->execute())) {
             return $ret;
         }
     } catch (\Doctrine\DBAL\Driver\PDOException $e) {
         return $ret;
     } catch (\Doctrine\DBAL\Exception\TableNotFoundException $e) {
         return $ret;
     } catch (\PDOException $e) {
         return $ret;
     }
     while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) {
         $module = new XoopsModule();
         $module->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] = $module;
         } else {
             $ret[$myrow['mid']] = $module;
         }
         unset($module);
     }
     return $ret;
 }
コード例 #4
0
 /**
  * Get count of users belonging to certain groups and matching criteria
  * Temporary solution
  *
  * @param array                $groups   IDs of groups
  * @param CriteriaElement|null $criteria criteria to match
  *
  * @return int count of users
  */
 public function getUserCountByGroupLink($groups, $criteria = null)
 {
     $qb = $this->userHandler->db2->createXoopsQueryBuilder();
     $eb = $qb->expr();
     $qb->select('COUNT(DISTINCT u.uid)')->fromPrefix('system_user', 'u')->leftJoinPrefix('u', 'system_usergroup', 'm', 'm.uid = u.uid');
     $where = false;
     if (!empty($groups)) {
         $qb->where($eb->in('m.groupid', $groups));
         $where = true;
     }
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         $whereMode = $where ? 'AND' : '';
         $criteria->renderQb($qb, $whereMode);
     }
     $result = $qb->execute();
     $ret = $result->fetchColumn(0);
     return $ret;
 }
コード例 #5
0
ファイル: notification.php プロジェクト: ming-hai/XoopsCore
 /**
  * Get some {@link NotificationsNotification}s
  *
  * @param CriteriaElement|null $criteria  criteria object
  * @param bool                 $id_as_key Use IDs as keys into the array?
  *
  * @return  array   Array of {@link NotificationsNotification} objects
  */
 public function getObjectsArray(CriteriaElement $criteria = null, $id_as_key = false)
 {
     $qb = $this->db2->createXoopsQueryBuilder()->select('*')->from($this->table, null);
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         $criteria->renderQb($qb);
     }
     $result = $qb->execute();
     $ret = array();
     if (!$result) {
         return $ret;
     }
     while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) {
         $notification = new NotificationsNotification();
         $notification->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] = $notification;
         } else {
             $ret[$myrow['id']] = $notification;
         }
         unset($notification);
     }
     return $ret;
 }
コード例 #6
0
ファイル: Stats.php プロジェクト: RanLee/XoopsCore
 /**
  * get counts matching a condition
  *
  * @param CriteriaElement|null $criteria {@link CriteriaElement} to match
  *
  * @return array of counts
  */
 public function getCounts(CriteriaElement $criteria = null)
 {
     $qb = \Xoops::getInstance()->db()->createXoopsQueryBuilder();
     $eb = $qb->expr();
     $ret = array();
     $sql_where = '';
     $limit = null;
     $start = null;
     $groupby_key = $this->handler->keyName;
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         if ($groupby = $criteria->getGroupby()) {
             $groupby_key = $groupby;
         }
     }
     $qb->select($groupby_key)->addSelect('COUNT(*)')->from($this->handler->table, null);
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         $qb = $criteria->renderQb($qb);
     }
     $result = $qb->execute();
     if (!$result) {
         return $ret;
     }
     while (list($id, $count) = $result->fetch(\PDO::FETCH_NUM)) {
         $ret[$id] = $count;
     }
     return $ret;
 }
コード例 #7
0
ファイル: Write.php プロジェクト: RanLee/XoopsCore
 /**
  * Change a field for objects with a certain criteria
  *
  * @param string               $fieldname  Name of the field
  * @param mixed                $fieldvalue Value to write
  * @param CriteriaElement|null $criteria   {@link CriteriaElement}
  * @param bool                 $force      force to query
  *
  * @return bool
  */
 public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
 {
     $qb = $this->handler->db2->createXoopsQueryBuilder();
     //$queryFunc = empty($force) ? 'query' : 'queryF';
     $qb->update($this->handler->table);
     if (isset($criteria)) {
         $qb = $criteria->renderQb($qb);
     }
     $qb->set($fieldname, $qb->createNamedParameter($fieldvalue));
     return $qb->execute();
 }
コード例 #8
0
ファイル: module.php プロジェクト: RanLee/XoopsCore
 /**
  * Load some modules
  *
  * @param CriteriaElement|null $criteria  {@link CriteriaElement}
  * @param boolean              $id_as_key Use the ID as key into the array
  *
  * @return array
  */
 public function getObjectsArray(CriteriaElement $criteria = null, $id_as_key = false)
 {
     $ret = array();
     $qb = $this->db2->createXoopsQueryBuilder();
     $qb->select('*')->fromPrefix('modules', null);
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         $criteria->setSort('weight');
         $criteria->renderQb($qb);
         $qb->addOrderBy('mid', 'ASC');
     }
     try {
         if (!($result = $qb->execute())) {
             return $ret;
         }
     } catch (Exception $e) {
         return $ret;
     }
     while ($myrow = $result->fetch(PDO::FETCH_ASSOC)) {
         $module = new XoopsModule();
         $module->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] = $module;
         } else {
             $ret[$myrow['mid']] = $module;
         }
         unset($module);
     }
     return $ret;
 }
コード例 #9
0
 /**
  * getTplObjects
  *
  * @param CriteriaElement|null $criteria  criteria to match
  * @param bool                 $getsource include the source
  * @param bool                 $id_as_key use the object id as array key
  *
  * @return array
  */
 public function getTplObjects(CriteriaElement $criteria = null, $getsource = false, $id_as_key = false)
 {
     $qb = $this->db2->createXoopsQueryBuilder();
     $eb = $qb->expr();
     $ret = array();
     if (!$getsource) {
         $qb->select('*')->fromPrefix('system_tplfile', 'f');
     } else {
         $qb->select('f.*')->addSelect('s.tpl_source')->fromPrefix('system_tplfile', 'f')->leftJoinPrefix('f', 'system_tplsource', 's', $eb->eq('s.tpl_id', 'f.tpl_id'));
     }
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         $criteria->renderQb($qb);
     }
     $result = $qb->execute();
     if (!$result) {
         return $ret;
     }
     while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) {
         $tplfile = new XoopsTplFile();
         $tplfile->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] = $tplfile;
         } else {
             $ret[$myrow['tpl_id']] = $tplfile;
         }
         unset($tplfile);
     }
     return $ret;
 }
コード例 #10
0
ファイル: Joint.php プロジェクト: ming-hai/XoopsCore
 /**
  * array of count of objects matching a condition of, groupby linked object keyname
  *
  * @param CriteriaElement $criteria criteria to match
  *
  * @return false|int count of objects
  */
 public function getCountsByLink(CriteriaElement $criteria = null)
 {
     if (!$this->validateLinks()) {
         return false;
     }
     $qb = $this->handler->db2->createXoopsQueryBuilder();
     $qb->select("l.{$this->handler->keyName_link}")->addSelect('COUNT(*)')->from($this->handler->table, 'o')->leftJoin('o', $this->handler->table_link, 'l', "o.{$this->handler->field_object} = l.{$this->handler->field_link}");
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         $criteria->renderQb($qb);
     }
     $qb->groupBy("l.{$this->handler->keyName_link}");
     $result = $qb->execute();
     $ret = array();
     while (list($id, $count) = $result->fetch(\PDO::FETCH_NUM)) {
         $ret[$id] = $count;
     }
     return $ret;
 }