public static function listSettings(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) {
        /* build query */
        $c = $xpdo->newQuery('modSystemSetting');
        $c->select(array(
            $xpdo->getSelectColumns('modSystemSetting','modSystemSetting'),
        ));
        $c->select(array(
            'name_trans' => 'Entry.value',
            'description_trans' => 'Description.value',
        ));
        $c->leftJoin('modLexiconEntry','Entry',"CONCAT('setting_',modSystemSetting.{$xpdo->escape('key')}) = Entry.name");
        $c->leftJoin('modLexiconEntry','Description',"CONCAT('setting_',modSystemSetting.{$xpdo->escape('key')},'_desc') = Description.name");
        $c->where($criteria);

        $count = $xpdo->getCount('modSystemSetting',$c);
        $c->sortby($xpdo->getSelectColumns('modSystemSetting','modSystemSetting','',array('area')),'ASC');
        foreach($sort as $field=> $dir) {
            $c->sortby($xpdo->getSelectColumns('modSystemSetting','modSystemSetting','',array($field)),$dir);
        }
        if ((int) $limit > 0) {
            $c->limit((int) $limit, (int) $offset);
        }
        $c->prepare();
        return array(
            'count'=> $count,
            'collection'=> $xpdo->getCollection('modSystemSetting',$c)
        );
    }
 /**
  * Initializes the field names with the qualified table name.
  *
  * Once this is called, you can lookup the qualified name by the field name
  * itself in {@link xPDOObject::$fieldNames}.
  *
  * @access protected
  */
 protected function _initFields()
 {
     reset($this->_fieldMeta);
     while (list($k, $v) = each($this->_fieldMeta)) {
         $this->fieldNames[$k] = $this->xpdo->escape($this->_table) . '.' . $this->xpdo->escape($k);
     }
 }
