Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 75 |
MobileNotificationService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
506.00 | |
0.00% |
0 / 75 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
__clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
|||
updateFCMTokenByLoginTokenIdAndUserType | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 24 |
|||
getFCMTokenByLoginTokenIDandUserType | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 21 |
|||
deleteFCMTokenByLoginTokenAndUserType | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 19 |
<?php | |
/** | |
* Created by PhpStorm. | |
* User: jithinvijayan | |
* Date: 13/02/18 | |
* Time: 6:07 PM | |
*/ | |
//DEPRECRATED - FOR OLD MOBILE VERSION | |
//DEPRECRATED - FOR OLD MOBILE VERSION | |
namespace com\linways\core\ams\professional\service\mobile\notification; | |
use com\linways\core\ams\professional\dto\notification\MobileNotification; | |
use com\linways\core\ams\professional\exception\mobile\MobileException; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\service\BaseService; | |
use Exception; | |
class MobileNotificationService extends BaseService | |
{ | |
// /Condition 1 - Presence of a static member variable | |
private static $_instance = null; | |
// /Condition 2 - Locked down the constructor | |
private function __construct() | |
{ | |
} | |
// Prevent any oustide instantiation of this class | |
// /Condition 3 - Prevent any object or instance of that class to be cloned | |
private function __clone() | |
{ | |
} | |
// Prevent any copy of this object | |
// /Condition 4 - Have a single globally accessible static method | |
public static function getInstance() | |
{ | |
if (!is_object(self::$_instance))// or if( is_null(self::$_instance) ) or if( self::$_instance == null ) | |
{ | |
self::$_instance = new self(); | |
} | |
return self::$_instance; | |
} | |
/** | |
* Insert/Update FCM token by user login token id and user type | |
* @param MobileNotification $mobileNotification | |
* @return bool | |
* @throws ProfessionalException | |
* @throws MobileException | |
*/ | |
public function updateFCMTokenByLoginTokenIdAndUserType($mobileNotification) | |
{ | |
$status = false; | |
$mobileNotification = $this->realEscapeObject($mobileNotification); | |
if (!$mobileNotification->userId) | |
throw new MobileException("Staff id missing", MobileException::INVALID_USER_ID); | |
if (!$mobileNotification->loginTokenId) | |
throw new MobileException("Login token id missing", MobileException::INVALID_LOGIN_TOKEN_ID); | |
if (!$mobileNotification->userType) | |
throw new MobileException("User type missing", MobileException::INVALID_USER_TYPE); | |
if (!$mobileNotification->fcmToken) | |
throw new MobileException("FCM token missing", MobileException::INVALID_FCM_TOKEN); | |
if (!$mobileNotification->signature) | |
throw new MobileException("Invalid signature", MobileException::INVALID_SIGNATURE); | |
$sql = "UPDATE mobile_login_tokens set fcm_token='" . $mobileNotification->fcmToken . "', token_signature='" . $mobileNotification->signature . "' | |
WHERE user_id=$mobileNotification->userId AND user_type = '" . $mobileNotification->userType . "' | |
AND id = $mobileNotification->loginTokenId"; | |
try { | |
$status = $this->executeQueryForObject($sql, true); | |
$status = true; | |
} catch (Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $status; | |
} | |
/** | |
* Return fcm token by user login token id and user type | |
* @param String $loginTokenId | |
* @param String $userType | |
* @return null|String | |
* @throws MobileException | |
* @throws ProfessionalException | |
*/ | |
public function getFCMTokenByLoginTokenIDandUserType($loginTokenId, $userType, $userId) | |
{ | |
$FCMToken = null; | |
$loginTokenId = $this->realEscapeString($loginTokenId); | |
$userType = $this->realEscapeString($userType); | |
$userId = $this->realEscapeString($userId); | |
if (empty($loginTokenId)) | |
throw new MobileException("Invalid login token id", MobileException::INVALID_LOGIN_TOKEN_ID); | |
if (empty($userType)) | |
throw new MobileException("Invalid user type", MobileException::INVALID_USER_TYPE); | |
if (empty($userId)) | |
throw new MobileException("Invalid user id", MobileException::INVALID_USER_ID); | |
$sql = "SELECT fcm_token FROM `mobile_login_tokens` WHERE id=$loginTokenId AND user_type='" . $userType . "' AND user_id=$userId"; | |
try { | |
$result = $this->executeQueryForObject($sql); | |
} catch (Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
if ($result) | |
$FCMToken = $result->fcm_token; | |
return $FCMToken; | |
} | |
/** | |
* Delete fcm token by user id , user type and login token id | |
* @param MobileNotification $mobileNotification | |
* @return bool | |
* @throws MobileException | |
* @throws ProfessionalException | |
*/ | |
public function deleteFCMTokenByLoginTokenAndUserType($mobileNotification) | |
{ | |
$status = false; | |
$mobileNotification = $this->realEscapeObject($mobileNotification); | |
if (empty($mobileNotification->userid)) | |
throw new MobileException("Invalid user id", MobileException::INVALID_USER_ID); | |
if (empty($mobileNotification->usertype)) | |
throw new MobileException("Invalid user type", MobileException::INVALID_USER_TYPE); | |
if (empty($mobileNotification->loginTokenId)) | |
throw new MobileException("Invalid login token", MobileException::INVALID_LOGIN_TOKEN_ID); | |
$sql = "DELETE FROM mobile_login_tokens WHERE id=$mobileNotification->loginTokenId AND user_id=$mobileNotification->userId | |
AND user_type=$mobileNotification->userType"; | |
try { | |
$status = $this->executeQuery($sql); | |
$status = true; | |
} catch (Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $status; | |
} | |
} |