Exemplo n.º 1
0
 protected function add_meta_data(&$data)
 {
     parent::add_meta_data($data);
     $ids = array();
     $users = array();
     foreach ($data as &$item) {
         $item['md5'] = false;
         $ids[] = $item['id'];
         $users[] = $item['id_user'];
     }
     if (!empty($users)) {
         $users = $this->db->get_table('user', array('id', 'login'), $this->db->array_in('id', $users), $users);
     }
     if (!empty($ids)) {
         $covers = $this->db->order('a.sortdate')->join('meta', 'm.item_type = 1 and m.meta_type = ' . Meta::ART_ARTIST . ' and m.id_item = a.id')->filter('meta', array('item_type = 1', 'id_item = id', 'meta_type = ' . Meta::STATE, 'meta = 4'), 'meta')->make_temp('art', array('m.meta', 'a.md5', 'a.sortdate'), $this->db->array_in('m.meta', $ids), $ids)->group('tmp.meta')->get_table('tmp', array('meta', 'md5'));
         foreach ($data as &$item) {
             foreach ($covers as $cover) {
                 if ($item['id'] == $cover['meta']) {
                     $item['md5'] = $cover['md5'];
                     break;
                 }
             }
             foreach ($users as $user) {
                 if ($item['id_user'] == $user['id']) {
                     $item['artist'] = $user['login'];
                     break;
                 }
             }
         }
         unset($item);
     }
 }
Exemplo n.º 2
0
Arquivo: Pack.php Projeto: 4otaku/api
 protected function add_meta_data(&$data)
 {
     parent::add_meta_data($data);
     $cover = array();
     $nocover = array();
     foreach ($data as &$item) {
         $item['md5'] = false;
         if (!empty($item['cover'])) {
             $cover[] = $item['cover'];
         } else {
             $nocover[] = $item['id'];
         }
     }
     if (!empty($nocover)) {
         $links = $this->db->order('order', 'asc')->group('id_pack')->get_table('art_pack_item', array('id_pack', 'id_art'), $this->db->array_in('id_pack', $nocover), $nocover);
         foreach ($data as &$item) {
             foreach ($links as $link) {
                 if ($item['id'] == $link['id_pack']) {
                     $item['cover'] = $link['id_art'];
                     $cover[] = $item['cover'];
                     break;
                 }
             }
         }
         unset($item);
     }
     if (!empty($cover)) {
         $covers = $this->db->get_table('art', array('id', 'md5'), $this->db->array_in('id', $cover), $cover);
         foreach ($data as &$item) {
             foreach ($covers as $cover) {
                 if ($item['cover'] == $cover['id']) {
                     $item['md5'] = $cover['md5'];
                     break;
                 }
             }
         }
         unset($item);
     }
 }
Exemplo n.º 3
0
Arquivo: Art.php Projeto: 4otaku/api
 protected function get_filters($params)
 {
     if (!empty($params['filter']) && is_array($params['filter'])) {
         $this->parse_date_filters($params['filter'], array('date'));
         foreach ($params['filter'] as &$filter) {
             if (!isset($filter['name']) || !isset($filter['type']) || !isset($filter['value'])) {
                 continue;
             }
             if (in_array($filter['name'], $this->local_filtered_variables) && Meta::parse($filter['type'])) {
                 if ($filter['name'] == 'date') {
                     $filter['name'] = 'sortdate';
                     $filter['value'] = $this->db->unix_to_date($filter['value']);
                 }
                 if ($filter['name'] == 'user') {
                     $filter['name'] = 'id_user';
                     $value = $this->db->get_field('user', 'id', 'login = ?', $filter['value']);
                     if (empty($value) && Meta::parse($filter['type']) == Meta::IS) {
                         throw new ErrorApi('Пользователя ' . $filter['value'] . ' не существует.', ErrorApi::INCORRECT_INPUT);
                     }
                     $filter['value'] = $value;
                 }
                 $this->local_filters[] = $filter['name'] . ' ' . Meta::parse($filter['type']) . ' ?';
                 $this->local_filter_vars[] = $filter['value'];
                 $filter = null;
             }
         }
         unset($filter);
     }
     return parent::get_filters($params);
 }