Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 27
MobileUserService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
72.00
0.00% covered (danger)
0.00%
0 / 27
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 2
 __clone
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 2
 getInstance
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 5
 getFCMTokenByUserIDandUserType
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 18
<?php
/**
 * Created by PhpStorm.
 * User: jithinvijayan
 * Date: 15/03/18
 * Time: 3:27 PM
 */
//DEPRECRATED - FOR OLD MOBILE VERSION
//DEPRECRATED - FOR OLD MOBILE VERSION
namespace com\linways\core\ams\professional\service\mobile;
use com\linways\core\ams\professional\exception\mobile\MobileException;
use com\linways\core\ams\professional\service\BaseService;
class MobileUserService extends BaseService
{
    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;
    }
    /**
     * return fcm token by user id and user name
     * @param integer $userId
     * @param string $userType
     * @return null
     * @throws MobileException
     */
    public function getFCMTokenByUserIDandUserType($userId, $userType)
    {
        $userDetails = null;
        $userId = $this->realEscapeString($userId);
        $userType = $this->realEscapeString($userType);
        if (empty($userId)) {
            throw new MobileException("Invalid user id", MobileException::INVALID_USER_ID);
        }
        if (empty($userType)) {
            throw new MobileException("Invalid user type", MobileException::INVALID_USER_TYPE);
        }
        $sql = "SELECT fcm_token FROM mobile_login_tokens WHERE user_id=$userId AND user_type='" . $userType . "'";
        try {
            $userDetails = $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new MobileException($e->getMessage(), $e->getCode());
        }
        return $userDetails;
    }
}