Пример #1
0
 public function query_builder($filter, $table)
 {
     $temp = $table->load();
     $where = $filter['where'] ? self::where_builder($filter['where']) : null;
     $options = $filter['options'] ? self::options_builder($filter['options']) : null;
     if (!$table->load()) {
         exit;
     }
     $records = $table->load()->find($where, $options);
     if (is_array($filter['fields'])) {
         if ($filter['fields']) {
             $fields = __::intersection($filter['fields'], $table->fields());
         }
     } elseif ($filter['fields']) {
         $filter['fields'] = array($filter['fields']);
         $fields = __::intersection($filter['fields'], $table->fields());
     } else {
         $fields = $table->fields();
     }
     $out = array();
     foreach ($records as $key => $value) {
         $temp = array();
         $temp['id'] = $value['_id'];
         foreach ($fields as $field) {
             if (isset($value[$field]) && $field != 'password') {
                 $temp[$field] = $value[$field];
             }
         }
         $out[] = $temp;
     }
     return $out;
 }
function _intersection($array)
{
    return Underscore::intersection($array);
}
Пример #3
0
 /**
  * @tags arrays
  */
 public function testIntersection()
 {
     // it should compute the list of values that are the intersection of all the arrays
     $values = [['a' => 1, 'b' => 2, 'c' => 3], ['a' => 4, 'b' => 1, 'c' => 2], ['a' => 0, 'b' => 3, 'c' => 1]];
     $this->typeTolerant($values, [1], function ($in, $out) {
         $in = _::toArray($in);
         $this->array(_::intersection($in[0], $in[1], $in[2]))->isEqualTo($out);
     }, [1, -1]);
     // it should be capable to compute intersection of different type
     $this->array(_::intersection($values[0], self::toObject($values[1]), self::toIterator($values[2])))->isEqualTo([1]);
     // it should return the array itself if it's the only argument
     $this->array(_::intersection($values[0]))->isEqualTo($values[0]);
     // it should return an empty array if the list is empty
     $this->array(_::intersection(null))->isEqualTo([]);
 }