Exemplo n.º 1
0
 /**
  * Set the state of an entry
  *
  * @return  void
  */
 public function stateTask()
 {
     $state = $this->_task == 'publish' ? 1 : 0;
     // Incoming
     $ids = Request::getVar('id', array(0));
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Check for an ID
     if (count($ids) < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&unit=' . Request::getInt('unit', 0), false), $state == 1 ? Lang::txt('COM_COURSES_SELECT_PUBLISH') : Lang::txt('COM_COURSES_SELECT_UNPUBLISH'), 'error');
         return;
     }
     // Update record(s)
     foreach ($ids as $id) {
         // Updating a category
         $row = new \Components\Courses\Models\Assetgroup($id);
         $row->set('state', $state);
         $row->store();
     }
     // Set message
     switch ($state) {
         case '-1':
             $message = Lang::txt('COM_COURSES_ARCHIVED', count($ids));
             break;
         case '1':
             $message = Lang::txt('COM_COURSES_PUBLISHED', count($ids));
             break;
         case '0':
             $message = Lang::txt('COM_COURSES_UNPUBLISHED', count($ids));
             break;
     }
     // Set the redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&unit=' . Request::getInt('unit', 0), false), $message);
 }
Exemplo n.º 2
0
 /**
  * Saves data to the database
  *
  * @param     $redirect boolean Redirect after saving?
  * @return    void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $fields = Request::getVar('fields', array(), 'post');
     // Instantiate a Course object
     $model = \Components\Courses\Models\Unit::getInstance($fields['id']);
     if (!$model->bind($fields)) {
         $this->setError($model->getError());
         $this->editTask($model);
         return;
     }
     if (!$model->store(true)) {
         $this->setError($model->getError());
         $this->editTask($model);
         return;
     }
     if ($model->get('id') && $model->assetgroups()->total() <= 0) {
         $asset_groups = explode(',', $this->config->get('default_asset_groups', 'Lectures, Homework, Exam'));
         array_map('trim', $asset_groups);
         foreach ($asset_groups as $key) {
             // Get our asset group object
             $assetGroup = new \Components\Courses\Models\Assetgroup(null);
             $assetGroup->set('title', $key);
             $assetGroup->set('unit_id', $model->get('id'));
             $assetGroup->set('parent', 0);
             // Save the asset group
             if (!$assetGroup->store(true)) {
                 $this->setError($model->getError());
             }
         }
     }
     if ($this->_task == 'apply') {
         return $this->editTask($model);
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&offering=' . Request::getInt('offering', 0), false), Lang::txt('COM_COURSES_ITEM_SAVED'));
 }