예제 #1
0
 /**
  * Build a tax_query clause corresponding to a single input
  *
  * @param $taxonomy
  * @param $input_name
  * @param $input
  * @return array
  */
 private function taxQueryClause($taxonomy, $input_name, $input)
 {
     if (empty($input)) {
         return;
     }
     $request_var = RequestVar::nameToVar($input_name, 'taxonomy');
     $terms = $this->request->get($request_var);
     if (empty($terms)) {
         return;
     }
     $clause = array();
     $clause['taxonomy'] = $taxonomy;
     $clause['operator'] = $input['operator'];
     $clause['field'] = empty($inputs['term_format']) ? self::$default_format : $inputs['term_format'];
     $clause['terms'] = $terms;
     return $clause;
 }
예제 #2
0
 /**
  *  Build a meta_query clause for meta values which are stored as an array
  *
  *  Creates a separate sub-clause for each value being queried
  *
  * @param $meta_key
  * @param $input_name
  * @param $input
  * @return array
  */
 private function metaQueryClauseArray($meta_key, $input_name, $input)
 {
     $request_var = RequestVar::nameToVar($input_name, 'meta_key');
     $var = $this->request->get($request_var);
     if (empty($var)) {
         return array();
     }
     $clause = array();
     if (!is_array($var)) {
         $var = array($var);
     }
     foreach ($var as $value) {
         $clause[] = $this->subClause($meta_key, $input, $value);
     }
     if (count($clause) > 1) {
         $clause['relation'] = $input['relation'];
     }
     if (count($clause) == 1) {
         $clause = $clause[0];
     }
     return $clause;
 }
예제 #3
0
 /**
  * Given a Field object, initializes that field's input(s) to Input objects
  * and adds them to the inputs table
  *
  * @param Field $field
  * @param $request
  */
 private function addInputs(Field $field, $request)
 {
     $field_type = $field->getFieldType();
     $inputs = $field->getInputs();
     foreach ($inputs as $name => $input_args) {
         try {
             if ($field_type == FieldType::date) {
                 $date_type = !empty($input_args['date_type']) ? $input_args['date_type'] : false;
                 $post_types = $this->selectedPostTypes($request);
                 $name = RequestVar::nameToVar($name, $field_type, $date_type);
                 $input = DateInputBuilder::make($name, $input_args, $post_types, $request);
             } else {
                 if ($field_type == FieldType::generic) {
                     $name = empty($input_args['id']) ? 'generic' : $input_args['id'];
                 } else {
                     $name = RequestVar::nameToVar($name, $field_type);
                 }
                 $input = InputBuilder::make($name, $field_type, $input_args, $request);
             }
             $this->inputs[] = $input;
         } catch (\InvalidArgumentException $e) {
             $this->addExceptionError($e);
             continue;
         } catch (\Exception $e) {
             $this->addExceptionError($e);
             continue;
         }
     }
 }
예제 #4
0
 /**
  * Adds and argument to an array of query arguments
  *
  * @param array $query
  * @param array $fields
  * @param HttpRequest $request
  * @return array
  */
 private function addQueryArg(array $query, array $fields, HttpRequest $request)
 {
     if (empty($fields)) {
         return $query;
     }
     $field = reset($fields);
     // As of v1.4, only one field allowed per
     // query var (other than taxonomy and meta_key)
     $field_id = $field->getFieldId();
     $var = RequestVar::nameToVar($field_id);
     $wp_var = RequestVar::wpQueryVar($field_id);
     $wp_var = !$wp_var ? $var : $wp_var;
     $val = $request->get($var);
     if (empty($val)) {
         return $query;
     }
     $query[$wp_var] = self::filter($wp_var, $val);
     return $query;
 }