Example #1
0
 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);
 }
Example #2
0
File: Meta.php Project: 4otaku/api
 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();
 }
Example #3
0
 protected function parse_date_filters(&$filters, $date_keys)
 {
     $add = array();
     foreach ($filters as $key => &$filter) {
         if (!in_array($filter['name'], $date_keys)) {
             continue;
         }
         try {
             $date = new \DateTime($filter['value']);
         } catch (\Exception $e) {
             $filter = null;
             continue;
         }
         switch (Meta::parse($filter['type'])) {
             case Meta::IS:
                 $add[] = array('name' => $filter['name'], 'type' => 'more', 'value' => $date->getTimestamp() - 1);
                 $add[] = array('name' => $filter['name'], 'type' => 'less', 'value' => $date->add(new \DateInterval('P1D'))->getTimestamp());
                 break;
             case Meta::NOT:
                 // @TODO: придумать что-нибудь. Текщая система фильтров не позволяет оператор OR
                 break;
             case Meta::MORE:
                 $add[] = array('name' => $filter['name'], 'type' => 'more', 'value' => $date->add(new \DateInterval('P1D'))->getTimestamp() - 1);
                 break;
             case Meta::LESS:
                 $add[] = array('name' => $filter['name'], 'type' => 'less', 'value' => $date->getTimestamp());
                 break;
             default:
                 break;
         }
         $filter = null;
     }
     foreach ($add as $item) {
         $filters[] = $item;
     }
 }