Exemplo n.º 1
0
 /**
  * Get Concat filter.
  *
  * @param string $searchValue Search value
  * @param string $fieldaliasprefix Field alias prefix
  *
  * @return string|bool
  */
 public function getConcatFilter($searchValue, $fieldaliasprefix = '')
 {
     // If we have a descriptor with multiple fields, use CONCAT
     $attribs = $this->m_destInstance->descriptorFields();
     if (count($attribs) > 1) {
         $fields = [];
         foreach ($attribs as $attribname) {
             $post = '';
             if (strstr($attribname, '.')) {
                 if ($fieldaliasprefix != '') {
                     $table = $fieldaliasprefix . '_AE_';
                 } else {
                     $table = '';
                 }
                 $post = substr($attribname, strpos($attribname, '.'));
                 $attribname = substr($attribname, 0, strpos($attribname, '.'));
             } elseif ($fieldaliasprefix != '') {
                 $table = $fieldaliasprefix . '.';
             } else {
                 $table = $this->m_destInstance->m_table . '.';
             }
             /** @var Attribute $p_attrib */
             $p_attrib = $this->m_destInstance->m_attribList[$attribname];
             $fields[$p_attrib->fieldName()] = $table . $p_attrib->fieldName() . $post;
         }
         if (is_array($searchValue)) {
             // (fix warning trim function)
             $searchValue = $searchValue[0];
         }
         $value = $this->escapeSQL(trim($searchValue));
         $value = str_replace('  ', ' ', $value);
         if (!$value) {
             return false;
         } else {
             $function = $this->getConcatDescriptorFunction();
             if ($function != '' && method_exists($this->m_destInstance, $function)) {
                 $descriptordef = $this->m_destInstance->{$function}();
             } elseif ($this->m_destInstance->m_descTemplate != null) {
                 $descriptordef = $this->m_destInstance->m_descTemplate;
             } elseif (method_exists($this->m_destInstance, 'descriptor_def')) {
                 $descriptordef = $this->m_destInstance->descriptor_def();
             } else {
                 $descriptordef = $this->m_destInstance->descriptor(null);
             }
             $parser = new StringParser($descriptordef);
             $concatFields = $parser->getAllParsedFieldsAsArray($fields, true);
             $concatTags = $concatFields['tags'];
             $concatSeparators = $concatFields['separators'];
             $concatSeparators[] = ' ';
             //the query removes all spaces, so let's do the same here [Bjorn]
             // to search independent of characters between tags, like spaces and comma's,
             // we remove all these separators so we can search for just the concatenated tags in concat_ws [Jeroen]
             foreach ($concatSeparators as $separator) {
                 $value = str_replace($separator, '', $value);
             }
             $db = $this->getDb();
             $searchcondition = 'UPPER(' . $db->func_concat_ws($concatTags, '', true) . ") LIKE UPPER('%" . $value . "%')";
         }
         return $searchcondition;
     }
     return false;
 }
Exemplo n.º 2
0
 public function getSearchCondition(Query $query, $table, $value, $searchmode, $fieldname = '')
 {
     $searchconditions = [];
     // Get search condition for all searchFields
     foreach ($this->m_searchfields as $field) {
         $p_attrib = $this->m_ownerInstance->getAttribute($field);
         if (is_object($p_attrib)) {
             $condition = $p_attrib->getSearchCondition($query, $table, $value, $searchmode);
             if (!empty($condition)) {
                 $searchconditions[] = $condition;
             }
         }
     }
     // When searchmode is substring also search the value in a concat of all searchfields
     if ($searchmode == 'substring') {
         $value = $this->escapeSQL(trim($value));
         $data = [];
         foreach ($this->m_searchfields as $field) {
             if (strpos($field, '.') == false) {
                 $data[$field] = $table . '.' . $field;
             } else {
                 $data[$field] = $field;
             }
         }
         $parser = new StringParser($this->m_template);
         $concatFields = $parser->getAllParsedFieldsAsArray($data, true);
         $concatTags = $concatFields['tags'];
         $concatSeparators = $concatFields['separators'];
         // to search independent of characters between tags, like spaces and comma's,
         // we remove all these separators (defined in the node with new atkAggregatedColumn)
         // so we can search for just the concatenated tags in concat_ws [Jeroen]
         foreach ($concatSeparators as $separator) {
             $value = str_replace($separator, '', $value);
         }
         $db = $this->getDb();
         $condition = 'UPPER(' . $db->func_concat_ws($concatTags, '', true) . ") LIKE UPPER('%" . $value . "%')";
         $searchconditions[] = $condition;
     }
     if (count($searchconditions)) {
         return '(' . implode(' OR ', $searchconditions) . ')';
     }
     return '';
 }