Esempio n. 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;
 }
Esempio n. 2
0
 /**
  * Delete item
  *
  * @return	   string
  */
 public function delete()
 {
     // Check permission
     if (!$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Incoming
     $todoid = $this->_todoid;
     $list = Request::getVar('dl', '');
     $gobacklist = '';
     // Load todo
     $objTD = new \Components\Projects\Tables\Todo($this->_database);
     if ($todoid && $objTD->loadTodo($this->model->get('id'), $todoid)) {
         // Get associated commenting activities
         $objC = new \Components\Projects\Tables\Comment($this->_database);
         $activities = $objC->collectActivities($todoid, "todo");
         $activities[] = $objTD->activityid;
         // Store list name (for redirect)
         $gobacklist = $objTD->color;
         // Delete todo
         if (!$objTD->deleteTodo($this->model->get('id'), $todoid)) {
             $this->setError(Lang::txt('PLG_PROJECTS_TODO_TODO_DELETED_ERROR'));
         } else {
             // Delete all associated comments
             $comments = $objC->deleteComments($todoid, "todo");
             // Delete all associated activities
             foreach ($activities as $a) {
                 $objAA = $this->model->table('Activity');
                 $objAA->loadActivity($a, $this->model->get('id'));
                 $objAA->deleteActivity();
             }
             $this->_msg = Lang::txt('PLG_PROJECTS_TODO_TODO_DELETED');
         }
     } elseif ($list && $objTD->getListName($this->model->get('id'), $list)) {
         // Are we deleting a list?
         $deleteall = Request::getInt('all', 0);
         if ($deleteall) {
             // Get all to-do's on list
             $todos = $objTD->getTodos($this->model->get('id'), $filters = array('todolist' => $list));
             if (count($todos) > 0) {
                 foreach ($todos as $todo) {
                     if ($objTD->loadTodo($this->model->get('id'), $todo->id)) {
                         // Get associated commenting activities
                         $objC = new \Components\Projects\Tables\Comment($this->_database);
                         $activities = $objC->collectActivities($todo->id, "todo");
                         $activities[] = $objTD->activityid;
                         // Delete todo
                         if ($objTD->deleteTodo($this->model->get('id'), $todo->id)) {
                             // Delete all associated comments
                             $comments = $objC->deleteComments($todo->id, "todo");
                             // Delete all associated activities
                             foreach ($activities as $a) {
                                 $objAA = new \Components\Projects\Tables\Activity($this->_database);
                                 $objAA->loadActivity($a, $this->model->get('id'));
                                 $objAA->deleteActivity();
                             }
                         }
                     }
                 }
             }
         }
         // Clean-up colored items
         $objTD->deleteList($this->model->get('id'), $list);
         $this->_msg = Lang::txt('PLG_PROJECTS_TODO_TODO_LIST_DELETED');
     }
     // Pass error or success message
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error', 'projects');
     } elseif (!empty($this->_msg)) {
         \Notify::message($this->_msg, 'success', 'projects');
     }
     // Redirect back to todo list
     $url = Route::url($this->model->link('todo'));
     $url .= $gobacklist ? '?list=' . $gobacklist : '';
     App::redirect($url);
     return;
 }