123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/6/23
- * Time: 下午4:26
- */
- require_once (BASE_ROOT_PATH . '/helper/relation/mem_relation.php');
- require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
- require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
- class relation_helper
- {
- static public function onLogin($member_id)
- {
- try
- {
- if(!relation\mem_relation::use_frineds_relation) {
- $relation = new relation\mem_relation($member_id);
- $relation->pass_subscribe();
- }
- }
- catch (Exception $ex)
- {
- Log::record("{$ex->getMessage()} member_id = {$member_id}",Log::ERR);
- }
- }
- static public function onRegister($user)
- {
- try
- {
- if(!relation\mem_relation::use_frineds_relation) {
- $relation = new relation\mem_relation($user);
- $relation->pass_subscribe();
- }
- }
- catch (Exception $ex)
- {
- Log::record("{$ex->getMessage()} member_id = {$user}",Log::ERR);
- }
- }
- static public function onUpContacts($member_id,$contacts)
- {
- try
- {
- $relation = new relation\mem_relation($member_id);
- $relation->subscribe_contacts($contacts);
- }
- catch (Exception $ex)
- {
- Log::record("{$ex->getMessage()} member_id = {$member_id}",Log::ERR);
- }
- }
- static public function onInvite($me_id,$user_id)
- {
- try
- {
- if($me_id == $user_id) {
- return false;
- }
- $relation = new relation\mem_relation($me_id);
- return $relation->invite($user_id);
- }
- catch (Exception $ex)
- {
- Log::record("onInvite: {$ex->getMessage()} param = {$me_id},{$user_id}",Log::ERR);
- return false;
- }
- }
- static public function subscribed($me_id,$someone_id)
- {
- try
- {
- $me_id = intval($me_id);
- $someone_id = intval($someone_id);
- if($me_id == $someone_id) {
- return false;
- }
- $relation = new relation\mem_relation($me_id);
- return $relation->is_follower($someone_id);
- }
- catch (Exception $ex)
- {
- Log::record("onInvite: {$ex->getMessage()} param = {$me_id},{$someone_id}");
- return false;
- }
- }
- static public function onSubscribe($me_id,$someone_id)
- {
- try
- {
- $me_id = intval($me_id);
- $someone_id = intval($someone_id);
- if($me_id == $someone_id) {
- return false;
- }
- $relation = new relation\mem_relation($me_id);
- $ret = $relation->subscribe($someone_id);
- if($ret == true)
- {
- $someone_relation = new relation\mem_relation($someone_id);
- $someone_relation->pass_subscribe();
- $publisher = new message\publisher();
- $publisher->add_follow($someone_id,[$me_id]);
- $minfo = new member_info($me_id);
- push_helper::notice_subscribe($someone_id,$minfo);
- }
- return $ret;
- }
- catch (Exception $ex)
- {
- Log::record("onInvite: {$ex->getMessage()} param = {$me_id},{$someone_id}",Log::ERR);
- return false;
- }
- }
- static public function onAccept($me_id,$someone_id)
- {
- try
- {
- $relation = new relation\mem_relation($me_id);
- return $relation->pass_onesub($someone_id);
- }
- catch (Exception $ex) {
- Log::record("onAccept: {$ex->getMessage()} param = {$me_id},{$someone_id}",Log::ERR);
- return false;
- }
- }
- static public function onUnSubscribe($me_id,$someone_id)
- {
- try
- {
- if($me_id == $someone_id) {
- return false;
- }
- $relation = new relation\mem_relation($me_id);
- $ret = $relation->unsubscribe($someone_id);
- if($ret == true) {
- $publisher = new message\publisher();
- $publisher->del_follow($someone_id,[$me_id]);
- }
- return $ret;
- }
- catch (Exception $ex)
- {
- $msg = $ex->getMessage();
- Log::record("onInvite: {$msg} param = {$me_id},{$someone_id}");
- return false;
- }
- }
- //关注我的
- static public function subscriber($member_id)
- {
- try
- {
- $relation = new relation\mem_relation($member_id);
- return $relation->subscriber();
- }
- catch (Exception $ex)
- {
- $msg = $ex->getMessage();
- Log::record("{$msg} member_id = {$member_id}");
- return array();
- }
- }
- static public function follower($member_id)
- {
- try
- {
- $relation = new relation\mem_relation($member_id);
- return $relation->follower();
- }
- catch (Exception $ex)
- {
- $msg = $ex->getMessage();
- Log::record("{$msg} member_id = {$member_id}");
- return [];
- }
- }
- static public function friends($member_id)
- {
- try
- {
- $relation = new relation\mem_relation($member_id);
- $subscriber = $relation->subscriber();
- $follower = $relation->follower();
- return array_merge($subscriber,$follower);
- }
- catch (Exception $ex)
- {
- $msg = $ex->getMessage();
- Log::record("{$msg} member_id = {$member_id}");
- return [];
- }
- }
- static public function is_follow($me,$other)
- {
- try
- {
- $relation = new relation\mem_relation($me);
- return $relation->is_follower($other);
- }
- catch (Exception $ex)
- {
- $msg = $ex->getMessage();
- Log::record("is_follow {$msg} member_id = {$me}");
- return false;
- }
- }
- static public function is_friends($left,$right)
- {
- try{
- $l = new relation\mem_relation($left);
- $r = new relation\mem_relation($right);
- return $l->is_friends($right) && $r->is_friends($left);
- }
- catch (Exception $ex)
- {
- Log::record(__METHOD__ . " {$ex->getMessage()}",Log::ERR);
- return false;
- }
- }
- }
|