protected function add_meta_data(&$data) { parent::add_meta_data($data); $ids = array(); foreach ($data as &$item) { $ids[] = $item['id']; $item['comment'] = array(); $item['comment_count'] = 0; } $comments = $this->db->order('sortdate')->get_table('comment', array('id', 'id_item', 'username', 'email', 'text', 'sortdate'), 'area = 1 and deleted = 0 and ' . $this->db->array_in('id_item', $ids), $ids); foreach ($comments as $comment) { foreach ($data as &$item) { if ($item['id'] == $comment['id_item']) { $comment['avatar'] = md5($comment['email']); unset($comment['email']); unset($comment['id_item']); if (count($item['comment']) < 5) { $item['comment'][] = $comment; } $item['comment_count']++; continue 2; } } unset($item); } }
protected function add_meta_data(&$data) { parent::add_meta_data($data); $ids = array(); $users = array(); foreach ($data as $item) { $ids[] = $item['id']; $users[] = $item['id_user']; } $users = array_unique($users); $ratings = $this->db->get_table('meta', array('id_item', 'meta'), 'm.item_type = 1 and m.meta_type = ' . Meta::ART_RATING . ' and ' . $this->db->array_in('m.id_item', $ids), $ids); $users = $this->db->get_table('user', array('id', 'login'), $this->db->array_in('id', $users), $users); foreach ($data as &$item) { foreach ($ratings as $rating) { if ($item['id'] == $rating['id_item']) { $item['rating'] = $rating['meta']; break; } } foreach ($users as $user) { if ($item['id_user'] == $user['id']) { $item['user'] = $user['login']; break; } } } unset($item); }
protected function add_meta_data(&$data) { parent::add_meta_data($data); $ids = array(); foreach ($data as &$item) { $ids[] = $item['id']; $item['translation_count'] = 0; $item['translator'] = array(); } unset($item); $translation_count = $this->db->group('id_art')->get_vector('art_translation', array('id_art', 'count(*)'), 'state = 1 and ' . $this->db->array_in('id_art', $ids), $ids); $translators = $this->db->order('at.sortdate', 'asc')->join('user', 'u.id = at.id_user')->get_table('art_translation', array('at.id_art', 'u.login'), 'state != 3 and ' . $this->db->array_in('at.id_art', $ids), $ids); foreach ($translation_count as $id_art => $count) { foreach ($data as &$item) { if ($item['id'] == $id_art) { $item['translation_count'] = $count; continue 2; } } unset($item); } foreach ($translators as $translator) { foreach ($data as &$item) { if ($item['id'] == $translator['id_art']) { $item['translator'][] = $translator['login']; continue 2; } } unset($item); } foreach ($data as &$item) { $item['translator'] = array_unique($item['translator']); } unset($item); }