protected function get_filter_values(&$filters) { $fetch = array(); $value_needed = Meta::value_needed(); foreach ($filters as $filter) { if (!in_array($filter['meta_type'], $value_needed)) { continue; } if (!isset($fetch[$filter['name']])) { $fetch[$filter['name']] = array(); } $fetch[$filter['name']][] = $filter['value']; } foreach ($fetch as $type => $names) { $table = $type == 'translator' ? 'user' : $type; $field = $type == 'translator' ? 'login' : 'name'; $fetched = (array) $this->db->get_vector($table, array($field, 'id'), $this->db->array_in($field, $names), $names); if ($table == 'art_tag' && count($fetched) != count($fetch[$table])) { $variants = (array) $this->db->get_vector('art_tag_variant', array('name', 'id_tag'), $this->db->array_in('name', $names), $names); $fetched = $fetched + $variants; } $fetch[$type] = array(); foreach ($fetched as $key => $item) { $key = new Text($key); $fetch[$type][(string) $key->lower()] = $item; } } foreach ($filters as &$filter) { if (!in_array($filter['meta_type'], $value_needed)) { continue; } $compare_value = new Text($filter['value']); $compare_value = (string) $compare_value->lower(); if (empty($fetch[$filter['name']]) || empty($fetch[$filter['name']][$compare_value])) { if ($filter['operator'] == Meta::IS) { switch ($filter['meta_type']) { case Meta::ART_TAG: $text = 'Тега "' . $filter['value'] . '" не существует.'; break; case Meta::STATE: $text = 'Состояния "' . $filter['value'] . '" не существует.'; break; case Meta::TRANSLATOR: $text = 'Пользователя "' . $filter['value'] . '" не существует.'; break; default: $text = $filter['name'] . ' "' . $filter['value'] . '" не существует.'; break; } throw new ErrorApi($text, ErrorApi::INCORRECT_INPUT); } $filter = null; continue; } $filter['value'] = $fetch[$filter['name']][$compare_value]; } unset($filter); $filters = array_filter($filters); }
protected function parse_raw_term() { $term = new Text($this->raw_term); return $term->lower()->trim()->cut_on("\n\r"); }