示例#1
0
文件: api.php 项目: uzura8/flockbird
 /**
  * Change timeline follow status
  * 
  * @access  public
  * @param   int  $id  timeline id
  * @return  Response (json)
  * @throws  Exception in Controller_Base::controller_common_api
  * @see  Controller_Base::controller_common_api
  */
 public function post_update_follow_status($id = null)
 {
     $this->controller_common_api(function () use($id) {
         $this->response_body['errors']['message_default'] = term('form.fallow') . '状態の変更に失敗しました。';
         $id = intval(\Input::post('id') ?: $id);
         $timeline = Model_Timeline::check_authority($id);
         $this->check_browse_authority($timeline->public_flag, $timeline->member_id);
         if ($timeline->member_id == $this->u->id) {
             throw new \HttpBadRequestException();
         }
         // 自分のタイムラインはフォロー解除不可
         \DB::start_transaction();
         $is_registerd = (int) Model_MemberFollowTimeline::change_registered_status4unique_key(array('member_id' => $this->u->id, 'timeline_id' => $timeline->id));
         \DB::commit_transaction();
         $data = array('result' => $is_registerd, 'message' => $is_registerd ? term('follow') . 'しました。' : term('follow') . 'を解除しました。', 'html' => icon_label($is_registerd ? 'followed' : 'do_follow', 'both', false));
         $this->set_response_body_api($data);
     });
 }
示例#2
0
 public static function get_list($self_member_id = 0, $target_member_id = 0, $is_mytimeline = false, $viewType = null, $max_id = 0, $limit = 0, $is_latest = true, $is_desc = true, $since_id = 0)
 {
     $follow_member_ids = null;
     $friend_member_ids = null;
     if (!$self_member_id || $target_member_id) {
         $is_mytimeline = false;
     }
     if ($is_mytimeline) {
         list($follow_member_ids, $friend_member_ids) = Site_Util::get_member_relation_member_ids($self_member_id, $viewType);
     }
     if (!$limit) {
         $limit = (int) \Config::get('timeline.articles.limit');
     }
     if ($limit > \Config::get('timeline.articles.limit_max')) {
         $limit = \Config::get('timeline.articles.limit_max');
     }
     $sort = array('id' => $is_desc ? 'desc' : 'asc');
     $query = Model_TimelineCache::query()->select('id', 'member_id', 'timeline_id', 'type', 'comment_count', 'like_count');
     if ($max_id || $since_id) {
         $query->and_where_open();
     }
     if ($is_mytimeline) {
         if ($follow_timeline_ids = Model_MemberFollowTimeline::get_cols('timeline_id', array('member_id' => $self_member_id))) {
             $query->or_where_open();
             $query->and_where_open();
             self::set_mytimeline_cond($query, $self_member_id, $follow_member_ids);
             $query->and_where_close();
             $query->where('timeline_id', 'in', $follow_timeline_ids);
             $query->where('is_follow', 1);
             $query->or_where_close();
             $query->or_where_open();
             $query->and_where_open();
             self::set_mytimeline_cond($query, $self_member_id, $follow_member_ids);
             $query->and_where_close();
             $query->where('timeline_id', 'not in', $follow_timeline_ids);
             $query->where('is_follow', 0);
             $query->or_where_close();
         } else {
             $query->and_where_open();
             self::set_mytimeline_cond($query, $self_member_id, $follow_member_ids);
             $query->and_where_close();
             $query->where('is_follow', 0);
         }
     } else {
         $is_mypage = $self_member_id && $target_member_id && $target_member_id == $self_member_id;
         $basic_cond = \Site_Model::get_where_params4list($target_member_id, $self_member_id, $is_mypage);
         $query->where($basic_cond);
         $query->where('is_follow', 0);
     }
     if ($max_id || $since_id) {
         $query->and_where_close();
     }
     $is_reverse = false;
     if ($limit && $is_latest && !$is_desc) {
         $is_desc = true;
         $is_reverse = true;
     }
     if ($since_id) {
         $query->where('id', '>', $since_id);
     }
     if ($max_id) {
         $query->where('id', '<=', $max_id);
     }
     $query->order_by($sort);
     if ($limit) {
         $rows_limit = $limit + 1;
         $query->rows_limit($rows_limit);
     }
     $list = $query->get();
     $next_id = 0;
     if ($limit && count($list) > $limit) {
         $next_obj = array_pop($list);
         $next_id = $next_obj->id;
     }
     return array($list, $next_id);
 }