Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 62 |
| ViewwayService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
240.00 | |
0.00% |
0 / 62 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| __clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
| validateToken | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 21 |
|||
| updateVideoContentDetails | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| generateToken | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| getToken | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 17 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use stdClass; | |
| use com\linways\base\util\SecurityUtils; | |
| class ViewwayService extends BaseService | |
| { | |
| // /Condition 1 - Presence of a static member variable | |
| private static $_instance = null; | |
| private $mapper = []; | |
| // /Condition 2 - Locked down the constructor | |
| private function __construct() | |
| { | |
| $this->mapper = null; | |
| } | |
| // 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; | |
| } | |
| /** | |
| * | |
| * @param GetAllBatchesRequest $request | |
| * @return object|array|\com\linways\base\util\$objectList[] | |
| * @throws ProfessionalException | |
| * @author gadheyan | |
| */ | |
| public function validateToken($token,$userId,$type) | |
| { | |
| $sql = "SELECT userType FROM viewway_token where userId = '$userId' AND token = '$token' and is_active = 1"; | |
| try { | |
| $result = $this->executeQueryForObject($sql); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| if(!$result) | |
| { | |
| return null; | |
| } | |
| else | |
| { | |
| $response = new \stdClass(); | |
| $response->status = true; | |
| $response->userRole = ($result->userType == 'STAFF')?2:3; | |
| $response->uploadPrivilege = ($result->userType == 'STAFF')?true:false; | |
| $response->viewPrivilege = true; | |
| return $response; | |
| } | |
| } | |
| public function updateVideoContentDetails($contentId, $thumbnailURL) | |
| { | |
| return true; | |
| } | |
| public function generateToken($userId,$userType) | |
| { | |
| $token = SecurityUtils::getRandomString(); | |
| $query = "INSERT INTO viewway_token (token, userType, userId, issued_at) VALUES ( '$token', '$userType', $userId, utc_timestamp()); | |
| "; | |
| try { | |
| $res = $this->executeQueryForObject($query, true); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $token; | |
| } | |
| public function getToken($userId,$userType) | |
| { | |
| $query = "SELECT token from viewway_token where userId = $userId AND userType = '$userType' and is_active = 1"; | |
| try { | |
| $result = $this->executeQueryForObject($query); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| if(empty($result)) | |
| { | |
| $token = $this->generateToken($userId,$userType); | |
| return $token; | |
| } | |
| else | |
| { | |
| return $result->token; | |
| } | |
| } | |
| } |