/**
  * Follows the owner object
  * 
  * @param int $userId
  * @return boolean 
  */
 public function follow($userId = "", $withNotifications = true)
 {
     if ($userId == "") {
         $userId = Yii::app()->user->id;
     }
     // User cannot follow himself
     if (get_class($this->getOwner()) == 'User' && $this->getOwner()->getPrimaryKey() == $userId) {
         return false;
     }
     $follow = $this->getFollowRecord($userId);
     if ($follow === null) {
         $follow = new UserFollow();
         $follow->user_id = $userId;
         $follow->object_id = $this->getOwner()->getPrimaryKey();
         $follow->object_model = get_class($this->getOwner());
     }
     if ($withNotifications) {
         $follow->send_notifications = 1;
     } else {
         $follow->send_notifications = 0;
     }
     if (!$follow->save()) {
         return false;
     }
     return true;
 }
Beispiel #2
0
 /**
  * Add a user to follower list of other and send notifcation
  *
  * @author Kuldeep Dangi <*****@*****.**>
  */
 public function actionFollowUser($userId, $followerId)
 {
     $model = new UserFollow();
     $userFollowingObj = Users::model()->findByPk($userId);
     $userObj = Users::model()->findByPk($followerId);
     if ($userFollowingObj && $userObj) {
         $isRecrodExist = $model->findByAttributes(array('id_follower' => $followerId, 'id_following' => $userId));
         if ($isRecrodExist) {
             $this->result['success'] = true;
         } else {
             $model->attributes = array('id_follower' => $followerId, 'id_following' => $userId);
             if ($model->validate() && $model->save()) {
                 $notificationObj = new Notifications();
                 $notificationObj->addNotification(array('byUserId' => $userId, 'user_id' => $followerId, 'type' => 'FOLLOW'));
                 $notificationObj->sendPushNotification(array('deviceToken' => $userObj->deviceToken, 'deviceType' => $userObj->deviceType, 'message' => $userFollowingObj->username . ' has started following you.'));
                 $this->result['success'] = true;
                 $this->getUserInformation($userId);
                 $this->result['message'] = 'Record saved successfuly.';
             } else {
                 $this->result['message'] = 'Invalid Data.';
             }
         }
     } else {
         $this->result['message'] = 'Invalid data.';
     }
     $this->sendResponse($this->result);
 }
Beispiel #3
0
 public function AddFollow($userid, $roomid, $flag = '')
 {
     if (!$flag) {
         //room有这个直播的前提,先查询follow里是否已添加,是的话
         $getRes = UserFollow::model()->find(array('condition' => 'userid=' . $userid . ' AND roomid=' . $roomid));
         if (!$getRes) {
             $flag = 1;
         }
     } else {
         //room里没有这个直播,首次添加,用户直接保存。
         $flag = 1;
     }
     if ($flag) {
         $newFollow = new UserFollow();
         $newFollow->roomid = $roomid;
         $newFollow->userid = $userid;
         $newFollow->addtime = time();
         $newFollow->save();
         return '1';
         //用户列表里新增该直播间
     } else {
         return '2';
         //用户列表里已添加该直播间。
     }
     /*
     if($flag){
     	$newFollow=new UserFollow();
     	$newFollow->roomid=$roomid;
     	$newFollow->userid=$userid;
     	$newFollow->addtime=time();
     	$newFollow->save();
     }else{
     	$getRes=UserFollow::model()->find(array('condition'=>'userid='.$userid.' AND roomid='.$roomid));
     if($getRes){
     	return '1';
     }else{
     	$newFollow=new UserFollow();
     	$newFollow->roomid=$roomid;
     	$newFollow->userid=$userid;
     	$newFollow->addtime=time();
     	$newFollow->save();
     	return '1';
     }
     }
     */
 }