Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 359 |
HostelNotificationService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 12 |
5402.00 | |
0.00% |
0 / 359 |
__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 |
|||
getHostelRequestLevelByPriority | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
triggerNotificationOnHostelRequestRejected | |
0.00% |
0 / 1 |
132.00 | |
0.00% |
0 / 48 |
|||
triggerNotificationOnHostelRequestRoomAssigned | |
0.00% |
0 / 1 |
132.00 | |
0.00% |
0 / 48 |
|||
triggerNotificationOnHostelRequest | |
0.00% |
0 / 1 |
156.00 | |
0.00% |
0 / 51 |
|||
getHostelRequestNotifyAdminEmails | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 23 |
|||
getHostelRequestNotifyStaffEmails | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 35 |
|||
notifyApprover | |
0.00% |
0 / 1 |
156.00 | |
0.00% |
0 / 91 |
|||
getHostelRequestById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
triggerNotificationOnHostelRequestConfirmed | |
0.00% |
0 / 1 |
72.00 | |
0.00% |
0 / 34 |
<?php | |
namespace com\linways\core\ams\professional\service\notification; | |
use com\linways\base\constant\UserType; | |
use com\linways\base\dto\Email; | |
use com\linways\base\dto\EmailFrom; | |
use com\linways\base\dto\EmailTo; | |
use com\linways\base\util\StringUtil; | |
use com\linways\core\ams\professional\dto\SettingsConstents; | |
use com\linways\core\ams\professional\service\BaseService; | |
use com\linways\core\ams\professional\service\CommonService; | |
use com\linways\core\ams\professional\service\StaffService; | |
use com\linways\core\ams\professional\service\StudentService; | |
use com\linways\core\ams\professional\util\MessageUtil; | |
use com\linways\core\ams\professional\util\CommonUtil; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\dto\hostel\HostelRequest; | |
use com\linways\core\ams\professional\constant\hostel\HostelRequestStatus; | |
use com\linways\nucleus\core\service\CollegeService; | |
class HostelNotificationService 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; | |
} | |
/** | |
* Get Hostel Level by priority | |
* @param int $priority | |
* @throws ProfessionalException | |
* @return object|NULL|\com\linways\base\util\$objectList[] | |
*/ | |
public function getHostelRequestLevelByPriority($priority) | |
{ | |
$priority = $this->realEscapeString($priority); | |
$hostelLevel = null; | |
try { | |
$sql = "SELECT id,levelName as name ,levelPriority as priority from hostel_approval_group where levelPriority = $priority"; | |
$hostelLevel = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $hostelLevel; | |
} | |
/** | |
* trigger notification on hostel request rejected | |
* @param HostelRequest $hostelRequest | |
*/ | |
public function triggerNotificationOnHostelRequestRejected($hostelRequest) | |
{ | |
// check DB configurations | |
$amsconfigFilePath = getenv('AMS_CONFIG'); | |
require $amsconfigFilePath; | |
$isApproverEmailNotificationEnabled = true; | |
$isRequesterEmailNotificationEnabled = true; | |
$userName = null; | |
$user = null; | |
$student = null; | |
$requesterEmail = null; | |
$hostelRequest = $this->realEscapeObject($hostelRequest); | |
$hostelNotificationSettings = CommonService::getInstance()->getSettingsByType(SettingsConstents::HOSTEL_NOTIFICATION_TYPE); | |
$isApproverEmailNotificationEnabledStrValue = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ENABLE, $hostelNotificationSettings); | |
$isApproverEmailNotificationEnabled = $isApproverEmailNotificationEnabledStrValue == '1' ? true : false; | |
$isRequesterEmailNotificationEnabledStrValue = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ENABLE, $hostelNotificationSettings); | |
$isRequesterEmailNotificationEnabled = $isRequesterEmailNotificationEnabledStrValue == '1' ? true : false; | |
if (! empty($hostelRequest) && ($isApproverEmailNotificationEnabled || $isRequesterEmailNotificationEnabled)) { | |
switch ($hostelRequest->userType) { | |
case UserType::STUDENT: | |
$student = StudentService::getInstance()->getStudentDetailsById($hostelRequest->userId); | |
$hostelRequest->user = $student; | |
// $userName = $user->name; | |
// $requesterEmail = $user->studentEmail; | |
break; | |
case UserType::STAFF: | |
// TODO Staff hostel request currenlty not available | |
// $user = StaffService::getInstance()->getStaffDetailsById($hostelRequest); | |
// $userName = $user->staffName; | |
// $requesterEmail = $user->staffEmail; | |
break; | |
default: | |
break; | |
} | |
if ($isRequesterEmailNotificationEnabled && ! empty($student->studentEmail)) { | |
$requesterMessage = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_REQUESTER_REQUEST_REJECTED_BODY, $hostelNotificationSettings); | |
$requesterMessage = StringUtil::replace_tags($requesterMessage, array( | |
"studentName" => $student->name, | |
"userType" => $hostelRequest->userType | |
)); | |
$requesterMessageSubj = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_REQUESTER_REQUEST_REJECTED_SUBJECT, $hostelNotificationSettings); | |
$emailObj = new Email(); | |
$emailFrom = new EmailFrom(); | |
$emailFrom->email = $college_MailFromID; | |
$emailFrom->name = $MailFromName; | |
$emailTo = new EmailTo(); | |
$emailTo->email = $student->studentEmail; | |
$emailTo->name = ''; | |
$emailObj->subject = empty($requesterMessageSubj) ? "Hostel Admission Request Rejected" : $requesterMessageSubj; | |
$emailObj->body = $requesterMessage; | |
$emailObj->from = $emailFrom; | |
$emailObj->to = $emailTo; | |
MessageUtil::sendEmailAsync($emailObj); | |
} | |
// TO DO Notification to Approvers ..not required now | |
} | |
} | |
/** | |
* trigger notification on hostel request Room assigned | |
* @param HostelRequest $hostelRequest | |
*/ | |
public function triggerNotificationOnHostelRequestRoomAssigned($hostelRequest) | |
{ | |
// check DB configurations | |
$amsconfigFilePath = getenv('AMS_CONFIG'); | |
require $amsconfigFilePath; | |
$isApproverEmailNotificationEnabled = true; | |
$isRequesterEmailNotificationEnabled = true; | |
$userName = null; | |
$user = null; | |
$student = null; | |
$requesterEmail = null; | |
$hostelRequest = $this->realEscapeObject($hostelRequest); | |
$hostelNotificationSettings = CommonService::getInstance()->getSettingsByType(SettingsConstents::HOSTEL_NOTIFICATION_TYPE); | |
$isApproverEmailNotificationEnabledStrValue = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ENABLE, $hostelNotificationSettings); | |
$isApproverEmailNotificationEnabled = $isApproverEmailNotificationEnabledStrValue == '1' ? true : false; | |
$isRequesterEmailNotificationEnabledStrValue = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ENABLE, $hostelNotificationSettings); | |
$isRequesterEmailNotificationEnabled = $isRequesterEmailNotificationEnabledStrValue == '1' ? true : false; | |
if (! empty($hostelRequest) && ($isApproverEmailNotificationEnabled || $isRequesterEmailNotificationEnabled)) { | |
switch ($hostelRequest->userType) { | |
case UserType::STUDENT: | |
$student = StudentService::getInstance()->getStudentDetailsById($hostelRequest->userId); | |
$hostelRequest->user = $student; | |
// $userName = $user->name; | |
// $requesterEmail = $user->studentEmail; | |
break; | |
case UserType::STAFF: | |
// TODO Staff hostel request currenlty not available | |
// $user = StaffService::getInstance()->getStaffDetailsById($hostelRequest); | |
// $userName = $user->staffName; | |
// $requesterEmail = $user->staffEmail; | |
break; | |
default: | |
break; | |
} | |
if ($isRequesterEmailNotificationEnabled && ! empty($student->studentEmail)) { | |
$requesterMessage = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_REQUESTER_REQUEST_ADMITTED_BODY, $hostelNotificationSettings); | |
$requesterMessage = StringUtil::replace_tags($requesterMessage, array( | |
"studentName" => $student->name, | |
"userType" => $hostelRequest->userType | |
)); | |
$requesterMessageSubj = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_REQUESTER_REQUEST_ADMITTED_SUBJECT, $hostelNotificationSettings); | |
$emailObj = new Email(); | |
$emailFrom = new EmailFrom(); | |
$emailFrom->email = $college_MailFromID; | |
$emailFrom->name = $MailFromName; | |
$emailTo = new EmailTo(); | |
$emailTo->email = $student->studentEmail; | |
$emailTo->name = ''; | |
$emailObj->subject = empty($requesterMessageSubj) ? "Hostel Admission Request Approved" : $requesterMessageSubj; | |
$emailObj->body = $requesterMessage; | |
$emailObj->from = $emailFrom; | |
$emailObj->to = $emailTo; | |
MessageUtil::sendEmailAsync($emailObj); | |
} | |
// TO DO Notification to Approvers ..not required now | |
} | |
} | |
/** | |
* trigger notification on hostel request | |
* @param HostelRequest $hostelRequest | |
*/ | |
public function triggerNotificationOnHostelRequest($hostelRequest) | |
{ | |
// check DB configurations | |
$amsconfigFilePath = getenv('AMS_CONFIG'); | |
require $amsconfigFilePath; | |
$isApproverEmailNotificationEnabled = true; | |
$isRequesterEmailNotificationEnabled = true; | |
$userName = null; | |
$user = null; | |
$student = null; | |
$requesterEmail = null; | |
$hostelRequest = $this->realEscapeObject($hostelRequest); | |
$hostelNotificationSettings = CommonService::getInstance()->getSettingsByType(SettingsConstents::HOSTEL_NOTIFICATION_TYPE); | |
$isApproverEmailNotificationEnabledStrValue = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ENABLE, $hostelNotificationSettings); | |
$isApproverEmailNotificationEnabled = $isApproverEmailNotificationEnabledStrValue == '1' ? true : false; | |
$isRequesterEmailNotificationEnabledStrValue = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ENABLE, $hostelNotificationSettings); | |
$isRequesterEmailNotificationEnabled = $isRequesterEmailNotificationEnabledStrValue == '1' ? true : false; | |
if (! empty($hostelRequest) && ($isApproverEmailNotificationEnabled || $isRequesterEmailNotificationEnabled)) { | |
switch ($hostelRequest->userType) { | |
case UserType::STUDENT: | |
$student = StudentService::getInstance()->getStudentDetailsById($hostelRequest->userId); | |
$hostelRequest->user = $student; | |
// $userName = $user->name; | |
// $requesterEmail = $user->studentEmail; | |
break; | |
case UserType::STAFF: | |
// TODO Staff hostel request currenlty not available | |
// $user = StaffService::getInstance()->getStaffDetailsById($hostelRequest); | |
// $userName = $user->staffName; | |
// $requesterEmail = $user->staffEmail; | |
break; | |
default: | |
break; | |
} | |
if ($isRequesterEmailNotificationEnabled && ! empty($student->studentEmail)) { | |
$requesterMessage = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_REQUESTER_REQUEST_ACK_BODY, $hostelNotificationSettings); | |
$requesterMessage = StringUtil::replace_tags($requesterMessage, array( | |
"userName" => $student->name, | |
"userType" => $hostelRequest->userType | |
)); | |
$requesterMessageSubj = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_REQUESTER_REQUEST_ACK_SUBJECT, $hostelNotificationSettings); | |
$emailObj = new Email(); | |
$emailFrom = new EmailFrom(); | |
$emailFrom->email = $college_MailFromID; | |
$emailFrom->name = $MailFromName; | |
$emailTo = new EmailTo(); | |
$emailTo->email = $student->studentEmail; | |
$emailTo->name = ''; | |
$emailObj->subject = empty($requesterMessageSubj) ? "Hostel Admission Request" : $requesterMessageSubj; | |
$emailObj->body = $requesterMessage; | |
$emailObj->from = $emailFrom; | |
$emailObj->to = $emailTo; | |
MessageUtil::sendEmailAsync($emailObj); | |
} | |
if ($isApproverEmailNotificationEnabled) { | |
$this->notifyApprover($hostelRequest, $hostelNotificationSettings); | |
} | |
} | |
} | |
/** | |
* Get Hostel request notifying admin emails | |
* @throws ProfessionalException | |
* @return array[]|\stdClass[] - return hostel privillege assigned admin emails | |
*/ | |
private function getHostelRequestNotifyAdminEmails() | |
{ | |
$emailObj = null; | |
$emailObjList = []; | |
$sql = null; | |
try { | |
$sql = "SELECT aa.adminId,aa.adminName,aa.adminEmail from adminaccount aa | |
inner join admin_privileges ap on aa.admintypeID = ap.admintypeID | |
where ap.menuItems = 'hostel' and aa.isSupportAdmin=0 | |
and aa.adminEmail is not null"; | |
$adminDetails = $this->executeQueryForList($sql); | |
foreach ($adminDetails as $admin) { | |
if (! empty($admin->adminEmail)) { | |
$emailObj = new \stdClass(); | |
$emailObj->email = $admin->adminEmail; | |
$emailObj->name = $admin->adminName; | |
$emailObjList[] = $emailObj; | |
} | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $emailObjList; | |
} | |
/** | |
* Get Hostel request notifiying staff emails which is configured in the levels | |
* @param unknown $hostelRequest | |
* @param unknown $levelPriority | |
* @throws ProfessionalException | |
* @return NULL[]|\stdClass[] | |
*/ | |
private function getHostelRequestNotifyStaffEmails($hostelRequest, $levelPriority) | |
{ | |
$emailObj = null; | |
$emailObjList = []; | |
$sql = null; | |
switch ($hostelRequest->userType) { | |
case UserType::STUDENT: | |
$sql = "SELECT sa.staffID,sa.staffName,sa.staffEmail from hostel_user_group hug | |
inner join staffaccounts sa on sa.staffId = hug.staffaccount_id | |
inner join hostel_approval_group hag on hug.hostel_approval_group_id = hag.id | |
where (hug.department_id = 0 || hug.department_id = (select deptID from studentaccount where studentId = $hostelRequest->userId)) | |
and (hug.batches_id = 0 || hug.batches_id = (select batchId from studentaccount where studentId = $hostelRequest->userId)) | |
and hag.levelPriority = $levelPriority and sa.staffEmail is not null"; | |
break; | |
case UserType::STAFF: | |
// TO DO currenlty system not supporting hostel request for staff | |
break; | |
default: | |
break; | |
} | |
// As first taking all level settings used staff email ids | |
if (! empty($sql)) { | |
try { | |
$staffDetails = $this->executeQueryForList($sql); | |
foreach ($staffDetails as $staff) { | |
if (! empty($staff->staffEmail)) { | |
$emailObj = new \stdClass(); | |
$emailObj->email = $staff->staffEmail; | |
$emailObj->name = $staff->staffName; | |
$emailObjList[] = $emailObj; | |
} | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
return $emailObjList; | |
} | |
/** | |
* Notifying approving staffs/admins | |
* @param HostelRequest $hostelRequest | |
* @param array $hostelNotificationSettings | |
*/ | |
private function notifyApprover($hostelRequest, $hostelNotificationSettings) | |
{ | |
$approverStaffEmails = null; | |
$adminEmails = null; | |
$isApproverEmailNotificationEnabledStrValue = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ENABLE, $hostelNotificationSettings); | |
$isApproverEmailNotificationEnabled = $isApproverEmailNotificationEnabledStrValue == '1' ? true : false; | |
if ($isApproverEmailNotificationEnabled) { | |
// check DB configurations | |
$amsconfigFilePath = getenv('AMS_CONFIG'); | |
require $amsconfigFilePath; | |
$currentLevel = ! empty($hostelRequest->currentLevel) ? $this->getHostelRequestLevelByPriority($hostelRequest->currentLevel->priority) : null; | |
$nextLevel = ! empty($hostelRequest->nextLevel) ? $this->getHostelRequestLevelByPriority($hostelRequest->nextLevel->priority) : null; | |
if(!empty($nextLevel) && !empty($nextLevel->priority)) | |
{ | |
// Take next level approver staff list in TO List | |
$approverStaffEmails = $this->getHostelRequestNotifyStaffEmails($hostelRequest, $nextLevel->priority); | |
} | |
// Take Hostel admin privillege admins to notify in cc | |
$adminEmails = $this->getHostelRequestNotifyAdminEmails(); | |
if (! empty($approverStaffEmails) || ! empty($adminEmails)) { | |
$student = $hostelRequest->user; | |
$hostName = CollegeService::getInstance()->getHostNameByCollegeCode($COLLEGE_CODE); | |
if (! empty($nextLevel)) { | |
$approverMessage = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ACK_BODY, $hostelNotificationSettings); | |
$priority = ! empty($nextLevel) ? $nextLevel->priority : null; | |
$currentLevel = ! empty($nextLevel) ? $nextLevel->name : null; | |
$viewLink = "https://" . $hostName . "/staff/staff.php?menu=hosteltransport&action=hostel&levelPriority=$priority"; | |
$approverMessage = StringUtil::replace_tags($approverMessage, array( | |
"studentName" => $student->name, | |
"admissionNo" => $student->admissionNo, | |
"departmentName" => $student->deptName, | |
"batchName" => $student->batchName, | |
"hostelStartDate" => $hostelRequest->startDate, | |
"hostelEndDate" => $hostelRequest->endDate, | |
"currentLevel" => $currentLevel, | |
"currentLevelStatus" => HostelRequestStatus::OPEN, // Current levele status setting as OPEN since we are not sending any notificatin . | |
// If we need to implement then we need to set this status accordingly | |
"viewLink" => $viewLink | |
)); | |
$approverMessageSubj = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ACK_SUBJECT, $hostelNotificationSettings); | |
$approverMessageSubj = StringUtil::replace_tags($approverMessageSubj, array( | |
"studentName" => $student->name, | |
"admissionNo" => $student->admissionNo, | |
"departmentName" => $student->deptName, | |
"batchName" => $student->batchName, | |
"hostelStartDate" => $hostelRequest->startDate, | |
"hostelEndDate" => $hostelRequest->endDate, | |
"currentLevel" => $currentLevel, | |
"currentLevelStatus" => HostelRequestStatus::OPEN, // Current levele status setting as OPEN since we are not sending any notificatin . | |
// If we need to implement then we need to set this status accordingly | |
"viewLink" => $viewLink | |
)); | |
$emailObj = new Email(); | |
$emailFrom = new EmailFrom(); | |
$emailFrom->email = $college_MailFromID; | |
$emailFrom->name = $MailFromName; | |
$emailObj->subject = $approverMessageSubj; | |
$emailObj->body = $approverMessage; | |
$emailObj->from = $emailFrom; | |
$emailObj->toList = $approverStaffEmails; | |
$emailObj->ccList = $adminEmails; | |
MessageUtil::sendEmailAsync($emailObj); | |
} else { | |
$adminApproverMessage = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_ADMIN_APPROVER_ACK_BODY, $hostelNotificationSettings); | |
$viewLink = "https://" . $hostName . "/admin/admin.php?menu=hostelstudents_level&action=inmatelist"; | |
$adminApproverMessage = StringUtil::replace_tags($adminApproverMessage, array( | |
"studentName" => $student->name, | |
"admissionNo" => $student->admissionNo, | |
"departmentName" => $student->deptName, | |
"batchName" => $student->batchName, | |
"hostelStartDate" => $hostelRequest->startDate, | |
"hostelEndDate" => $hostelRequest->endDate, | |
// If we need to implement then we need to set this status accordingly | |
"viewLink" => $viewLink | |
)); | |
$adminApproverMessageSubj = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_ADMIN_APPROVER_ACK_SUBJECT, $hostelNotificationSettings); | |
$adminApproverMessageSubj = StringUtil::replace_tags($adminApproverMessageSubj, array( | |
"studentName" => $student->name, | |
"admissionNo" => $student->admissionNo, | |
"departmentName" => $student->deptName, | |
"batchName" => $student->batchName, | |
"hostelStartDate" => $hostelRequest->startDate, | |
"hostelEndDate" => $hostelRequest->endDate, | |
// If we need to implement then we need to set this status accordingly | |
"viewLink" => $viewLink | |
)); | |
$emailObj = new Email(); | |
$emailFrom = new EmailFrom(); | |
$emailFrom->email = $college_MailFromID; | |
$emailFrom->name = $MailFromName; | |
$emailObj->subject = $adminApproverMessageSubj; | |
$emailObj->body = $adminApproverMessage; | |
$emailObj->from = $emailFrom; | |
$emailObj->toList = $adminEmails; | |
// $emailObj->ccList = ; | |
MessageUtil::sendEmailAsync($emailObj); | |
} | |
} | |
} | |
} | |
/** | |
* Get Hostel Request deatils by id | |
* | |
* @param int $hostelRequestId | |
* @return HostelRequest | |
*/ | |
public function getHostelRequestById($hostelRequestId) | |
{ | |
$hostelRequestId = $this->realEscapeString($hostelRequestId); | |
$hostelRequest = null; | |
try { | |
$sql = "select id,semesters_id as semId,studentaccount_id as userId,'STUDENT' as userType,hostelStartDate as startDate, hostelEndDate as endDate,(case when earlierID = 1 then true else false end) as isExHosteller,earlierHostelStartDate as exStartDate,earlierHostelEndDate as exEndDate from hostel_student_request where id = $hostelRequestId"; | |
$hostelRequest = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $hostelRequest; | |
} | |
/** | |
* Trigger notification on hostel request confirmed | |
* @param HostelRequest $hostelRequest | |
*/ | |
public function triggerNotificationOnHostelRequestConfirmed($hostelRequest) | |
{ | |
$isApproverEmailNotificationEnabled = true; | |
$isRequesterEmailNotificationEnabled = true; | |
$userName = null; | |
$user = null; | |
$student = null; | |
$requesterEmail = null; | |
$nextLevel = null; | |
$currentLevel = null; | |
$hostelRequest = $this->realEscapeObject($hostelRequest); | |
$nextLevel = $hostelRequest->nextLevel; | |
$currentLevel = $hostelRequest->currentLevel; | |
$hostelRequest = $this->getHostelRequestById($hostelRequest->id); | |
$hostelRequest->nextLevel = $nextLevel; | |
$hostelRequest->currentLevel = $currentLevel; | |
$hostelNotificationSettings = CommonService::getInstance()->getSettingsByType(SettingsConstents::HOSTEL_NOTIFICATION_TYPE); | |
$isApproverEmailNotificationEnabledStrValue = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_APPROVER_ENABLE, $hostelNotificationSettings); | |
$isApproverEmailNotificationEnabled = $isApproverEmailNotificationEnabledStrValue == '1' ? true : false; | |
$isRequesterEmailNotificationEnabledStrValue = CommonUtil::getSettingsValueByName(SettingsConstents::HOSTEL_NOTIFICATION_EMAIL_REQUESTER_ENABLE, $hostelNotificationSettings); | |
$isRequesterEmailNotificationEnabled = $isRequesterEmailNotificationEnabledStrValue == '1' ? true : false; | |
if (! empty($hostelRequest) && ($isApproverEmailNotificationEnabled || $isRequesterEmailNotificationEnabled)) { | |
switch ($hostelRequest->userType) { | |
case UserType::STUDENT: | |
$student = StudentService::getInstance()->getStudentDetailsById($hostelRequest->userId); | |
$hostelRequest->user = $student; | |
// $userName = $user->name; | |
// $requesterEmail = $user->studentEmail; | |
break; | |
case UserType::STAFF: | |
// TODO Staff hostel request currenlty not available | |
// $user = StaffService::getInstance()->getStaffDetailsById($hostelRequest); | |
// $userName = $user->staffName; | |
// $requesterEmail = $user->staffEmail; | |
break; | |
default: | |
break; | |
} | |
$this->notifyApprover($hostelRequest, $hostelNotificationSettings); | |
} | |
} | |
} | |