/** * Gets the current thread * * @static * @param modX $modx * @param quipThread $thread * @param int $parent * @param string $ids * @param string $sortBy * @param string $sortByAlias * @param string $sortDir * @return array */ public static function getThread(modX $modx, quipThread $thread, $parent = 0, $ids = '', $sortBy = 'rank', $sortByAlias = 'quipComment', $sortDir = 'ASC') { $c = $modx->newQuery('quipComment'); $c->innerJoin('quipThread', 'Thread'); $c->leftJoin('quipCommentClosure', 'Descendants'); $c->leftJoin('quipCommentClosure', 'RootDescendant', 'RootDescendant.descendant = quipComment.id AND RootDescendant.ancestor = 0'); $c->leftJoin('quipCommentClosure', 'Ancestors'); $c->leftJoin('modUser', 'Author'); $c->leftJoin('modResource', 'Resource'); $c->where(array('quipComment.thread' => $thread->get('name'), 'quipComment.deleted' => false)); if (!$thread->checkPolicy('moderate')) { $c->andCondition(array('quipComment.approved' => true), null, 2); } if (!empty($parent)) { $c->where(array('Descendants.ancestor' => $parent)); } $total = $modx->getCount('quipComment', $c); if (!empty($ids)) { $c->where(array('Descendants.ancestor:IN' => $ids)); } $c->select($modx->getSelectColumns('quipComment', 'quipComment')); $c->select(array('Thread.resource', 'Thread.idprefix', 'Thread.existing_params', 'RootDescendant.depth', 'Author.username', 'Resource.pagetitle', 'Resource.context_key')); $c->sortby($modx->escape($sortByAlias) . '.' . $modx->escape($sortBy), $sortDir); $comments = $modx->getCollection('quipComment', $c); return array('results' => $comments, 'total' => $total); }
/** * Prepare a list of Comment ids for pagination * @return array */ public function preparePaginationIds() { /* if pagination is on, get IDs of root comments so can limit properly */ $this->ids = array(); $limit = $this->getProperty('limit', 0); if (!empty($limit)) { $c = $this->modx->newQuery('quipComment'); $c->select($this->modx->getSelectColumns('quipComment', 'quipComment', '', array('id'))); $c->where(array('quipComment.thread' => $this->thread->get('name'), 'quipComment.deleted' => false, 'quipComment.parent' => 0)); if (!$this->thread->checkPolicy('moderate')) { $c->where(array('quipComment.approved' => true, 'OR:quipComment.author:=' => $this->modx->user->get('id'))); } $c->sortby($this->getProperty('sortByAlias', 'quipComment') . '.' . $this->getProperty('sortBy', 'rank'), $this->getProperty('sortDir', 'ASC')); $this->setPlaceholder('rootTotal', $this->modx->getCount('quipComment', $c)); $c->limit($limit, $this->getProperty('start', 0)); $comments = $this->modx->getCollection('quipComment', $c); $this->ids = array(); /** @var quipComment $comment */ foreach ($comments as $comment) { $this->ids[] = $comment->get('id'); } $this->ids = array_unique($this->ids); } return $this->ids; }
/** * @param xPDOQuery $c * @return xPDOQuery */ public function prepareQueryBeforeCount(xPDOQuery $c) { $c->leftJoin('modUser', 'Author'); $c->leftJoin('modResource', 'Resource'); $thread = $this->getProperty('thread'); if (!empty($thread)) { $c->where(array('quipComment.thread' => $this->thread->get('name'))); } $family = $this->getProperty('family'); if (!empty($family)) { $c->where(array('quipComment.thread:LIKE' => '%' . $family . '%')); } $c->where(array('quipComment.deleted' => $this->getProperty('deleted'))); $search = $this->getProperty('search'); if ($search) { $c->where(array('quipComment.body:LIKE' => '%' . $search . '%', 'OR:quipComment.author:LIKE' => '%' . $search . '%', 'OR:quipComment.name:LIKE' => '%' . $search . '%'), null, 2); } return $c; }
/** * Handle if the user is unsubscribing from this thread * @return boolean */ public function checkForUnSubscribe() { $unSubscribed = false; if (!empty($_GET[$this->getProperty('unsubscribeAction')]) && $this->modx->user->hasSessionContext($this->modx->context->get('key'))) { $profile = $this->modx->user->getOne('Profile'); if ($profile) { /** @var quipCommentNotify $notify */ $notify = $this->modx->getObject('quipCommentNotify', array('email' => $profile->get('email'), 'thread' => $this->thread->get('name'))); if ($notify && $notify->remove()) { $unSubscribed = true; $this->setPlaceholder('successMsg', $this->modx->lexicon('quip.unsubscribed')); } } } return $unSubscribed; }