示例#1
0
 /**
  * Check whether user is logged-in
  * @param int $user_id
  * @param string $user_sid session
  * @param bool $touch prolong session
  * @return bool
  */
 private function checkSession($user_id, $user_sid, $touch = false)
 {
     $user_id = (int) $user_id;
     if (!defined('USER_ID')) {
         define('USER_ID', $user_id);
     }
     // Prolong session
     if ($touch) {
         $sessions = new UsersSessionEntityRepository();
         $sessions->setWhereSid($user_sid);
         /**
          * @var UsersSessionEntity $session
          */
         $session = $sessions->getFirstObjectFromCollection();
         if ($session) {
             $session->setTs(NOW);
             $session->save();
         }
     }
     // Check session for current user exists
     $sessions = new UsersSessionEntityRepository();
     $sessions->setWhereUserId($user_id);
     $sessions->setWhereSid($user_sid);
     return $sessions->hasAnyObjectInCollection();
 }