Example #1
0
 /**
  * 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();
 }
Example #2
0
 /**
  * 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'));
 }