示例#1
0
 /**
  * Reorder entries
  *
  * @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\Unit($this->database);
     $row->load($uid);
     $row->move($inc, 'offering_id=' . $this->database->Quote($row->offering_id));
     $offering = \Components\Courses\Models\Offering::getInstance(Request::getInt('offering', 0));
     foreach ($offering->units() as $unit) {
         $unit->store();
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&offering=' . Request::getInt('offering', 0), false));
 }
示例#2
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      mixed $idx Index value
  * @return     array
  */
 public function units($filters = array(), $clear = false)
 {
     if (!isset($filters['offering_id'])) {
         $filters['offering_id'] = (int) $this->get('id');
     }
     if (!isset($filters['section_id'])) {
         $filters['section_id'] = (int) $this->section()->get('id');
     }
     if (isset($filters['count']) && $filters['count']) {
         $tbl = new Tables\Unit($this->_db);
         return $tbl->count($filters);
     }
     if (!$this->_units instanceof Iterator || $clear) {
         $tbl = new Tables\Unit($this->_db);
         if ($results = $tbl->find($filters)) {
             foreach ($results as $key => $result) {
                 if (!$result->section_id) {
                     $result->section_id = (int) $this->section()->get('id');
                 }
                 $results[$key] = new Unit($result);
             }
         } else {
             $results = array();
         }
         $this->_units = new Iterator($results);
     }
     return $this->_units;
 }