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) ); }
public static function listProfiles(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { $objCollection= array (); /* query for profiles */ $c = $xpdo->newQuery('modFormCustomizationProfile'); $c->select(array( $xpdo->getSelectColumns('modFormCustomizationProfile','modFormCustomizationProfile'), )); $c->where($criteria,null,2);// also log issue in remine to look at this usage of where() $count = $xpdo->getCount('modFormCustomizationProfile',$c); foreach($sort as $field=> $dir) { $c->sortby($xpdo->getSelectColumns('modFormCustomizationProfile','modFormCustomizationProfile','',array($field)),$dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } $rows= xPDOObject :: _loadRows($xpdo, 'modFormCustomizationProfile', $c); $rowsArray = $rows->fetchAll(PDO::FETCH_ASSOC); $rows->closeCursor(); foreach($rowsArray as $row) { $objCollection[] = $xpdo->call('modFormCustomizationProfile', '_loadInstance', array(&$xpdo, 'modFormCustomizationProfile', $c, $row)); } unset($row, $rowsArray); return array( 'count'=> $count, 'collection'=> $objCollection ); }
public static function loadOptions(xPDO &$xpdo, $product) { $c = $xpdo->newQuery('msProductOption'); $c->rightJoin('msOption', 'msOption', 'msProductOption.key=msOption.key'); $c->leftJoin('modCategory', 'Category', 'Category.id=msOption.category'); $c->where(array('msProductOption.product_id' => $product)); $c->select($xpdo->getSelectColumns('msOption', 'msOption')); $c->select($xpdo->getSelectColumns('msProductOption', 'msProductOption', '', array('key'), true)); $c->select('`Category`.`category` AS `category_name`'); $data = array(); $tstart = microtime(true); if ($c->prepare() && $c->stmt->execute()) { $xpdo->queryTime += microtime(true) - $tstart; $xpdo->executedQueries++; while ($option = $c->stmt->fetch(PDO::FETCH_ASSOC)) { if (isset($data[$option['key']])) { // если опция повторяется, ее значение будет массивом if (!is_array($data[$option['key']])) { $data[$option['key']] = array($data[$option['key']]); } $data[$option['key']][] = $option['value']; } else { // одиночная опция останется строкой $data[$option['key']] = $option['value']; } foreach ($option as $key => $value) { $data[$option['key'] . '.' . $key] = $value; } } } return $data; }
public static function listProfiles(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { /* query for profiles */ $c = $xpdo->newQuery('modFormCustomizationProfile'); $c->select(array( 'modFormCustomizationProfile.*', )); $c->select(' (SELECT GROUP_CONCAT(UserGroup.name) FROM '.$xpdo->getTableName('modUserGroup').' AS UserGroup INNER JOIN '.$xpdo->getTableName('modFormCustomizationProfileUserGroup').' AS fcpug ON fcpug.usergroup = UserGroup.id WHERE fcpug.profile = modFormCustomizationProfile.id ) AS usergroups '); $c->where($criteria,null,2);// also log issue in remine to look at this usage of where() $count = $xpdo->getCount('modFormCustomizationProfile',$c); foreach($sort as $field=> $dir) { $c->sortby($xpdo->getSelectColumns('modFormCustomizationProfile','modFormCustomizationProfile','',array($field)),$dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } return array( 'count'=> $count, 'collection'=> $xpdo->getCollection('modFormCustomizationProfile',$c) ); }
public static function listEvents(xPDO &$xpdo, $plugin, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { $c = $xpdo->newQuery('modEvent'); $count = $xpdo->getCount('modEvent',$c); $c->select(array( 'modEvent.*', 'IF(ISNULL(modPluginEvent.pluginid),0,1) AS enabled', 'modPluginEvent.priority AS priority', 'modPluginEvent.propertyset AS propertyset', )); $c->leftJoin('modPluginEvent','modPluginEvent',' modPluginEvent.event = modEvent.name AND modPluginEvent.pluginid = '.$plugin.' '); $c->where($criteria); foreach($sort as $field=> $dir) { $c->sortby($xpdo->getSelectColumns('modEvent','modEvent','',array($field)),$dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } return array( 'count'=> $count, 'collection'=> $xpdo->getCollection('modEvent',$c) ); }
public static function listSettings(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { $c = $xpdo->newQuery('modUserGroupSetting'); $c->select(array($xpdo->getSelectColumns('modUserGroupSetting', 'modUserGroupSetting'), 'Entry.value AS name_trans', 'Description.value AS description_trans')); $c->leftJoin('modLexiconEntry', 'Entry', "'setting_' + modUserGroupSetting.[key] = Entry.name"); $c->leftJoin('modLexiconEntry', 'Description', "'setting_' + modUserGroupSetting.[key] + '_desc' = Description.name"); $c->where($criteria); $count = $xpdo->getCount('modUserGroupSetting', $c); $c->sortby($xpdo->getSelectColumns('modUserGroupSetting', 'modUserGroupSetting', '', array('area')), 'ASC'); foreach ($sort as $field => $dir) { $c->sortby($xpdo->getSelectColumns('modUserGroupSetting', 'modUserGroupSetting', '', array($field)), $dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } return array('count' => $count, 'collection' => $xpdo->getCollection('modUserGroupSetting', $c)); }
/** * Grabs all descendants of this post. * * @access public * @param int $depth If set, will limit to specified depth * @return array A collection of quipComment objects. */ public function getDescendants($depth = 0) { $c = $this->xpdo->newQuery('quipComment'); $c->select($this->xpdo->getSelectColumns('quipComment', 'quipComment')); $c->select(array('Descendants.depth')); $c->innerJoin('quipCommentClosure', 'Descendants'); $c->innerJoin('quipCommentClosure', 'Ancestors'); $c->where(array('Descendants.ancestor' => $this->get('id'))); if ($depth) { $c->where(array('Descendants.depth:<=' => $depth)); } $c->sortby('quipComment.rank', 'ASC'); return $this->xpdo->getCollection('quipComment', $c); }
/** * Fetch a full list of boards for the forum with restrictions based on current user * * @static * @param xPDO $modx * @param bool $ignoreBoards * @return array */ public static function fetchList(xPDO &$modx, $ignoreBoards = true) { $c = array('ignore_boards' => $ignoreBoards); $cacheKey = 'discuss/board/user/' . $modx->discuss->user->get('id') . '/select-options-' . md5(serialize($c)); $boards = $modx->cacheManager->get($cacheKey); if (empty($boards)) { $c = $modx->newQuery('disBoard'); $c->innerJoin('disBoardClosure', 'Descendants'); $c->leftJoin('disBoardUserGroup', 'UserGroups'); $c->innerJoin('disCategory', 'Category'); $groups = $modx->discuss->user->getUserGroups(); if (!$modx->discuss->user->isAdmin()) { 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)); } } if ($modx->discuss->user->isLoggedIn && $ignoreBoards) { $ignoreBoards = $modx->discuss->user->get('ignore_boards'); if (!empty($ignoreBoards)) { $c->where(array('id:NOT IN' => explode(',', $ignoreBoards))); } } $c->select($modx->getSelectColumns('disBoard', 'disBoard')); $c->select(array('Descendants.depth AS depth', 'Category.name AS category_name')); $c->where(array('Descendants.ancestor' => 0)); $c->sortby('Category.rank', 'ASC'); $c->sortby('disBoard.map', 'ASC'); $c->groupby('disBoard.id'); $boardObjects = $modx->getCollection('disBoard', $c); /** @var disBoard $board */ foreach ($boardObjects as $board) { $boards[] = $board->toArray('', false, true); } if (!empty($boards)) { $modx->cacheManager->set($cacheKey, $boards, $modx->getOption('discuss.cache_time', null, 3600)); } } return $boards; }
/** * Fetch a list of active users in the forum * * @static * @param xPDO $modx A reference to the modX object * @param int $timeAgo If set, will grab within X seconds * @param int $limit Limit results to this number * @param int $start Start at this index * @return array A response array of active users */ public static function fetchActive(xPDO &$modx, $timeAgo = 0, $limit = 0, $start = 0) { $response = array(); $c = $modx->newQuery('disUser'); $c->innerJoin('disSession', 'Session', $modx->getSelectColumns('disSession', 'Session', '', array('user')) . ' = ' . $modx->getSelectColumns('disUser', 'disUser', '', array('id'))); $c->innerJoin('modUser', 'User'); $c->leftJoin('disUserGroupProfile', 'PrimaryDiscussGroup'); if (!empty($timeAgo)) { $c->where(array('Session.access:>=' => $timeAgo)); } if (!empty($limit)) { $c->limit($limit, $start); } $response['total'] = $modx->getCount('disUser', $c); $c->select(array('disUser.id', 'disUser.username', 'PrimaryDiscussGroup.color')); $c->groupby('disUser.id'); $c->sortby('Session.access', 'ASC'); $response['results'] = $modx->getCollection('disUser', $c); return $response; }
/** * 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; }