Example #1
0
 /**
  * Sets scope for this expression so it knows its
  * source table.
  *
  * @param $stmt  FQLStatement that this expression was contained in
  */
 public function set_scope($stmt)
 {
     $this->right->set_scope($stmt);
     parent::set_scope($stmt);
 }
Example #2
0
 /**
  * Sets the scope for this field expression. Performs validity
  * check on the field name by checking if the field name is
  * contained in the source table. Initializes the appropriate
  * field object for the field name for this table.
  *
  * @param  $scope FQLStatement that this expression is
  *                contained in
  *
  * Throws UnknownFieldException if this field name is not
  * a valid field in the source table.
  */
 public function set_scope($scope)
 {
     $fields = $scope->from_table->get_fields();
     if (isset($fields[$this->field_name])) {
         $this->field = new $fields[$this->field_name]($scope->user, $scope->app_id, $scope->from_table, $this->field_name);
     } else {
         throw new UnknownFieldException($this->field_name, $scope->from, 'table');
     }
     parent::set_scope($scope);
 }
Example #3
0
 /**
  * Gets the list of query expressions that matches the constraints
  * expressed in the IN expression.
  *
  * Queries are only generated when the expression is of the form
  * uid IN (1, 2, 3,...) where uid is a field name and the list
  * contains only constants, or 90210 IN (hometown_location, current_location)
  * where the initial expression is a constant and the list
  * contains only field names.  In all other cases, this function
  * will just return the generic ':' wildcard query, which matches all
  * ids.
  *
  * @return associative array of queries where the keys are the queries,
  *         all mapping to 1
  */
 public function get_queries()
 {
     if ($this->expression instanceof FQLFieldExpression) {
         // like (uid IN (1,3,5))
         $queries = array();
         $all_consts = array();
         foreach ($this->list as $const) {
             if (!$const instanceof FQLConstantExpression) {
                 return parent::get_queries();
             }
             $val = $const->evaluate(null);
             $all_consts[$val] = 1;
             $query = $this->expression->field->get_query($val, '=');
             if ($query) {
                 $queries[$query] = 1;
             }
         }
         // save the list of constants so it doesn't need to be reevaluated each time
         $this->const_list = $all_consts;
         return $queries;
     } else {
         if ($this->expression instanceof FQLConstantExpression) {
             // like (90210 IN (hometown_location, current_location))
             $queries = array();
             $val = $this->expression->evaluate(null);
             foreach ($this->list as $field) {
                 if (!$field instanceof FQLFieldExpression) {
                     return parent::get_queries();
                 }
                 $query = $field->field->get_query($val, '=');
                 if ($query) {
                     $queries[$query] = 1;
                 }
             }
             return $queries;
         }
     }
     return parent::get_queries();
 }