Since: 1.2
Author: alcaeus (alcaeus@alcaeus.org)
示例#1
0
 /**
  * @param mixed|self $expression
  * @return mixed
  */
 protected function ensureArray($expression)
 {
     // Convert field names in expressions
     if (is_string($expression) && substr($expression, 0, 1) === '$') {
         return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
     }
     // Convert PHP types to MongoDB types for everything else
     return Type::convertPHPToDatabaseValue(parent::ensureArray($expression));
 }
示例#2
0
 /**
  * Returns the year portion of a date.
  *
  * The argument can be any expression as long as it resolves to a date.
  *
  * @see http://docs.mongodb.org/manual/reference/operator/aggregation/year/
  * @see Expr::year
  * @param mixed|Expr $expression
  * @return self
  */
 public function year($expression)
 {
     $this->expr->year($expression);
     return $this;
 }
示例#3
0
 /**
  * Calculates and returns the sum of all the numeric values that result from
  * applying a specified expression to each document in a group of documents
  * that share the same group by key. Ignores nun-numeric values.
  *
  * @see http://docs.mongodb.org/manual/reference/operator/aggregation/sum/
  * @see Expr::sum
  * @param mixed|Expr $expression
  * @return Operator
  */
 public function sum($expression)
 {
     $this->expr->sum($expression);
     return $this;
 }
示例#4
0
 public static function provideProxiedExprMethods()
 {
     $expression = new Expr();
     $expression->field('dayOfMonth')->dayOfMonth('$dateField')->field('dayOfWeek')->dayOfWeek('$dateField');
     return array('avg()' => array('avg', array('$field')), 'max()' => array('max', array('$field')), 'min()' => array('min', array('$field')), 'stdDevPop()' => array('stdDevPop', array('$field')), 'stdDevSamp()' => array('stdDevSamp', array('$field')), 'sum()' => array('sum', array('$field')));
 }
示例#5
0
 public function provideProxiedExprMethods()
 {
     $expression = new Expr();
     $expression->field('dayOfMonth')->dayOfMonth('$dateField')->field('dayOfWeek')->dayOfWeek('$dateField');
     return ['addToSet()' => ['addToSet', ['$field']], 'avg()' => ['avg', ['$field']], 'expression()' => ['expression', [$expression]], 'first()' => ['first', ['$field']], 'last()' => ['last', ['$field']], 'max()' => ['max', ['$field']], 'min()' => ['min', ['$field']], 'push()' => ['push', ['$field']], 'stdDevPop()' => ['stdDevPop', ['$field']], 'stdDevSamp()' => ['stdDevSamp', ['$field']], 'sum()' => ['sum', ['$field']]];
 }
示例#6
0
 public function testMap()
 {
     $in = new Expr();
     $in->add('$$grade', 2);
     $expr = new Expr();
     $this->assertSame($expr, $expr->field('adjustedGrades')->map('$quizzes', 'grade', $in));
     $this->assertSame(array('adjustedGrades' => array('$map' => array('input' => '$quizzes', 'as' => 'grade', 'in' => array('$add' => array('$$grade', 2))))), $expr->getExpression());
 }
