/**
  * check if last notification for a user
  * is from userId, for objectId
  * @param  int   $userId
  * @param  array $matches array containing properties to match with
  * @return bool
  */
 protected function checkLastNotification($userId, $matches)
 {
     $rez = false;
     //save current user id
     $currentUser = $_SESSION['user']['id'];
     $_SESSION['user']['id'] = $userId;
     $api = new \CB\Api\Notifications();
     //check if counts are not empty
     $countResult = $api->getNewCount(array());
     if ($countResult['success'] !== true || empty($countResult['count'])) {
         return $rez;
     }
     //check the last notification with given $matches
     $n = $this->getLastNotification($userId);
     if (!empty($n)) {
         $rez = true;
         foreach ($matches as $k => $v) {
             $rez = $rez && $n[$k] == $v;
         }
     }
     //restore previous user id
     $_SESSION['user']['id'] = $currentUser;
     return $rez;
 }
Esempio n. 2
0
 /**
  * check if last notification for a user
  * is from userId, for objectId
  * @param  int   $userId
  * @param  array $matches array containing properties to match with
  * @return bool
  */
 protected function checkLastNotification($userId, $matches)
 {
     $rez = false;
     //save current user id
     $currentUser = $_SESSION['user']['id'];
     \CB\User::setAsLoged($userId, $_SESSION['key']);
     //$_SESSION['user']['id'] = $userId;
     $api = new \CB\Api\Notifications();
     //check if counts are not empty
     $countResult = $api->getNew(array());
     if ($countResult['success'] !== true || empty($countResult['data'])) {
         trigger_error(print_r($countResult, true), E_USER_ERROR);
         return $rez;
     }
     //check the last notification with given $matches
     $n = $this->getLastNotification($userId);
     if (!empty($n)) {
         $rez = true;
         foreach ($matches as $k => $v) {
             $rez = $rez && $n[$k] == $v;
         }
     }
     //restore previous user id
     //$_SESSION['user']['id'] = $currentUser;
     \CB\User::setAsLoged($currentUser, $_SESSION['key']);
     if (!$rez) {
         trigger_error(print_r($n, true), E_USER_ERROR);
     }
     return $rez;
 }