Exemplo n.º 1
0
 protected function check_auth_and_is_mypage($member_id = 0, $is_api = false)
 {
     $is_mypage = false;
     $access_from = 'guest';
     $member = null;
     $member_id = (int) $member_id;
     if (!$member_id) {
         $this->check_auth_and_redirect(false);
         $is_mypage = true;
         $member = $this->u;
         $access_from = 'self';
     } elseif ($this->check_is_mypage($member_id)) {
         $is_mypage = true;
         $member = $this->u;
         $access_from = 'self';
     } else {
         $member = Model_Member::check_authority($member_id);
         if (Auth::check()) {
             $access_from = 'member';
             if (Model_MemberRelation::check_relation('friend', $this->u->id, $member_id)) {
                 $access_from = 'friend';
             }
         }
     }
     return array($is_mypage, $member, $access_from);
 }
Exemplo n.º 2
0
 /**
  * post_update
  * 
  * @access  public
  * @return  Response (json)
  */
 public function post_update($member_id_to = null, $relation_type = null)
 {
     $this->controller_common_api(function () use($member_id_to, $relation_type) {
         $this->response_body['errors']['message_default'] = sprintf('%sの%sに%sしました。', term('follow'), term('form.update'), term('site.failure'));
         if (!self::check_relation_type($relation_type)) {
             throw new HttpNotFoundException();
         }
         if (!is_null(Input::post('id'))) {
             $member_id_to = (int) Input::post('id');
         }
         $member = Model_Member::check_authority($member_id_to);
         if ($member_id_to == $this->u->id) {
             throw new HttpInvalidInputException();
         }
         $member_relation = Model_MemberRelation::get4member_id_from_to($this->u->id, $member_id_to);
         if (!$member_relation) {
             $member_relation = Model_MemberRelation::forge();
         }
         $prop = 'is_' . $relation_type;
         $status_before = (bool) $member_relation->{$prop};
         $status_after = !$status_before;
         \DB::start_transaction();
         $member_relation->{$prop} = $status_after;
         $member_relation->member_id_to = $member_id_to;
         $member_relation->member_id_from = $this->u->id;
         $member_relation->save();
         \DB::commit_transaction();
         $this->response_body['isFollow'] = (int) $status_after;
         $this->response_body['html'] = $status_after ? sprintf('<span class="glyphicon glyphicon-ok"></span> %s', term('followed')) : term('do_follow');
         $this->response_body['attr'] = $status_after ? array('class' => array('add' => 'btn-primary')) : array('class' => array('remove' => 'btn-primary'));
         $this->response_body['message'] = sprintf('%s%s', term('follow'), $status_after ? 'しました。' : 'を解除しました。');
         return $this->response_body;
     });
 }
Exemplo n.º 3
0
 public static function get_access_from_member_relation($member_id, $self_member_id = 0)
 {
     if (!$self_member_id) {
         return 'others';
     }
     if ($member_id == $self_member_id) {
         return 'self';
     }
     if (Model_MemberRelation::check_relation('friend', $self_member_id, $member_id)) {
         return 'friend';
     }
     return 'member';
 }
Exemplo n.º 4
0
 public static function get_member_relation_member_ids($member_id_from, $timeline_viewType = null)
 {
     $follow_member_ids = null;
     $friend_member_ids = null;
     $timeline_viewType = Site_Model::validate_timeline_viewType($timeline_viewType);
     switch ($timeline_viewType) {
         case 1:
             $follow_member_ids = \Model_MemberRelation::get_member_ids($member_id_from, 'is_follow');
             break;
         case 2:
             $friend_member_ids = \Model_MemberRelation::get_member_ids($member_id_from, 'is_friend');
             break;
         case 3:
             $follow_member_ids = \Model_MemberRelation::get_member_ids($member_id_from, 'is_follow');
             $friend_member_ids = \Model_MemberRelation::get_member_ids($member_id_from, 'is_friend');
             break;
         case 0:
         default:
             break;
     }
     return array($follow_member_ids, $friend_member_ids);
 }
Exemplo n.º 5
0
<?php

