public function process() { $id_item = (int) $this->get('id_item'); $area = Meta::parse($this->get('area')); $parent = (int) $this->get('parent'); $name = (string) $this->get('name'); $mail = (string) $this->get('mail'); $text = (string) $this->get('text'); $text = trim($text); if (empty($text) || empty($id_item) || empty($area)) { throw new ErrorApi(ErrorApi::MISSING_INPUT); } if (!empty($parent) && !$this->db->get_count('comment', $parent)) { throw new ErrorApi(ErrorApi::COMMENT_PARENT_DO_NOT_EXIST); } if ($parent) { $root = $this->db->get_field('comment', 'rootparent', $parent); if (!$root) { $root = $parent; } } else { $root = 0; } $name = $name ? $name : $this->db->get_field('user', 'login', 1); $mail = $mail ? $mail : $this->db->get_field('user', 'email', 1); $time = time(); $this->db->insert('comment', array('parent' => $parent, 'rootparent' => $root, 'id_item' => $id_item, 'area' => $area, 'username' => $name, 'email' => $mail, 'ip' => ip2long($this->get_ip()), 'cookie' => $this->get_cookie(), 'text' => $text, 'sortdate' => $this->db->unix_to_date($time))); $this->db->update('meta', array('meta' => DatabaseAction::get(DatabaseAction::INCREMENT)), 'item_type = ? and id_item = ? and meta_type = ?', array(Meta::ART, $id_item, Meta::COMMENT_COUNT)); $this->add_single_meta(Meta::ART, $id_item, Meta::COMMENT_DATE, $time); $this->set_success(true); }
protected function translation_date() { $meta_type = Meta::parse('translation_date'); $dates = $this->db->group('id_art')->get_vector('art_translation', array('id_art', 'max(`sortdate`)'), 'state = 1'); foreach ($dates as $id => $date) { if ($this->db->get_count('meta', 'item_type = 1 and meta_type = ? and id_item = ?', array($meta_type, $id))) { $this->db->update('meta', array('meta' => strtotime($date)), 'item_type = 1 and meta_type = ? and id_item = ?', array($meta_type, $id)); } else { $this->db->insert('meta', array('item_type' => 1, 'meta_type' => $meta_type, 'id_item' => $id, 'meta' => strtotime($date))); } } return memory_get_usage(); }
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); }