/**
  * Parse the product query.
  *
  * @since 1.0
  *
  * @return Join|null
  */
 protected function parse_join()
 {
     if (empty($this->args['product']) && empty($this->args['customer'])) {
         return null;
     }
     $on = new Where_Raw('k.lkey = q.lkey');
     if (!empty($this->args['product'])) {
         $on->qAnd(new Where('k.product', true, absint($this->args['product'])));
     }
     if (!empty($this->args['customer'])) {
         $on->qAnd(new Where('k.customer', true, absint($this->args['customer'])));
     }
     return new Join(new From(Manager::get('itelic-keys')->get_table_name($GLOBALS['wpdb']), 'k'), $on);
 }
Exemplo n.º 2
0
 /**
  * Parse the search query.
  *
  * @since 1.0
  *
  * @return Join|null
  */
 protected function parse_customer_search()
 {
     if (empty($this->args['customer_search']) || empty($this->args['customer_search_columns'])) {
         return null;
     }
     $clause = esc_sql($this->args['customer_search']);
     $search_ids = new Where_Raw('u.ID = q.customer');
     $white_list = $this->get_default_arg('customer_search_columns');
     foreach ((array) $this->args['customer_search_columns'] as $column) {
         if (!in_array($column, $white_list)) {
             throw new \InvalidArgumentException("Invalid customer_search_column {$column}.");
         }
         if (!isset($search_where)) {
             $search_where = new Where("u.{$column}", 'LIKE', $clause);
         } else {
             /**
              * @var Where $search_where
              */
             $search_where->qOr(new Where("u.{$column}", 'LIKE', $clause));
         }
     }
     if (!isset($search_where)) {
         return null;
     }
     $search_ids->qAnd($search_where);
     return new Join(new From($GLOBALS['wpdb']->users, 'u'), $search_ids);
 }