Exemple #1
0
 /**
  * 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;
 }