Exemple #1
0
 /**
  * Constructor
  *
  * @param   string $uid User ID
  * @param   string $cid Course ID
  * @param   string $oid Offering ID
  * @param   string $sid Section ID
  * @return  void
  */
 public function __construct($uid, $cid = 0, $oid = 0, $sid = 0)
 {
     $this->_db = \App::get('db');
     $this->_tbl = new Tables\Member($this->_db);
     if (is_numeric($uid) || is_string($uid)) {
         $this->_tbl->load($uid, $cid, $oid, $sid, 0);
     } else {
         if (is_object($uid) || is_array($uid)) {
             $this->bind($uid);
         }
     }
     if (!$this->get('role_permissions')) {
         $result = new Tables\Role($this->_db);
         if ($result->load($this->get('role_id'))) {
             foreach ($result->getProperties() as $key => $property) {
                 $this->_tbl->set('__role_' . $key, $property);
             }
         }
     }
 }
Exemple #2
0
 /**
  * Add one or more user IDs or usernames to the managers list
  *
  * @param     array $value List of IDs or usernames
  * @return    void
  */
 public function add($data = array(), $role_id = 'student')
 {
     if (!is_array($data)) {
         $data = array($data);
     }
     $role = new Tables\Role($this->_db);
     $role->load($role_id);
     if (is_string($role_id)) {
         $role_id = $role->get('id');
     }
     if (!$this->get('course_id')) {
         require_once __DIR__ . DS . 'offering.php';
         $offering = Offering::getInstance($this->get('offering_id'));
         $this->set('course_id', $offering->get('course_id'));
     }
     foreach ($data as $result) {
         $user_id = (int) $this->_userId($result);
         // Create the entry
         $model = Member::getInstance($user_id, $this->get('course_id'), $this->get('offering_id'), $this->get('id'));
         $model->set('user_id', $user_id);
         $model->set('course_id', $this->get('course_id'));
         $model->set('offering_id', $this->get('offering_id'));
         $model->set('section_id', $this->get('id'));
         $model->set('role_id', $role_id);
         if ($role->get('alias') == 'student') {
             $model->set('student', 1);
         }
         if (!$model->store()) {
             $this->setError($model->getError());
             continue;
         }
         // Append to the members list
         if (isset($this->_members) && is_array($this->_members)) {
             $this->_members[$user_id] = $model;
         }
     }
 }
Exemple #3
0
 /**
  * Remove one or more types
  *
  * @return  void  Redirects back to main listing
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming (expecting an array)
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Ensure we have an ID to work with
     if (empty($ids)) {
         // Redirect with error message
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_COURSES_ERROR_NO_ENTRIES_SELECTED'), 'error');
         return;
     }
     $rt = new Tables\Role($this->database);
     foreach ($ids as $id) {
         // Delete the type
         $rt->delete($id);
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_COURSES_ITEMS_REMOVED', count($ids)));
 }
 /**
  * Add one or more user IDs or usernames to the managers list
  *
  * @param     array $value List of IDs or usernames
  * @return    void
  */
 public function add($data = array(), $role_id = 'student')
 {
     if (!is_array($data)) {
         $data = array($data);
     }
     $role = new Tables\Role($this->_db);
     $role->load($role_id);
     if (is_string($role_id)) {
         $role_id = $role->get('id');
     }
     foreach ($data as $result) {
         $user_id = (int) $this->_userId($result);
         $model = Member::getInstance($user_id, $this->get('course_id'), $this->get('id'), $this->section()->get('id'));
         $model->set('user_id', $user_id);
         $model->set('course_id', $this->get('course_id'));
         $model->set('offering_id', $this->get('id'));
         $model->set('section_id', $this->section()->get('id'));
         $model->set('role_id', $role_id);
         if ($role->get('alias') == 'student') {
             $model->set('student', 1);
         }
         if (!$model->store()) {
             $this->setError($model->getError());
             continue;
         }
         $this->_managers[$user_id] = $model;
     }
 }