/** * Fetch all posts for this thread * * @param mixed $post A reference to a disPost or ID of disPost to start the posts from * @param array $options An array of options for sorting, limiting and display * @return array */ public function fetchPosts($post = false, array $options = array()) { $response = array(); $c = $this->xpdo->newQuery('disPost'); $c->innerJoin('disThread', 'Thread'); $c->where(array('thread' => $this->get('id'))); $response['total'] = $this->xpdo->discuss->controller->getPostCount('disThread', $this->get('id')); $flat = $this->xpdo->getOption('flat', $options, true); $limit = $this->xpdo->getOption('limit', $options, (int) $this->xpdo->getOption('discuss.post_per_page', $options, 10)); $start = $this->xpdo->getOption('start', $options, 0); if ($flat) { $sortBy = $this->xpdo->getOption('sortBy', $options, 'createdon'); $sortDir = $this->xpdo->getOption('sortDir', $options, 'ASC'); $c->sortby($this->xpdo->getSelectColumns('disPost', 'disPost', '', array($sortBy)), $sortDir); if (empty($_REQUEST['print'])) { $c->limit($limit, $start); } } else { $c->sortby($this->xpdo->getSelectColumns('disPost', 'disPost', '', array('rank')), 'ASC'); } if (!empty($post)) { if (!is_object($post)) { $post = $this->xpdo->getObject('disPost', $post); } if ($post) { $c->where(array('disPost.createdon:>=' => $post->get('createdon'))); } } $c->bindGraph('{"Author":{"PrimaryDiscussGroup":{},"PrimaryGroup":{}},"EditedBy":{}}'); //$c->prepare(); //$cacheKey = 'discuss/thread/'.$thread->get('id').'/'.md5($c->toSql()); $response['results'] = $this->xpdo->getCollectionGraph('disPost', '{"Author":{"PrimaryDiscussGroup":{},"PrimaryGroup":{}},"EditedBy":{}}', $c); return $response; }
/** * Gets all the User Group names of the groups this user belongs to. * * @access public * @return array An array of User Group names. */ public function getUserGroupNames() { $groupNames = array(); $id = $this->get('id') ? (string) $this->get('id') : '0'; if (isset($_SESSION["modx.user.{$id}.userGroupNames"]) && $this->xpdo->user->get('id') == $this->get('id')) { $groupNames = $_SESSION["modx.user.{$id}.userGroupNames"]; } else { $memberGroups = $this->xpdo->getCollectionGraph('modUserGroup', '{"UserGroupMembers":{}}', array('UserGroupMembers.member' => $this->get('id'))); if ($memberGroups) { /** @var modUserGroup $group */ foreach ($memberGroups as $group) { $groupNames[] = $group->get('name'); } } $_SESSION["modx.user.{$id}.userGroupNames"] = $groupNames; } return $groupNames; }
/** * Gets all the Resource Group names of the resource groups this resource is assigned to. * * @access public * @return array An array of Resource Group names. */ public function getResourceGroupNames() { $resourceGroupNames = array(); $resourceGroups = $this->xpdo->getCollectionGraph('modResourceGroup', '{"ResourceGroupResources":{}}', array('ResourceGroupResources.document' => $this->get('id'))); if ($resourceGroups) { /** @var modResourceGroup $resourceGroup */ foreach ($resourceGroups as $resourceGroup) { $resourceGroupNames[] = $resourceGroup->get('name'); } } return $resourceGroupNames; }