Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 86 |
| SessionService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 12 |
600.00 | |
0.00% |
0 / 86 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| __clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
| staffLogout | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 12 |
|||
| staffLogin | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| checkIfStaffIsLoggedIn | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 5 |
|||
| checkIfRolesAssignedForStaffInSessionAreCorrect | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 18 |
|||
| setLastActivitySessionVariableToCurrentTime | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| getStaffDetailsForLoggingIn | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| getStaffDetailsByIdForLoggingIn | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| studentLogout | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 11 |
|||
| verifyMailId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service; | |
| use com\linways\core\ams\professional\service\BaseService; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| class SessionService 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; | |
| } | |
| /** | |
| * Clear logged in staff details | |
| */ | |
| public function staffLogout() | |
| { | |
| unset($_SESSION['staffID']); | |
| unset($_SESSION['staffSess']); | |
| unset($_SESSION['passwdSess']); | |
| unset($_SESSION['deptID']); | |
| unset($_SESSION['staffName']); | |
| unset($_SESSION['notification']); | |
| unset($_SESSION['deptName']); | |
| unset($_SESSION['isHOD']); | |
| unset($_SESSION['isPrincipal']); | |
| unset($_SESSION['isDean']); | |
| } | |
| public function staffLogin(){ | |
| } | |
| public static function checkIfStaffIsLoggedIn(){ | |
| if (!isset($_SESSION['staffID']) || !isset($_SESSION['staffSess']) || !isset($_SESSION['passwdSess'])) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| /** | |
| * This method verifies whether isHOD, isPrincipal given as | |
| * session variables is correct or not | |
| * | |
| * @return void | |
| */ | |
| public function checkIfRolesAssignedForStaffInSessionAreCorrect(){ | |
| $sql = ""; | |
| $staffID = $_SESSION['staffID']; | |
| $staffSess = $_SESSION['staffSess']; | |
| $deptID = $_SESSION['deptID']; | |
| $passwdSess = $_SESSION['passwdSess']; | |
| $isHOD_condition = ($_SESSION['isHOD'] == 1) ? " isHOD > 0" : "isHOD = 0"; | |
| $isPrincipal_condition = ($_SESSION['isPrincipal'] == 1) ? " isPrincipal > 0" : "isPrincipal = 0"; | |
| $sql = "SELECT staffName FROM staffaccounts WHERE staffID = " . $staffID . " AND staffAccount = \"" . $staffSess . "\" AND staffPassword = \"" . $passwdSess . "\" AND deptID = " . $deptID . " AND " . $isPrincipal_condition . " AND " . $isHOD_condition . ""; | |
| try{ | |
| $staff = $this->executeQueryForObject($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| if(!empty($staff) && !empty($staff->staffName)){ | |
| return true; | |
| } | |
| return false; | |
| } | |
| /** | |
| * This is used for alerting user when the session is about to timeout. | |
| * | |
| * @return void | |
| */ | |
| public static function setLastActivitySessionVariableToCurrentTime(){ | |
| $_SESSION['lastActivity'] = time(); // This is used for alerting user when the session is about to timeout. | |
| } | |
| public function getStaffDetailsForLoggingIn($staffAccount, $staffPassword){ | |
| $staffDetails = null; | |
| $staffAccount = $this->realEscapeString($staffAccount); | |
| $staffPassword = $this->realEscapeString($staffPassword); | |
| $sql = "SELECT t1.staffID, t1.staffAccount, t1.staffName, t1.deptID, t1.isHOD, t1.isPrincipal, t1.isResigned, t2.deptName, t1.staffLock , t1.staffGender FROM staffaccounts t1, department t2 WHERE t1.staffAccount=\"$staffAccount\" AND t1.staffPassword=\"$staffPassword\" and t1.deptID = t2.deptID"; | |
| try{ | |
| $staffDetails = $this->executeQueryForObject($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $staffDetails; | |
| } | |
| public function getStaffDetailsByIdForLoggingIn($staffId){ | |
| $staffId = $this->realEscapeString($staffId); | |
| $staffDetails = null; | |
| $sql = "SELECT staffAccount,staffPassword FROM staffaccounts WHERE staffID=\"$staffId\""; | |
| try{ | |
| $staffDetails = $this->executeQueryForObject($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $staffDetails; | |
| } | |
| /** | |
| * Clear logged in Student details | |
| */ | |
| public function studentLogout() | |
| { | |
| unset($_SESSION['studentID']); | |
| unset($_SESSION['studentSess']); | |
| unset($_SESSION['deptID']); | |
| unset($_SESSION['passwdSess']); | |
| unset($_SESSION['studentName']); | |
| unset($_SESSION['batchID']); | |
| unset($_SESSION['studentgender']); | |
| unset($_SESSION['deptName']); | |
| unset($_SESSION['isPassOut']); | |
| } | |
| /** | |
| * V4 to V3 redirection | |
| */ | |
| public function verifyMailId($mailId){ | |
| $mailId = $this->realEscapeString($mailId); | |
| $sql = "select staffAccount, staffPassword, staffEmail from staffaccounts s where staffEmail = '$mailId'"; | |
| try{ | |
| $staffCredentials = $this->executeQueryForList($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $staffCredentials; | |
| } | |
| } |