Exemple #3
0
 /**
  * Get a full list of all boards on the forum, for any user
  * @static
  * @param xPDO $modx
  * @param int $board
  * @param bool $category
  * @return array
  */
 public static function getList(xPDO &$modx, $board = 0, $category = false)
 {
     $response = array();
     /* get a comma-sep-list of thread IDs for comparing to read ids for user */
     $threadsCriteria = $modx->newQuery('disThread');
     $threadsCriteria->setClassAlias('Threadr');
     $threadsCriteria->select(array('GROUP_CONCAT(Threadr.id)'));
     $threadsCriteria->where(array('Threadr.board = disBoard.id'));
     $threadsCriteria->prepare();
     $threadsSql = $threadsCriteria->toSql();
     /* subboards sql */
     $sbCriteria = $modx->newQuery('disBoard');
     $sbCriteria->setClassAlias('subBoard');
     $sbCriteria->select(array('GROUP_CONCAT(CONCAT_WS(":",subBoardClosureBoard.id,subBoardClosureBoard.name) SEPARATOR "||") AS name'));
     $sbCriteria->innerJoin('disBoardClosure', 'subBoardClosure', 'subBoardClosure.ancestor = subBoard.id');
     $sbCriteria->innerJoin('disBoard', 'subBoardClosureBoard', 'subBoardClosureBoard.id = subBoardClosure.descendant');
     $sbCriteria->where(array('subBoard.id = disBoard.id', 'subBoard.status:!=' => disBoard::STATUS_INACTIVE, 'subBoardClosureBoard.status:!=' => disBoard::STATUS_INACTIVE, 'subBoardClosure.descendant != disBoard.id', 'subBoardClosure.depth' => 1));
     $sbCriteria->groupby($modx->getSelectColumns('disBoard', 'subBoard', '', array('id')));
     $sbCriteria->prepare();
     $sbSql = $sbCriteria->toSql();
     /* get main query */
     $c = $modx->newQuery('disBoard');
     $c->innerJoin('disCategory', 'Category');
     $c->innerJoin('disBoardClosure', 'Descendants');
     $c->leftJoin('disPost', 'LastPost');
     $c->leftJoin('disUser', 'LastPostAuthor', 'LastPost.author = LastPostAuthor.id');
     $c->leftJoin('disThread', 'LastPostThread', 'LastPostThread.id = LastPost.thread');
     $c->where(array('disBoard.status:!=' => disBoard::STATUS_INACTIVE));
     if (isset($board) && $board !== null) {
         $c->where(array('disBoard.parent' => $board));
     }
     if (!empty($category)) {
         $c->where(array('disBoard.category' => $category));
     }
     $ugc = $modx->newQuery('disBoardUserGroup');
     $ugc->select(array('GROUP_CONCAT(usergroup)'));
     $ugc->where(array('board = disBoard.id'));
     $ugc->groupby('board');
     $ugc->prepare();
     $userGroupsSql = $ugc->toSql();
     $response['total'] = $modx->getCount('disBoard', $c);
     $c->query['distinct'] = 'DISTINCT';
     $c->select($modx->getSelectColumns('disBoard', 'disBoard'));
     $c->select(array('Category.name AS category_name', '(' . $sbSql . ') AS ' . $modx->escape('subboards'), '(' . $threadsSql . ') AS ' . $modx->escape('threads'), '(' . $userGroupsSql . ') AS ' . $modx->escape('usergroups'), 'LastPost.id AS last_post_id', 'LastPost.thread AS last_post_thread', 'LastPost.author AS last_post_author', 'LastPost.createdon AS last_post_createdon', 'LastPostThread.replies AS last_post_replies', 'LastPostThread.title AS last_post_title', 'LastPostAuthor.username AS last_post_username', 'LastPostAuthor.use_display_name AS last_post_udn', 'LastPostAuthor.display_name AS last_post_display_name'));
     $c->sortby('Category.rank', 'ASC');
     $c->sortby('disBoard.rank', 'ASC');
     $c->prepare();
     $modx->log(modX::LOG_LEVEL_ERROR, $c->toSQL());
     $response['results'] = $modx->getCollection('disBoard', $c);
     return $response;
 }
 /**
  * Clear the caches of all sources
  * @param array $options
  * @return void
  */
 public function clearCache(array $options = array())
 {
     /** @var modCacheManager $cacheManager */
     $cacheManager = $this->xpdo->getCacheManager();
     if (empty($cacheManager)) {
         return;
     }
     $c = $this->xpdo->newQuery('modContext');
     $c->select($this->xpdo->escape('key'));
     $options[xPDO::OPT_CACHE_KEY] = $this->getOption('cache_media_sources_key', $options, 'media_sources');
     $options[xPDO::OPT_CACHE_HANDLER] = $this->getOption('cache_media_sources_handler', $options, $this->getOption(xPDO::OPT_CACHE_HANDLER, $options));
     $options[xPDO::OPT_CACHE_FORMAT] = (int) $this->getOption('cache_media_sources_format', $options, $this->getOption(xPDO::OPT_CACHE_FORMAT, $options, xPDOCacheManager::CACHE_PHP));
     $options[xPDO::OPT_CACHE_ATTEMPTS] = (int) $this->getOption('cache_media_sources_attempts', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 10));
     $options[xPDO::OPT_CACHE_ATTEMPT_DELAY] = (int) $this->getOption('cache_media_sources_attempt_delay', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000));
     if ($c->prepare() && $c->stmt->execute()) {
         while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) {
             if ($row && !empty($row['key'])) {
                 $cacheManager->delete($row['key'] . '/source', $options);
             }
         }
     }
 }
 /**
  * Fetch all new replies in threads that the active user is a participant in
  *
  * @static
  *
  * @param xPDO $modx A reference to the modX instance
  * @param string $sortBy The column to sort by
  * @param string $sortDir The direction to sort
  * @param int $limit The # of threads to limit
  * @param int $start The index to start by
  * @param boolean $sinceLastLogin
  * @param bool $countOnly Set to true to only return count, not run the actual query
  *
  * @return array An array in results/total format
  */
 public static function fetchNewReplies(xPDO &$modx, $sortBy = 'post_last_on', $sortDir = 'DESC', $limit = 20, $start = 0, $sinceLastLogin = false, $countOnly = false)
 {
     $response = array();
     $c = $modx->newQuery('disThread');
     $c->innerJoin('disBoard', 'Board');
     $c->innerJoin('disUser', 'LastAuthor');
     $c->innerJoin('disThreadParticipant', 'Participants', array("{$modx->escape('Participants')}.{$modx->escape('user')} = {$modx->discuss->user->get('id')}", "{$modx->escape('Participants')}.{$modx->escape('thread')} = {$modx->escape('disThread')}.{$modx->escape('id')}"));
     $groups = $modx->discuss->user->getUserGroups();
     /* usergroup protection */
     if ($modx->discuss->user->isLoggedIn) {
         if ($sinceLastLogin) {
             $lastLogin = $modx->discuss->user->get('last_login');
             if (!empty($lastLogin)) {
                 $c->where(array('disThread.post_last_on:>=' => is_int($lastLogin) ? $lastLogin : strtotime($lastLogin)));
             }
         }
         $ignoreBoards = $modx->discuss->user->get('ignore_boards');
         if (!empty($ignoreBoards)) {
             $c->where(array('Board.id:NOT IN' => explode(',', $ignoreBoards)));
         }
     }
     $cRead = $modx->newQuery('disThreadRead');
     $cRead->select(array($modx->getSelectColumns('disThreadRead', 'disThreadRead', '', array('thread'))));
     $cRead->where(array('user' => $modx->discuss->user->get('id'), "{$modx->escape('disThreadRead')}.{$modx->escape('thread')} = {$modx->escape('disThread')}.{$modx->escape('id')}"));
     $cRead->prepare();
     $c->WHERE(array("{$modx->escape('disThread')}.{$modx->escape('id')} NOT IN ({$cRead->toSQL()})"));
     if (!$modx->discuss->user->isAdmin()) {
         $c->leftJoin('disBoardUserGroup', 'UserGroups', 'Board.id = UserGroups.board');
         if (!empty($groups)) {
             /* restrict boards by user group if applicable */
             $g = array('UserGroups.usergroup:IN' => $groups);
             $g['OR:UserGroups.usergroup:IS'] = null;
             $where[] = $g;
             $c->andCondition($where, null, 2);
         } else {
             $c->where(array('UserGroups.usergroup:IS' => null));
         }
     }
     $daysAgo = time() - $modx->getOption('discuss.new_replies_threshold', null, 14) * 24 * 60 * 60;
     $c->where(array('Board.status:>' => disBoard::STATUS_INACTIVE, 'author_last:!=' => $modx->discuss->user->get('id')));
     /* ignore spam/recycle bin boards */
     $spamBoard = $modx->getOption('discuss.spam_bucket_board', null, false);
     if (!empty($spamBoard)) {
         $c->where(array('Board.id:!=' => $spamBoard));
     }
     $trashBoard = $modx->getOption('discuss.recycle_bin_board', null, false);
     if (!empty($trashBoard)) {
         $c->where(array('Board.id:!=' => $trashBoard));
     }
     $response['total'] = $modx->getCount('disThread', $c);
     $c->select($modx->getSelectColumns('disThread', 'disThread'));
     $c->select(array('board_name' => "{$modx->escape('Board')}.{$modx->escape('name')}", 'thread' => "{$modx->escape('disThread')}.{$modx->escape('id')}", 'author_username' => 'LastAuthor.username', 'post_id' => "{$modx->escape('disThread')}.{$modx->escape('post_last')}", "FROM_UNIXTIME({$modx->escape('disThread')}.{$modx->escape('post_last_on')}) AS {$modx->escape('createdon')}", 'author' => "{$modx->escape('disThread')}.{$modx->escape('author_last')}", 'last_post_replies' => "{$modx->escape('disThread')}.{$modx->escape('replies')}"));
     $c->sortby($sortBy, $sortDir);
     $c->limit($limit, $start);
     if (!$countOnly) {
         $response['results'] = $modx->getCollection('disThread', $c);
     }
     return $response;
 }
 /**
  * Indicates if a previous version of the package is installed.
  *
  * @return boolean True if a previous version of the package is installed.
  */
 public function previousVersionInstalled()
 {
     $this->parseSignature();
     $count = $this->xpdo->getCount('transport.modTransportPackage', array(array("UCASE({$this->xpdo->escape('package_name')}) LIKE UCASE({$this->xpdo->quote($this->identifier)})"), 'installed:IS NOT' => null, 'signature:!=' => $this->get('signature')));
     return $count > 0;
 }