示例#1
0
 /**
  * Reorder a plugin
  *
  * @param      integer $access Access level to set
  * @return     void
  */
 public function orderTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $id = Request::getVar('id', array(0), 'post', 'array');
     \Hubzero\Utility\Arr::toInteger($id, array(0));
     $uid = $id[0];
     $inc = $this->_task == 'orderup' ? -1 : 1;
     $row = new Tables\Assetgroup($this->database);
     $row->load($uid);
     $row->move($inc, 'unit_id=' . $this->database->Quote($row->unit_id) . ' AND parent=' . $this->database->Quote($row->parent));
     $row->reorder('unit_id=' . $this->database->Quote($row->unit_id) . ' AND parent=' . $this->database->Quote($row->parent));
     //$unit = \Components\Courses\Models\Unit::getInstance(Request::getInt('unit', 0));
     //$ags = $unit->assetgroups(null, array('parent' => $row->parent));
     if ($ags = $row->find(array('w' => array('parent' => $row->parent, 'unit_id' => $row->unit_id)))) {
         foreach ($ags as $ag) {
             $a = new \Components\Courses\Models\Assetgroup($ag);
             $a->store();
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&unit=' . Request::getInt('unit', 0), false));
 }
示例#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'));
 }