Esempio n. 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      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;
 }