Esempio n. 1
0
 public function buildFilterQuery($filter, &$joins, array &$where, Register $parameter_output)
 {
     $driver = Extension::load('members');
     $filter = $this->processFilter($filter);
     $filter_join = DataSource::FILTER_OR;
     $db = Symphony::Database();
     $values = DataSource::prepareFilterValue($filter->value, $parameter_output, $filter_join);
     if (!is_array($values)) {
         $values = array();
     }
     // Exact matches:
     if ($filter->type == 'is' or $filter->type == 'is-not') {
         $statements = array();
         if ($filter_join == DataSource::FILTER_OR) {
             $handle = $this->buildFilterJoin($joins);
         }
         foreach ($values as $index => $value) {
             if ($filter_join != DataSource::FILTER_OR) {
                 $handle = $this->buildFilterJoin($joins);
             }
             $statements[] = $db->prepareQuery("{$handle}.password = '******' OR {$handle}.code = '%s'", array(sha1($value), $driver->extractToken($value, 'login')));
         }
         if (empty($statements)) {
             return true;
         }
         if ($filter_join == DataSource::FILTER_OR) {
             $statement = "(\n\t" . implode("\n\tOR ", $statements) . "\n)";
         } else {
             $statement = "(\n\t" . implode("\n\tAND ", $statements) . "\n)";
         }
         if ($filter->type == 'is-not') {
             $statement = 'NOT ' . $statement;
         }
         $where[] = $statement;
     }
     return true;
 }
Esempio n. 2
0
 public function buildFilterQuery($filter, &$joins, array &$where, Register $parameter_output)
 {
     $filter = $this->processFilter($filter);
     $filter_join = DataSource::FILTER_OR;
     $db = Symphony::Database();
     $values = DataSource::prepareFilterValue($filter->value, $parameter_output, $filter_join);
     if (!is_array($values)) {
         $values = array();
     }
     // Exact matches:
     if ($filter->type == 'is' or $filter->type == 'is-not') {
         $statements = array();
         if ($filter_join == DataSource::FILTER_OR) {
             $handle = $this->buildFilterJoin($joins);
         }
         foreach ($values as $index => $value) {
             if ($filter_join != DataSource::FILTER_OR) {
                 $handle = $this->buildFilterJoin($joins);
             }
             $statements[] = $db->prepareQuery("'%s' IN ({$handle}.value, {$handle}.handle)", array($value));
         }
         if (empty($statements)) {
             return true;
         }
         if ($filter_join == DataSource::FILTER_OR) {
             $statement = "(\n\t" . implode("\n\tOR ", $statements) . "\n)";
         } else {
             $statement = "(\n\t" . implode("\n\tAND ", $statements) . "\n)";
         }
         if ($filter->type == 'is-not') {
             $statement = 'NOT ' . $statement;
         }
         $where[] = $statement;
     } else {
         if ($filter->type == 'is-null') {
             $handle = $this->buildFilterJoin($joins);
             $where[] = $db->prepareQuery("{$handle}.value IS NULL");
         } else {
             if ($filter->type == 'is-null') {
                 $handle = $this->buildFilterJoin($joins);
                 $where[] = $db->prepareQuery("{$handle}.value IS NULL");
             } else {
                 if ($filter->type == 'contains' or $filter->type == 'does-not-contain') {
                     $statements = array();
                     if ($filter_join == DataSource::FILTER_OR) {
                         $handle = $this->buildFilterJoin($joins);
                     }
                     foreach ($values as $index => $value) {
                         $value = '%' . $value . '%';
                         if ($filter_join != DataSource::FILTER_OR) {
                             $handle = $this->buildFilterJoin($joins);
                         }
                         $statements = array($db->prepareQuery("{$handle}.value LIKE '%s'", array($value)), $db->prepareQuery("{$handle}.handle LIKE '%s'", array($value)));
                     }
                     if (empty($statements)) {
                         return true;
                     }
                     if ($filter_join == DataSource::FILTER_OR) {
                         $statement = "(\n\t" . implode("\n\tOR ", $statements) . "\n)";
                     } else {
                         $statement = "(\n\t" . implode("\n\tAND ", $statements) . "\n)";
                     }
                     if ($filter->type == 'does-not-contain') {
                         $statement = 'NOT ' . $statement;
                     }
                     $where[] = $statement;
                 } else {
                     if ($filter->type == 'regex-search') {
                         $handle = $this->buildFilterJoin($joins);
                         $value = trim($filter->value);
                         $statements = array($db->prepareQuery("{$handle}.value REGEXP '%s'", array($value)), $db->prepareQuery("{$handle}.handle REGEXP '%s'", array($value)));
                         $where[] = "(\n\t" . implode("\n\tOR ", $statements) . "\n)";
                     }
                 }
             }
         }
     }
     return true;
 }
