Exemplo n.º 1
0
 /**
  * Convert a QueryGroup object to a query string.
  *
  * @param QueryGroup $query QueryGroup to convert
  *
  * @return string
  */
 protected function queryGroupToString(QueryGroup $query)
 {
     $groups = $excludes = [];
     foreach ($query->getQueries() as $params) {
         // Advanced Search
         if ($params instanceof QueryGroup) {
             $thisGroup = [];
             // Process each search group
             foreach ($params->getQueries() as $group) {
                 // Build this group individually as a basic search
                 $thisGroup[] = $this->abstractQueryToString($group);
             }
             // Is this an exclusion (NOT) group or a normal group?
             if ($params->isNegated()) {
                 $excludes[] = join(" OR ", $thisGroup);
             } else {
                 $groups[] = join(" " . $params->getOperator() . " ", $thisGroup);
             }
         } else {
             // Basic Search
             $groups[] = $this->queryToString($params);
         }
     }
     // Put our advanced search together
     $queryStr = '';
     if (count($groups) > 0) {
         $queryStr .= "(" . join(") " . $query->getOperator() . " (", $groups) . ")";
     }
     // and concatenate exclusion after that
     if (count($excludes) > 0) {
         $queryStr .= " NOT ((" . join(") OR (", $excludes) . "))";
     }
     return $queryStr;
 }