Example #1
0
 /**
  * Constructs the arithmetic expression with the arithmetic
  * operator $op and two operands, $left and $right, which
  * are FQLExpressions themselves.
  *
  * @param  $op     arithmetic op (+, -, *, /)
  * @param  $left   FQLExpression representing left operand
  * @param  $right  FQLExpression representing right operand
  */
 public function __construct($op, $left, $right)
 {
     $this->op = $op;
     parent::__construct($left, $right);
 }
Example #2
0
 /**
  * Gets the query expression that the comparison expression
  * is enforcing. Currently this supports equality only, so an
  * expression like id < 3 will yield ':', which matches all ids.
  * An expression like id == 3 will yield the query for the field
  * 'id' for the value 3.
  *
  * Only comparisons between a field and a constant are valid.
  *
  * @return associative array where the keys are the query expressions
  *         and they all map to 1.
  */
 public function get_queries()
 {
     if ($this->op != '==') {
         // can only index by equality
         return parent::get_queries();
     }
     if ($this->right instanceof FQLConstantExpression && $this->left instanceof FQLFieldExpression) {
         // expression is something like "id == 3"
         $query = $this->left->field->get_query($this->right->evaluate(null));
     } else {
         if ($this->left instanceof FQLConstantExpression && $this->right instanceof FQLFieldExpression) {
             // expression is something like "3 == id"
             $query = $this->right->field->get_query($this->left->evaluate(null));
         } else {
             return parent::get_queries();
         }
     }
     if (isset($query) && $query) {
         return array($query => 1);
     } else {
         // this means that we're sure there are no matches.  e.g. you did a
         // search for groups where id == -5 or something.
         return array();
     }
 }