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) { /* 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 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 ); }
/** * Gets a count of {@link modUserMessage} objects ascribed to the user. * * @access public * @param mixed $read * @return integer The number of messages. */ public function countMessages($read = '') { if ($read == 'read') { $read = 1; } elseif ($read == 'unread') { $read = 0; } $criteria = array('recipient' => $this->get('id')); if ($read) { $criteria['messageread'] = $read; } return $this->xpdo->getCount('modUserMessage', $criteria); }
/** * @param sTaskRun $run * @return mixed */ public function _run(&$run) { $snippet = $this->get('content'); $scriptProperties = (array) $run->get('data'); $scriptProperties['task'] =& $this; $scriptProperties['run'] =& $run; // Check if the snippet exists before running it. // This may fail with OnElementNotFound snippets in 2.3 $key = !empty($snippet) && is_numeric($snippet) ? 'id' : 'name'; if ($this->xpdo->getCount('modSnippet', array($key => $snippet)) < 1) { $run->addError('snippet_not_found', array('snippet' => $snippet)); return false; } /** @var modSnippet $snippet */ $snippet = $this->xpdo->getObject('modSnippet', array($key => $snippet)); if (empty($snippet) || !is_object($snippet)) { $run->addError('snippet_not_found', array('snippet' => $snippet)); return false; } $snippet->setCacheable(false); $out = $snippet->process($scriptProperties); unset($scriptProperties, $snippet); return $out; }
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)); }
/** * 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; }
/** * 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; }
/** * Mark all posts in this thread as read * @static * @param xPDO $modx * @param string $type * @return bool */ public static function readAll(xPDO &$modx, $type = 'message') { $userId = $modx->discuss->user->get('id'); $sql = 'SELECT `disThread`.`id` FROM ' . $modx->getTableName('disThread') . ' `disThread` INNER JOIN ' . $modx->getTableName('disThreadUser') . ' `ThreadUser` ON `ThreadUser`.`thread` = `disThread`.`id` LEFT JOIN ' . $modx->getTableName('disThreadRead') . ' `ThreadRead` ON `ThreadRead`.`thread` = `disThread`.`id` WHERE `ThreadUser`.`user` = ' . $userId . ' AND `ThreadRead`.`id` IS NULL AND `private` = 1 ORDER BY `disThread`.`id` DESC'; $stmt = $modx->query($sql); if (!$stmt) { return false; } while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $read = $modx->getCount('disThreadRead', array('thread' => $row['id'], 'user' => $userId)); if ($read == 0) { $read = $modx->newObject('disThreadRead'); $read->fromArray(array('thread' => $row['id'], 'board' => 0, 'user' => $userId)); $read->save(); } } $stmt->closeCursor(); return true; }
/** * 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; }