/** * Reorder items * * @return string */ public function reorder() { // Check permission if (!$this->model->access('content')) { return $this->page(); } // AJAX // Incoming $newid = Request::getInt('newid', 0); $oldid = Request::getInt('oldid', 0); $items = Request::getVar('item', array()); if ($newid && $oldid) { $objTD1 = new \Components\Projects\Tables\Todo($this->_database); $objTD1->loadTodo($this->model->get('id'), $oldid); $objTD2 = new \Components\Projects\Tables\Todo($this->_database); $objTD2->loadTodo($this->model->get('id'), $newid); $priority1 = $objTD1->priority; $priority2 = $objTD2->priority; $objTD2->priority = $priority1; $objTD1->priority = $priority2; $objTD1->store(); $objTD2->store(); } elseif (!empty($items)) { $o = 1; foreach ($items as $item) { $objTD = new \Components\Projects\Tables\Todo($this->_database); $objTD->loadTodo($this->model->get('id'), $item); $objTD->priority = $o; $objTD->store(); $o++; } } // Go back to todo list return $this->page(); }
/** * 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; }
/** * Save item * * @return string */ protected function _save() { if (User::isGuest()) { $this->setError(Lang::txt('MEMBERS_LOGIN_NOTICE')); return; } if (User::get('id') != $this->member->get('id')) { $this->setError(Lang::txt('PLG_MEMBERS_TODO_NOT_AUTHORIZED')); return $this->_browse(); } // Check for request forgeries Request::checkToken(); // Incoming $content = Request::getVar('content', ''); $projectid = Request::getInt('projectid', 0); $due = trim(Request::getVar('due', '')); $model = new \Components\Projects\Models\Project($projectid); if (!$content) { $this->setError(Lang::txt('PLG_MEMBERS_TODO_ERROR_PROVIDE_CONTENT')); return $this->_browse(); } if (!$model->exists() || !$model->access('content')) { $this->setError(Lang::txt('PLG_MEMBERS_TODO_ERROR_ACCESS_PROJECT')); return $this->_browse(); } // Initiate extended database class $objTD = new \Components\Projects\Tables\Todo($this->database); $content = rtrim(stripslashes($content)); $objTD->content = $content ? $content : $objTD->content; $objTD->content = \Hubzero\Utility\Sanitize::stripAll($objTD->content); $objTD->created_by = $this->member->get('id'); $objTD->created = Date::toSql(); $objTD->projectid = $model->get('id'); if (strlen($objTD->content) > 255) { $objTD->details = $objTD->content; } $objTD->content = \Hubzero\Utility\String::truncate($objTD->content, 255); if ($due && $due != 'mm/dd/yyyy') { $date = explode('/', $due); if (count($date) == 3) { $month = $date[0]; $day = $date[1]; $year = $date[2]; if (intval($month) && intval($day) && intval($year)) { if (strlen($day) == 1) { $day = '0' . $day; } if (strlen($month) == 1) { $month = '0' . $month; } if (checkdate($month, $day, $year)) { $objTD->duedate = Date::of(mktime(0, 0, 0, $month, $day, $year))->toSql(); } } } } else { $objTD->duedate = ''; } // Get last order $lastorder = $objTD->getLastOrder($model->get('id')); $objTD->priority = $lastorder ? $lastorder + 1 : 1; // Store content if (!$objTD->store()) { $this->setError($objTD->getError()); return $this->_browse(); } else { // Record activity $aid = $model->recordActivity(Lang::txt('PLG_MEMBERS_TODO_ACTIVITY_TODO_ADDED'), $objTD->id, 'to do', Route::url('index.php?option=com_projects&alias=' . $model->get('alias') . '&active=todo&action=view&todoid=' . $objTD->id), 'todo', 1); // Store activity ID if ($aid) { $objTD->activityid = $aid; $objTD->store(); } } App::redirect(Route::url($this->member->link() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_TODO_SAVED')); }