Example #1
0
 /**
  * Get a list of units for an offering
  *   Accepts either a numeric array index or a string [id, name]
  *   If index, it'll return the entry matching that index in the list
  *   If string, it'll return either a list of IDs or names
  *
  * @param      array   $filters Filters to build query from
  * @param      boolean $clear   Force a new dataset?
  * @return     mixed
  */
 public function members($filters = array(), $clear = false)
 {
     if (!isset($filters['section_id'])) {
         $filters['section_id'] = (int) $this->get('id');
     }
     if (isset($filters['count']) && $filters['count']) {
         $tbl = new Tables\Member($this->_db);
         return $tbl->count($filters);
     }
     if (!isset($this->_members) || !is_array($this->_members) || $clear) {
         $tbl = new Tables\Member($this->_db);
         $results = array();
         if ($data = $tbl->find($filters)) {
             foreach ($data as $key => $result) {
                 $results[$result->user_id] = new Member($result, $this->get('id'));
             }
         }
         $this->_members = $results;
     }
     return $this->_members;
 }
Example #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 = null, $role_id = 0)
 {
     $user_ids = $this->_userIds($data);
     $tbl = new Tables\Member($this->_db);
     $filters = array('course_id' => (int) $this->get('id'));
     foreach ($user_ids as $user_id) {
         $filters['user_id'] = $user_id;
         if ($data = $tbl->find($filters)) {
             $this->_managers[$user_id] = new Manager(array_shift($data), $this->get('id'));
             if (count($data) > 0) {
                 foreach ($data as $key => $result) {
                     $tbl->delete($result->id);
                     //$data[$key] = new Manager($result, $this->get('id'));
                     //$data[$key]->delete();
                 }
             }
         }
         if (!isset($this->_managers[$user_id])) {
             $this->_managers[$user_id] = new Manager($user_id, $this->get('id'));
         }
         $this->_managers[$user_id]->set('user_id', $user_id);
         $this->_managers[$user_id]->set('course_id', $this->get('id'));
         $this->_managers[$user_id]->set('role_id', $role_id);
         $this->_managers[$user_id]->set('section_id', 0);
         $this->_managers[$user_id]->set('student', 0);
         $this->_managers[$user_id]->set('offering_id', 0);
         $this->_managers[$user_id]->store();
     }
 }
Example #3
0
 /**
  * Get a list of memerships for a user
  *
  * @param      array   $filters Filters to build query from
  * @return     mixed
  */
 public function membership($user_id = 0)
 {
     $filters = array();
     if (!isset($filters['course_id'])) {
         $filters['course_id'] = (int) $this->get('course_id');
     }
     /*if (!isset($filters['offering_id']))
     		{
     			$filters['offering_id'] = (int) $this->get('id');
     		}*/
     if (!$user_id) {
         $user_id = User::get('id');
     }
     $filters['user_id'] = (int) $user_id;
     $filters['sort'] = 'offering_id ASC, student';
     $filters['sort_Dir'] = 'ASC';
     if (isset($filters['count']) && $filters['count']) {
         $tbl = new Tables\Member($this->_db);
         return $tbl->count($filters);
     }
     if (!isset($this->_membership[$user_id]) || !is_array($this->_membership[$user_id])) {
         $tbl = new Tables\Member($this->_db);
         $results = array();
         if ($results = $tbl->find($filters)) {
             foreach ($results as $key => $result) {
                 $mdl = '\\Components\\Courses\\Models\\Member';
                 if ($result->student) {
                     $mdl = '\\Components\\Courses\\Models\\Student';
                 } else {
                     $mdl = '\\Components\\Courses\\Models\\Manager';
                 }
                 $results[$key] = new $mdl($result);
             }
         }
         $this->_membership[$user_id] = $results;
     }
     return $this->_membership[$user_id];
 }
Example #4
0
 /**
  * Get a list of students
  *
  * @param   array   $filters Filters to build query from
  * @param   boolean $clear   Force a new dataset?
  * @return  mixed
  */
 public function students($filters = array(), $clear = false)
 {
     if (!isset($filters['course_id'])) {
         $filters['course_id'] = (int) $this->get('course_id');
     }
     if (!isset($filters['offering_id'])) {
         $filters['offering_id'] = (int) $this->get('offering_id');
     }
     if (!isset($filters['section_id'])) {
         $filters['section_id'] = (int) $this->get('section_id');
     }
     $filters['student'] = 1;
     if (isset($filters['count']) && $filters['count']) {
         $tbl = new Tables\Member($this->_db);
         return $tbl->count($filters);
     }
     if (!isset($this->_students) || !is_array($this->_students) || $clear) {
         $tbl = new Tables\Member($this->_db);
         $results = array();
         if ($data = $tbl->find($filters)) {
             foreach ($data as $key => $result) {
                 $results[$result->user_id] = new \Components\Courses\Models\Student($result, $this->get('id'));
             }
         }
         $this->_students = $results;
         //new \Components\Courses\Models\Iterator($results);
     }
     return $this->_students;
 }
Example #5
0
 /**
  * Save students info as CSV file
  *
  * @return  void
  */
 public function csvTask()
 {
     $this->view->filters = array('offering' => Request::getState($this->_option . '.' . $this->_controller . '.offering', 'offering', 0), 'section_id' => Request::getState($this->_option . '.' . $this->_controller . '.section', 'section', 0));
     $this->view->offering = \Components\Courses\Models\Offering::getInstance($this->view->filters['offering']);
     $this->view->filters['offering_id'] = $this->view->filters['offering'];
     $this->view->course = \Components\Courses\Models\Course::getInstance($this->view->offering->get('course_id'));
     if (!$this->view->filters['offering_id']) {
         $this->view->filters['offering_id'] = null;
     }
     if (!$this->view->filters['section_id']) {
         $this->view->filters['section_id'] = null;
     }
     $this->view->filters['student'] = 1;
     $tbl = new Tables\Member($this->database);
     $this->view->rows = $tbl->find($this->view->filters);
     //$this->view->offering->students($this->view->filters);
     if ($this->view->rows) {
         foreach ($this->view->rows as $key => $row) {
             $this->view->rows[$key] = new \Components\Courses\Models\Student($row);
         }
     }
     // Output the CSV
     $this->view->display();
 }