/** * 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; } } }
/** * 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; } }