Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * @param array $list
  * @return array
  */
 public function beforeIteration(array $list)
 {
     $canApprove = $this->modx->hasPermission('quip.comment_approve');
     $canRemove = $this->modx->hasPermission('quip.comment_remove');
     $canUpdate = $this->modx->hasPermission('quip.comment_update');
     if ($this->thread) {
         $canApprove = $canApprove && $this->thread->checkPolicy('comment_approve');
         $canRemove = $canRemove && $this->thread->checkPolicy('comment_remove');
         $canUpdate = $canUpdate && $this->thread->checkPolicy('comment_update');
     }
     $cls = array();
     if ($canApprove) {
         $cls[] = 'papprove';
     }
     if ($canUpdate) {
         $cls[] = 'pupdate';
     }
     if ($canRemove) {
         $cls[] = 'premove';
     }
     $this->defaultCls = implode(',', $cls);
     return $list;
 }
Ejemplo n.º 5
0
 public function tearDown()
 {
     parent::tearDown();
     $this->thread->remove();
     $this->resource->remove();
 }
Ejemplo n.º 6
0
 public function process()
 {
     return $this->thread->truncate() ? $this->success() : $this->failure('quip.thread_err_truncate');
 }