Example #1
0
 /**
  * To map user with device when user logs in
  * @param int $userId
  * @param string $deviceId
  * @param string $deviceType
  * @param string $pushToken
  * @return string $accessToken
  */
 public function mapUserAndDevice($userId, $deviceId, $deviceType, $pushToken)
 {
     $accessToken = $this->generateToken($userId, $deviceId);
     $dateTime = date('Y-m-d H:i:s');
     $data = array('user_id' => $userId, 'device_id' => $deviceId, 'access_token' => $accessToken, 'device_type' => $deviceType, 'device_push_token' => $pushToken, 'login_time' => $dateTime, 'status' => 1, 'created_at' => $dateTime);
     UsersLogin::where('device_id', '=', $deviceId)->update(array('status' => 0, 'logout_time' => $dateTime));
     UsersLogin::insert($data);
     return $accessToken;
 }
Example #2
0
 /**
  * Checking is the users login status according to the user id 
  * 
  * @param integer $userId
  * @return string
  */
 public static function checkUsersLoginStatus($userId)
 {
     if (!empty($userId)) {
         $userLoginStatus = UsersLogin::USER_VERY_ACTIVE;
         $currentDate = new \DateTime();
         $past7daysDate = (new \DateTime())->sub(new \DateInterval('P7D'));
         $past14daysDate = (new \DateTime())->sub(new \DateInterval('P14D'));
         $past30daysDate = (new \DateTime())->sub(new \DateInterval('P30D'));
         $query = UsersLogin::where('user_id', '=', $userId);
         $_7daysRecord = $query->whereBetween('login_time', array($past7daysDate->format('Y-m-d'), $currentDate->format('Y-m-d')))->get();
         if (!$_7daysRecord->count()) {
             $_14daysRecord = $query->whereBetween('login_time', array($past14daysDate->format('Y-m-d'), $past7daysDate->format('Y-m-d')))->get();
             if (!$_14daysRecord->count()) {
                 $_30daysRecord = $query->whereBetween('login_time', array($past30daysDate->format('Y-m-d'), $past14daysDate->format('Y-m-d')))->get();
                 return !$_30daysRecord->count() ? UsersLogin::USER_IN_ACTIVE : UsersLogin::USER_LITTLE_ACTIVE;
             }
             $userLoginStatus = UsersLogin::USER_ACTIVE;
         }
         return $userLoginStatus;
     }
 }