예제 #1
0
파일: Builder.php 프로젝트: Konro1/pms
 /**
  * Convert a column to a `table`.`column` using the appropriate model info
  * @param  string $column
  * @param  string $model
  * @param  mixed $value
  * @return string
  */
 public static function resolve_attribute_name($column, $model = NULL, $value = NULL)
 {
     if (is_array($column)) {
         list($column, $alias) = $column;
     }
     if (!$column instanceof Database_Expression and $column !== '*') {
         if (strpos($column, '.') !== FALSE) {
             list($model, $column) = explode('.', $column);
         }
         if ($meta = Jam::meta(Jam_Query_Builder::aliased_model($model))) {
             $column = Jam_Query_Builder::resolve_meta_attribute($column, $meta, $value);
         }
         if ($model) {
             if (is_array($model)) {
                 $model = $model[1];
             } elseif ($meta) {
                 $model = $meta->table();
             }
             $column = $model . '.' . $column;
         }
     }
     if (!empty($alias)) {
         return array($column, $alias);
     } else {
         return $column;
     }
 }
예제 #2
0
파일: Collection.php 프로젝트: Konro1/pms
 /**
  * Return all of the models in the result as an array.
  *
  *     // Indexed array of all models
  *     $rows = $result->as_array();
  *
  *     // Associative array of models by "id"
  *     $rows = $result->as_array('id');
  *
  *     // Associative array of fields, "id" => "name"
  *     $rows = $result->as_array('id', 'name');
  *
  * @param   string  column for associative keys
  * @param   string  column for values
  * @return  array
  */
 public function as_array($key = NULL, $value = NULL)
 {
     $key = Jam_Query_Builder::resolve_meta_attribute($key, $this->meta());
     if ($value === NULL) {
         return array_map(array($this, '_load_model'), $this->result()->as_array($key));
     } else {
         $value = Jam_Query_Builder::resolve_meta_attribute($value, $this->meta());
         return $this->result()->as_array($key, $value);
     }
 }
예제 #3
0
파일: Jam.php 프로젝트: Konro1/pms
 protected static function find_or($method, $model, array $values)
 {
     $collection = Jam::all($model);
     $converted_keys = array();
     foreach ($values as $key => $value) {
         $key = Jam_Query_Builder::resolve_meta_attribute($key, Jam::meta($model), $value);
         $collection->where($key, '=', $value);
         $converted_keys[$key] = $value;
     }
     if ($item = $collection->first()) {
         return $item;
     }
     return call_user_func($method, $model, $converted_keys);
 }
예제 #4
0
파일: Model.php 프로젝트: Konro1/pms
 public function as_array($key = NULL, $value = NULL)
 {
     $results = array();
     $key = Jam_Query_Builder::resolve_meta_attribute($key, $this->meta());
     $value = Jam_Query_Builder::resolve_meta_attribute($value, $this->meta());
     foreach ($this as $i => $item) {
         $results[$key ? $item->{$key} : $i] = $value ? $item->{$value} : $item;
     }
     return $results;
 }