示例#7
0
 public function provideProxiedExprMethods()
 {
     $expression = new Expr();
     $expression->field('dayOfMonth')->dayOfMonth('$dateField')->field('dayOfWeek')->dayOfWeek('$dateField');
     return array('abs()' => array('abs', array('$number')), 'add()' => array('add', array(5, '$field', '$otherField')), 'allElementsTrue()' => array('allElementsTrue', array('$field')), 'anyElementTrue()' => array('anyElementTrue', array('$field')), 'arrayElemAt()' => array('arrayElemAt', array('$array', '$index')), 'ceil()' => array('ceil', array('$number')), 'cmp()' => array('cmp', array('$field', '$otherField')), 'concat()' => array('concat', array('foo', '$field', '$otherField')), 'concatArrays()' => array('concatArrays', array('$field', '$otherField')), 'cond()' => array('cond', array('$ifField', '$field', '$otherField')), 'dateToString()' => array('dateToString', array('%Y-%m-%d', '$dateField')), 'dayOfMonth()' => array('dayOfMonth', array('$dateField')), 'dayOfWeek()' => array('dayOfWeek', array('$dateField')), 'dayOfYear()' => array('dayOfYear', array('$dateField')), 'divide()' => array('divide', array('$field', 5)), 'eq()' => array('eq', array('$field', '$otherField')), 'exp()' => array('exp', array('$field')), 'expression()' => array('expression', array($expression)), 'filter()' => array('filter', array('$input', '$as', '$cond')), 'floor()' => array('floor', array('$number')), 'gt()' => array('gt', array('$field', '$otherField')), 'gte()' => array('gte', array('$field', '$otherField')), 'hour()' => array('hour', array('$dateField')), 'ifNull()' => array('ifNull', array('$field', '$otherField')), 'isArray()' => array('isArray', array('$field')), 'let()' => array('let', array('$vars', '$in')), 'literal()' => array('literal', array('$field')), 'ln()' => array('ln', array('$number')), 'log()' => array('log', array('$number', '$base')), 'log10()' => array('log10', array('$number')), 'lt()' => array('lt', array('$field', '$otherField')), 'lte()' => array('lte', array('$field', '$otherField')), 'map()' => array('map', array('$quizzes', 'grade', array('$add' => array('$$grade' => 2)))), 'meta()' => array('meta', array('textScore')), 'millisecond()' => array('millisecond', array('$dateField')), 'minute()' => array('minute', array('$dateField')), 'mod()' => array('mod', array('$field', 5)), 'month()' => array('month', array('$dateField')), 'multiply()' => array('multiply', array('$field', 5)), 'ne()' => array('ne', array('$field', '$otherField')), 'not()' => array('not', array('$field')), 'pow()' => array('pow', array('$number', '$exponent')), 'second()' => array('second', array('$dateField')), 'setDifference()' => array('setDifference', array('$field', '$otherField')), 'setEquals()' => array('setEquals', array('$field', '$otherField', '$anotherField')), 'setIntersection()' => array('setIntersection', array('$field', '$otherField', '$anotherField')), 'setIsSubset()' => array('setIsSubset', array('$field', '$otherField')), 'setUnion()' => array('setUnion', array('$field', '$otherField', '$anotherField')), 'size()' => array('size', array('$field')), 'slice()' => array('slice', array('$array', '$index')), 'sqrt()' => array('sqrt', array('$number')), 'strcasecmp()' => array('strcasecmp', array('$field', '$otherField')), 'substr()' => array('substr', array('$field', 0, '$length')), 'subtract()' => array('subtract', array('$field', 5)), 'toLower()' => array('toLower', array('$field')), 'toUpper()' => array('toUpper', array('$field')), 'trunc()' => array('trunc', array('$number')), 'week()' => array('week', array('$dateField')), 'year()' => array('year', array('$dateField')));
 }
示例#8
0
 public function provideProxiedExprMethods()
 {
     $expression = new Expr();
     $expression->field('dayOfMonth')->dayOfMonth('$dateField')->field('dayOfWeek')->dayOfWeek('$dateField');
     return array('addToSet()' => array('addToSet', array('$field')), 'avg()' => array('avg', array('$field')), 'expression()' => array('expression', array($expression)), 'first()' => array('first', array('$field')), 'last()' => array('last', array('$field')), 'max()' => array('max', array('$field')), 'min()' => array('min', array('$field')), 'push()' => array('push', array('$field')), 'stdDevPop()' => array('stdDevPop', array('$field')), 'stdDevSamp()' => array('stdDevSamp', array('$field')), 'sum()' => array('sum', array('$field')));
 }