public static function get_list($name, $deep = false, $where = array(), $order_by = null, $order_by_dir = 'ASC', $limit_offset = null, $limit = null) { $obj = Bamboo::factory($name); $query = DB::select()->from($obj->_table); if ($deep) { call_user_func_array(array($query, 'select'), array_keys($obj->_fields)); } else { call_user_func_array(array($query, 'select'), array($obj->__id_field, $obj->__name_field)); } foreach ($where as $key => $value) { $query->where($key, '=', $value); } if ($order_by) { $query->order_by($order_by, $order_by_dir); } else { if ($obj->_sort_on) { $query->order_by($obj->_sort_on); } } if ($limit_offset !== null && $limit !== null) { $query->offset($limit_offset)->limit($limit); } $results = array(); $result = $query->execute($obj->_db); while ($row = $result->current()) { array_push($results, Bamboo::factory($name, $row)); $result->next(); } return $results; }
public function input($name, array $attr = NULL) { // TODO: cache? $relatedItems = Bamboo::get_list($this->model); $options = array(); foreach ($relatedItems as $relatedItem) { $options[$relatedItem->{$relatedItem->__id_field}->raw()] = $relatedItem->{$relatedItem->__name_field}->raw(); } return Form::select($name, $options, $this->value, $attr); }