/** * Get list by member * * @access public * @param int $member_id target member_id * @return Response (html) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function get_member($member_id = null) { $this->api_accept_formats = array('html'); $this->controller_common_api(function () use($member_id) { $member_id = \Input::get('member_id', 0) ?: $member_id; list($is_mypage, $member) = $member_id ? $this->check_auth_and_is_mypage($member_id, true) : array(null, false); list($limit, $page) = $this->common_get_pager_list_params(conf('articles.limit', 'album'), conf('articles.limit_max', 'album')); $data = Site_Model::get_album_images($limit, $page, get_uid(), $member, $is_mypage, null, $this->format != 'html'); $data['liked_album_image_ids'] = conf('like.isEnabled') && \Auth::check() ? \Site_Model::get_liked_ids('album_image', $this->u->id, $data['list']) : array(); if ($this->format == 'html') { if ($member) { $data['member'] = $member; } } else { $list_array = array(); foreach ($data['list'] as $key => $obj) { $row = $obj->to_array(); $row['album']['member'] = \Model_Member::get_one_basic4id($obj->album->member_id); $list_array[] = $row; } // json response $data = $list_array; } $this->set_response_body_api($data, $this->format == 'html' ? 'image/_parts/list' : null); }); }
/** * Get comments common api controller * * @access protected * @param string $parent_table target parent table * @param int $parent_id target parent record id * @param string $public_flag_related related table for check brows authority * @param array $parent_member_id_relateds related table and property array for check edit authority * @param int $limit record count for get * @param int $limit_max record limited count for get * @param string $parent_id_prop parent table id property. * @return Response (json|html) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ protected function api_get_comments_common($parent_table, $parent_id, $public_flag_related = null, $parent_member_id_relateds = array(), $limit = 0, $limit_max = 0, $parent_id_prop = null) { $this->api_accept_formats = array('json', 'html'); $this->controller_common_api(function () use($parent_table, $parent_id, $public_flag_related, $parent_member_id_relateds, $limit, $limit_max, $parent_id_prop) { $comment_table = $parent_table . '_comment'; $comment_model = Site_Model::get_model_name($comment_table); $parent_id = (int) $parent_id; $parent_model = Site_Model::get_model_name($parent_table); $parent_obj = $parent_model::check_authority($parent_id, 0, $public_flag_related); if (!$parent_id_prop) { $parent_id_prop = $parent_table . '_id'; } $auther_member_ids = Util_Orm::get_related_member_ids($parent_obj, $parent_member_id_relateds); foreach ($auther_member_ids as $member_id) { $this->check_browse_authority($public_flag_related ? $parent_obj->{$public_flag_related}->public_flag : $parent_obj->public_flag, $member_id); } $member_profile_image_size = Input::get('image_size') ?: 'M'; if (!in_array($member_profile_image_size, array('SS', 'S', 'M'))) { $member_profile_image_size = 'M'; } $default_params = array('latest' => 1, 'limit' => $limit ?: conf('view_params_default.list.comment.limit')); list($limit, $is_latest, $is_desc, $since_id, $max_id) = $this->common_get_list_params($default_params, $limit_max ?: conf('view_params_default.list.comment.limit_max')); list($list, $next_id, $all_comment_count) = $comment_model::get_list(array($parent_id_prop => $parent_id), $limit, $is_latest, $is_desc, $since_id, $max_id, null, $this->format == 'json', $this->format == 'json'); if (conf('like.isEnabled')) { $liked_ids = \Auth::check() ? \Site_Model::get_liked_ids($comment_table, $this->u->id, $list) : array(); } $api_uri_path_prefix = Site_Model::convert_table2controller_path($parent_table); $get_uri = sprintf('%s/comment/api/list/%d.json', $api_uri_path_prefix, $parent_id); $data = array('list' => $list, 'parent' => $parent_obj, 'next_id' => $next_id, 'delete_uri' => sprintf('%s/comment/api/delete.json', $api_uri_path_prefix), 'image_size' => $member_profile_image_size); if ($since_id) { $data['since_id'] = $since_id; } if ($this->format == 'html') { $data += array('auther_member_ids' => $auther_member_ids, 'list_more_box_attrs' => array('id' => 'listMoreBox_comment_' . $parent_id, 'data-uri' => $get_uri, 'data-list' => '#comment_list_' . $parent_id), 'counter_selector' => '#comment_count_' . $parent_id); if (conf('like.isEnabled')) { $data['liked_ids'] = $liked_ids; } } else { $data += array('count' => $all_comment_count, 'get_uri' => $get_uri); $data['parent'] = array('id' => $parent_id, 'member_id' => $parent_member_id_relateds ? array_shift($auther_member_ids) : $parent_obj->member_id); $data['image_size'] = array('key' => $member_profile_image_size, 'value' => conf('upload.types.img.types.m.sizes.' . $member_profile_image_size)); foreach ($list as $key => $row) { $row['body'] = convert_body($row['body'], array('nl2br' => conf('view_params_default.comment.nl2br'), 'is_truncate' => false, 'mention2link' => true)); $row['member'] = Model_Member::get_one_basic4id($row['member_id']); if (conf('like.isEnabled')) { $row['get_like_members_uri'] = sprintf('%s/comment/like/api/member/%d.html', $api_uri_path_prefix, $row['id']); $row['post_like_uri'] = sprintf('%s/comment/like/api/update/%d.json', $api_uri_path_prefix, $row['id']); $row['is_liked'] = \Auth::check() && in_array($row['id'], $liked_ids) ? 1 : 0; $row['comment_table'] = $comment_table; } $list[$key] = $row; } $data['list'] = $list; } $this->set_response_body_api($data, $this->format == 'html' ? '_parts/comment/list' : null); }); }
public static function set_optional_data2album_image_list($album_images, $start_album_image_id = 0) { $list_array = array(); $list_array_post = array(); $is_set_main = $start_album_image_id ? false : true; foreach ($album_images as $key => $row) { if (!$is_set_main && $key == $start_album_image_id) { $is_set_main = true; } $row['album'] = Model_Album::get_one_basic4id($row['album_id']); $row['member'] = \Model_Member::get_one_basic4id($row['album']['member_id']); if ($is_set_main) { $list_array[] = $row; } else { $list_array_post[] = $row; } } return array_merge($list_array, $list_array_post); }
/** * Get notice list * * @access public * @return Response (json) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function get_list() { $this->controller_common_api(function () { list($limit, $page) = $this->common_get_pager_list_params(\Config::get('notice.articles.limit'), \Config::get('notice.articles.limit_max')); $data = Model_NoticeStatus::get_pager_list4member_id($this->u->id, $limit, $page); $list_array = array(); foreach ($data['list'] as $key => $obj) { $row = $obj->to_array(); $row['members_count'] = Model_NoticeMemberFrom::get_count4notice_id($row['notice_id'], $this->u->id); $row['members'] = array(); $notice_member_froms = Model_NoticeMemberFrom::get4notice_id($row['notice_id'], \Config::get('notice.noticeMemberFrom.limit'), $this->u->id); foreach ($notice_member_froms as $notice_member_from) { $row['members'][] = \Model_Member::get_one_basic4id($notice_member_from->member_id); } $row['is_read'] = (int) $row['is_read']; $list_array[] = $row; } // json response $data['list'] = $list_array; $data['is_detail'] = (bool) \Input::get('is_detail', 0); $this->set_response_body_api($data); }); }