Esempio n. 3
0
    public function buildFilterQuery($filter, &$joins, array &$where, Register $ParameterOutput = NULL)
    {
        self::$key++;
        $value = DataSource::prepareFilterValue($filter['value'], $ParameterOutput, $operation_type);
        $joins .= sprintf('
				LEFT OUTER JOIN `tbl_data_%2$s_%3$s` AS t%1$s ON (e.id = t%1$s.entry_id)
			', self::$key, $this->section, $this->{'element-name'});
        if ($operation_type == DataSource::FILTER_AND) {
            $clause = NULL;
            foreach ($value as $v) {
                $clause .= sprintf("(t%1\$s.value %2\$s '%3\$s') AND", self::$key, $filter['type'] == 'is-not' ? '<>' : '=', $v);
            }
            $where[] = sprintf("(%s)", preg_replace('/AND$/i', NULL, $clause));
        } else {
            $where[] = sprintf("(t%1\$s.value %2\$s IN ('%3\$s'))", self::$key, $filter['type'] == 'is-not' ? 'NOT' : NULL, implode("', '", $value));
        }
        return true;
    }
Esempio n. 4
0
    public function xbuildFilterQuery($filter, &$joins, array &$where, Register $ParameterOutput = NULL)
    {
        var_dump($this->getFilterTypes($filter));
        var_dump($filter);
        exit;
        self::$key++;
        $value = DataSource::prepareFilterValue($filter['value'], $ParameterOutput, $filterOperationType);
        $joins .= sprintf('
				LEFT OUTER JOIN `tbl_data_%2$s_%3$s` AS t%1$s ON (e.id = t%1$s.entry_id)
			', self::$key, $this->section, $this->{'element-name'});
        if ($filterOperationType == DataSource::FILTER_AND) {
            $clause = NULL;
            foreach ($value as $v) {
                $clause .= sprintf(" (t%1\$s.relation_id %2\$s '%3\$s') AND", self::$key, $filter['type'] == 'is-not' ? '<>' : '=', $v);
            }
            $where[] = sprintf("(%s)", preg_replace('/AND$/i', NULL, $clause));
        } else {
            $where[] = sprintf("(t%1\$s.relation_id %2\$s IN ('%3\$s'))", self::$key, $filter['type'] == 'is-not' ? 'NOT' : NULL, implode("', '", $value));
        }
        return true;
        // OLD CODE ------
        $field_id = $this->{'id'};
        if (preg_match('/^sql:\\s*/', $data[0], $matches)) {
            $data = trim(array_pop(explode(':', $data[0], 2)));
            if (strpos($data, "NOT NULL") !== false) {
                $joins .= " LEFT JOIN\n\t\t\t\t\t\t\t\t\t`tbl_entries_data_{$field_id}` AS `t{$field_id}`\n\t\t\t\t\t\t\t\tON (`e`.`id` = `t{$field_id}`.entry_id)";
                $where .= " AND `t{$field_id}`.relation_id IS NOT NULL ";
            } else {
                if (strpos($data, "NULL") !== false) {
                    $joins .= " LEFT JOIN\n\t\t\t\t\t\t\t\t\t`tbl_entries_data_{$field_id}` AS `t{$field_id}`\n\t\t\t\t\t\t\t\tON (`e`.`id` = `t{$field_id}`.entry_id)";
                    $where .= " AND `t{$field_id}`.relation_id IS NULL ";
                }
            }
        } else {
            foreach ($data as $key => &$value) {
                // for now, I assume string values are the only possible handles.
                // of course, this is not entirely true, but I find it good enough.
                if (!is_numeric($value)) {
                    $related_field_id = $this->{'related-field-id'};
                    if (is_array($related_field_id) && !empty($related_field_id)) {
                        $return = Symphony::Database()->fetchCol("id", sprintf("SELECT\n\t\t\t\t\t\t\t\t\t`entry_id` as `id`\n\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t`tbl_entries_data_%d`\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t`handle` = '%s'\n\t\t\t\t\t\t\t\tLIMIT 1", $related_field_id[0], Lang::createHandle($value)));
                        // Skipping returns wrong results when doing an AND operation, return 0 instead.
                        if (empty($return)) {
                            $value = 0;
                        } else {
                            $value = $return[0];
                        }
                    }
                }
            }
            if ($andOperation) {
                foreach ($data as $key => $bit) {
                    $joins .= " LEFT JOIN `tbl_entries_data_{$field_id}` AS `t{$field_id}{$key}` ON (`e`.`id` = `t{$field_id}{$key}`.entry_id) ";
                    $where .= " AND `t{$field_id}{$key}`.relation_id = '{$bit}' ";
                }
            } else {
                $joins .= " LEFT JOIN `tbl_entries_data_{$field_id}` AS `t{$field_id}` ON (`e`.`id` = `t{$field_id}`.entry_id) ";
                $where .= " AND `t{$field_id}`.relation_id IN ('" . @implode("', '", $data) . "') ";
            }
        }
        return true;
    }
Esempio n. 5
0
 public function buildFilterQuery($filter, &$joins, array &$where, Register $parameter_output)
 {
     $filter = $this->processFilter($filter);
     $filter_join = DataSource::FILTER_OR;
     $db = Symphony::Database();
     $values = DataSource::prepareFilterValue($filter->value, $parameter_output, $filter_join);
     if (!is_array($values)) {
         $values = array();
     }
     // Exact matches:
     if ($filter->type == 'is' or $filter->type == 'is-not') {
         $statements = array();
         if ($filter_join == DataSource::FILTER_OR) {
             $handle = $this->buildFilterJoin($joins);
         }
         foreach ($values as $index => $value) {
             if ($filter_join != DataSource::FILTER_OR) {
                 $handle = $this->buildFilterJoin($joins);
             }
             $statements[] = $db->prepareQuery("'%s' IN ({$handle}.relation_id)", array($value));
         }
         if (empty($statements)) {
             return true;
         }
         if ($filter_join == DataSource::FILTER_OR) {
             $statement = "(\n\t" . implode("\n\tOR ", $statements) . "\n)";
         } else {
             $statement = "(\n\t" . implode("\n\tAND ", $statements) . "\n)";
         }
         if ($filter->type == 'is-not') {
             $statement = 'NOT ' . $statement;
         }
         $where[] = $statement;
     }
 }