/** * 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); } } } }
/** * 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; } } }
/** * Edit a role * * @return void */ public function editTask($row = null) { Request::setVar('hidemainmenu', 1); if (!is_object($row)) { // Incoming (expecting an array) $id = Request::getVar('id', array(0)); if (is_array($id)) { $id = !empty($id) ? $id[0] : 0; } // Load the object $row = new Tables\Role($this->database); $row->load($id); } $this->view->row = $row; if (!$this->view->row->id) { $this->view->row->created_by = User::get('id'); $this->view->row->created = Date::toSql(); } require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'courses.php'; $model = \Components\Courses\Models\Courses::getInstance(); $this->view->courses = $model->courses(); // Set any errors foreach ($this->getErrors() as $error) { \Notify::error($error); } // Output the HTML $this->view->setLayout('edit')->display(); }
/** * 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; } }