/** * Get a list or count of comments * * @param string $rtrn Data format to return * @param array $filters Filters to apply to data fetch * @param boolean $clear Clear cached data? * @return mixed */ public function comments($rtrn = 'list', $filters = array(), $clear = false) { $tbl = new \Components\Projects\Tables\Comment($this->_db); switch (strtolower($rtrn)) { case 'count': if (!isset($this->_comments_count) || !is_numeric($this->_comments_count) || $clear) { $this->_comments_count = 0; if (!$this->_comments) { $c = $this->comments('list', $filters); } foreach ($this->_comments as $com) { $this->_comments_count++; } } return $this->_comments_count; break; case 'list': case 'results': default: if (!$this->_comments instanceof \Hubzero\Base\ItemList || $clear) { if ($results = $tbl->getComments($this->get('id'), 'todo')) { foreach ($results as $key => $result) { $results[$key] = new Comment($result); $results[$key]->set('option', 'com_projects'); $results[$key]->set('scope', ''); $results[$key]->set('alias', ''); $results[$key]->set('path', ''); } } else { $results = array(); } $this->_comments = new \Hubzero\Base\ItemList($results); } return $this->_comments; break; } }
/** * Collect activity data * * @param array $activities * @param array $filters Query filters * @param integer $limit Number of entries * @return array */ protected function _prepActivities($activities, $filters, $limit) { $objAC = $this->model->table('Activity'); // Instantiate some classes $objM = new \Components\Projects\Tables\Blog($this->_database); $objC = new \Components\Projects\Tables\Comment($this->_database); $objTD = new \Components\Projects\Tables\Todo($this->_database); // Collectors $shown = array(); $newc = array(); $skipped = array(); $prep = array(); // Loop through activities if (is_array($activities) && count($activities) > 0) { foreach ($activities as $a) { // Is this a comment? if ($a->class == 'quote') { // Get comment $c = $objC->getComments(NULL, NULL, $a->id); if (!$c) { continue; } // Bring up commented item $needle = array('id' => $c->parent_activity); $key = \Components\Projects\Helpers\Html::myArraySearch($needle, $activities); $shown[] = $a->id; if (!$key) { // get and add parent activity $filters['id'] = $c->parent_activity; $pa = $objAC->getActivities($a->projectid, $filters, 0, $this->_uid); if ($pa && count($pa) > 0) { $a = $pa[0]; } } else { $a = $activities[$key]; } $a->new = isset($c->newcount) ? $c->newcount : 0; } if (!in_array($a->id, $shown)) { $shown[] = $a->id; $class = $a->class ? $a->class : 'activity'; // Display hyperlink if ($a->highlighted && $a->url) { $a->activity = str_replace($a->highlighted, '<a href="' . $a->url . '">' . $a->highlighted . '</a>', $a->activity); } // Set vars $ebody = ''; $eid = $a->id; $etbl = 'activity'; $deletable = 0; // Get blog entry if ($class == 'blog') { $blog = $objM->getEntries($a->projectid, $bfilters = array('activityid' => $a->id), $a->referenceid); if (!$blog) { continue; } $ebody = $this->drawBodyText($blog[0]->blogentry); $eid = $a->referenceid; $etbl = 'blog'; $deletable = 1; } elseif ($class == 'todo') { $todo = $objTD->getTodos($a->projectid, $tfilters = array('activityid' => $a->id), $a->referenceid); if (!$todo) { continue; } $content = $todo[0]->details ? $todo[0]->details : $todo[0]->content; $ebody = $this->drawBodyText($content); $eid = $a->referenceid; $etbl = 'todo'; } // Get/parse & save item preview if available $preview = empty($this->miniView) ? $this->getItemPreview($class, $a) : ''; // Get comments if ($a->commentable) { $comments = $objC->getComments($eid, $etbl); } else { $comments = null; } // Is user allowed to delete item? $deletable = empty($this->miniView) && $deletable && $this->model->access('content') && ($a->userid == $this->_uid or $this->model->access('manager')) ? 1 : 0; $prep[] = array('activity' => $a, 'eid' => $eid, 'etbl' => $etbl, 'body' => $ebody, 'deletable' => $deletable, 'comments' => $comments, 'class' => $class, 'preview' => $preview); } } } return $prep; }