if (empty($size)) {
    $size = 'sm';
}
$default_attrs = array('class' => array('btn', 'btn-default', 'js-update_toggle', 'btn-' . $size), 'id' => 'btn_follow_' . $member_id_to, 'data-uri' => sprintf('member/relation/api/update/%d/follow.json', $member_id_to));
if (!isset($attrs)) {
    $attrs = array();
}
$attrs = array_merge_recursive($default_attrs, $attrs);
if (empty($name)) {
    $name = $default_attrs['id'];
}
if (Model_MemberRelation::check_relation('follow', $member_id_from, $member_id_to)) {
    $label = '<span class="glyphicon glyphicon-ok"></span> ' . term('followed');
    $attrs['class'][] = 'btn-primary';
} else {
    $label = term('do_follow');
    $attrs['class'][] = 'btn-default';
}
$attrs = Util_Array::conv_arrays2str($attrs);
echo Form::button($name, $label, $attrs);
Exemplo n.º 6
0
 /**
  * @dataProvider get_list_provider
  */
 public function test_get_list($self_member_id = null, $target_member_id = null, $is_mytimeline = null, $viewType = null, $max_id = null, $limit = null, $is_latest = null, $is_desc = null, $since_id = null)
 {
     $public_flags_all = \Site_Util::get_public_flags();
     list($test_list, $next_id) = Site_Model::get_list($self_member_id, $target_member_id, $is_mytimeline, $viewType, $max_id, $limit, $is_latest, $is_desc, $since_id);
     if (!$test_list) {
         return;
     }
     $is_limitted = count($test_list) <= self::$total_count;
     // test for limit
     if ($limit) {
         $this->assertTrue(count($test_list) <= $limit);
     } else {
         $this->assertTrue(count($test_list) <= \Config::get('timeline.articles.limit'));
     }
     $first_id = 0;
     $before_id = 0;
     foreach ($test_list as $timeline_cache) {
         if (!$first_id) {
             $first_id = $timeline_cache->id;
         }
         // member_id
         if ($target_member_id) {
             $this->assertEquals($target_member_id, $timeline_cache->member_id);
         }
         // test for public_flag
         if ($timeline_cache->public_flag == FBD_PUBLIC_FLAG_PRIVATE) {
             $this->assertEquals($self_member_id, $timeline_cache->member_id);
         }
         if (!$self_member_id) {
             $this->assertEquals($timeline_cache->public_flag, FBD_PUBLIC_FLAG_ALL);
         }
         if ($self_member_id && $timeline_cache->member_id != $self_member_id) {
             $this->assertTrue(in_array($timeline_cache->public_flag, array(FBD_PUBLIC_FLAG_ALL, FBD_PUBLIC_FLAG_MEMBER)));
         }
         if ($self_member_id && $self_member_id == $target_member_id) {
             $this->assertTrue(in_array($timeline_cache->public_flag, array(FBD_PUBLIC_FLAG_ALL, FBD_PUBLIC_FLAG_MEMBER, FBD_PUBLIC_FLAG_PRIVATE)));
         }
         if ($self_member_id && $target_member_id && $self_member_id != $target_member_id) {
             $this->assertTrue(in_array($timeline_cache->public_flag, array(FBD_PUBLIC_FLAG_ALL, FBD_PUBLIC_FLAG_MEMBER)));
         }
         if ($self_member_id && $is_mytimeline && $timeline_cache->member_id != $self_member_id) {
             $this->assertTrue(in_array($timeline_cache->public_flag, array(FBD_PUBLIC_FLAG_ALL, FBD_PUBLIC_FLAG_MEMBER)));
         }
         if ($self_member_id && $is_mytimeline && $timeline_cache->member_id == $self_member_id) {
             $this->assertTrue(in_array($timeline_cache->public_flag, array(FBD_PUBLIC_FLAG_ALL, FBD_PUBLIC_FLAG_MEMBER, FBD_PUBLIC_FLAG_PRIVATE)));
         }
         // test for viewType
         if ($is_mytimeline && $viewType == 1) {
             $member_ids = \Model_MemberRelation::get_member_ids($self_member_id, 'follow');
             $member_ids[] = $self_member_id;
             $this->assertTrue(in_array($timeline_cache->member_id, $member_ids));
         }
         if ($is_mytimeline && $viewType == 2) {
             $member_ids = \Model_MemberRelation::get_member_ids($self_member_id, 'firiend');
             $member_ids[] = $self_member_id;
             $this->assertTrue(in_array($timeline_cache->member_id, $member_ids));
         }
         // test for param max_id
         if ($max_id) {
             $this->assertTrue($timeline_cache->id <= $max_id);
         }
         // test for param since_id
         if ($since_id) {
             $this->assertTrue($timeline_cache->id > $since_id);
         }
         if ($before_id) {
             // test for param is_desc
             if ($is_desc) {
                 $this->assertTrue($timeline_cache->id < $before_id);
             } else {
                 $this->assertTrue($timeline_cache->id > $before_id);
             }
         }
         $before_id = $timeline_cache->id;
     }
     $last_id = $timeline_cache->id;
     // test for param is_latest
     if ($is_latest && !$is_limitted) {
         $this->assertTrue($first_id == self::$total_last_id);
     }
     // test for return next_id
     if ($next_id) {
         if ($is_desc) {
             $this->assertTrue($next_id < $last_id);
         } else {
             $this->assertTrue($next_id > $last_id);
         }
     }
 }