Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 13 |
CRAP | |
0.00% |
0 / 633 |
ScheduledNotifications | |
0.00% |
0 / 1 |
|
0.00% |
0 / 13 |
9900.00 | |
0.00% |
0 / 633 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
__clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
timeTableReminderSms | |
0.00% |
0 / 1 |
240.00 | |
0.00% |
0 / 85 |
|||
getDayName | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 12 |
|||
unmarkedAttendanceReminder | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 40 |
|||
unmarkedHourDetails | |
0.00% |
0 / 1 |
342.00 | |
0.00% |
0 / 132 |
|||
notifyParentOnStudentAttendanceOnSpecifiedTime | |
0.00% |
0 / 1 |
306.00 | |
0.00% |
0 / 100 |
|||
getStudentAttendanceSMSSendOnSpecifiedTimeMsgParamValues | |
0.00% |
0 / 1 |
110.00 | |
0.00% |
0 / 48 |
|||
filterOutInvalidParentPhoneNumber | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 16 |
|||
getStudentAttendanceDetailsForNotification | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 14 |
|||
sendEmailNotificationToFaculteesAbsenteesStudentList | |
0.00% |
0 / 1 |
342.00 | |
0.00% |
0 / 170 |
|||
v4IntimationRequest | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
<?php | |
namespace com\linways\core\ams\professional\service\notification; | |
use stdClass; | |
use mikehaertl\wkhtmlto\Pdf; | |
use com\linways\base\dto\Email; | |
use com\linways\base\dto\EmailTo; | |
use com\linways\base\dto\sms\SMS; | |
use com\linways\base\dto\EmailFrom; | |
use com\linways\base\util\StringUtil; | |
use com\linways\base\dto\EmailAttachment; | |
use com\linways\base\service\EmailService; | |
use com\linways\core\ams\professional\util\CommonUtil; | |
use com\linways\core\ams\professional\dto\AMSConstants; | |
use com\linways\core\ams\professional\util\MessageUtil; | |
use com\linways\core\ams\professional\constant\UserType; | |
use com\linways\academics\core\service\IntimationService; | |
use com\linways\core\ams\professional\service\SMSService; | |
use com\linways\core\ams\professional\constant\SMSContext; | |
use com\linways\core\ams\professional\service\BaseService; | |
use com\linways\core\ams\professional\constant\EmailModule; | |
use com\linways\core\ams\professional\service\BatchService; | |
use com\linways\core\ams\professional\service\StaffService; | |
use com\linways\core\ams\professional\service\TimetableService; | |
use com\linways\core\ams\professional\service\AttendanceService; | |
use com\linways\core\ams\professional\service\DepartmentService; | |
use com\linways\core\ams\professional\dto\notification\Notification; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\request\api\GetAllBatchesRequest; | |
use com\linways\core\ams\professional\dto\notification\NotificationRecipient; | |
use com\linways\core\ams\professional\request\notification\GetGlobalSettingsRequest; | |
use com\linways\core\ams\professional\mapper\notification\SchedulerNotificationMapper; | |
use com\linways\core\ams\professional\constant\notification\NotificationContextConstant; | |
use com\linways\core\ams\professional\constant\notification\NotificationFeatureConstant; | |
use com\linways\core\ams\professional\request\notification\GetStudentAttendanceDetailsForNotification; | |
use com\linways\core\ams\professional\constant\SettingsConstants; | |
use com\linways\core\ams\professional\service\CommonService; | |
/** | |
* | |
* @author gadheyan | |
* | |
*/ | |
class ScheduledNotifications extends BaseService{ | |
private static $_instance = null; | |
private $mapper = []; | |
// /Condition 2 - Locked down the constructor | |
private function __construct() | |
{ | |
$this->mapper = SchedulerNotificationMapper::getInstance()->getMapper(); | |
} | |
// 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; | |
} | |
public function timeTableReminderSms() | |
{ | |
// Send Notifications For Unassigned Timetable | |
$combinedMessage = ""; | |
$noTimeTable = ""; | |
$smsContent = ""; | |
$departments = DepartmentService::getInstance()->getDepartments(); | |
$principalDetail = StaffService::getInstance()->getPrincipalDetails(); | |
$erpAdminDetail = StaffService::getInstance()->getErpAdminDetails(); | |
$notification = new Notification(); | |
$notification->context = NotificationContextConstant::TIMETABLE; | |
$notification->feature = NotificationFeatureConstant::UNASSIGNED_TIMETABLE_REMINDER_SMS; | |
$notification->recipientType = UserType::STAFF; | |
$notification->smsDeferred = 0; | |
$notification->createdBy = 0; | |
$notification->creatorType = UserType::STAFF; | |
foreach ($departments as $department) { | |
$hodDetail = StaffService::getInstance()->getHodDetailsByDeptID($department->id); | |
$batches = BatchService::getInstance()->getBatchesByDepartmentIdWithoutPassoutBatches($department->id); | |
if (! empty($batches)) { | |
foreach ($batches as $batch) { | |
$timeTableDetails = TimetableService::getInstance()->getBatchTimeTableByBatchAndSem($batch->batchID, $batch->semID); | |
if (empty($timeTableDetails)) { | |
$noTimeTable = "TimeTable is not Defined for " . $batch->batchName . ","; | |
} else { | |
foreach ($timeTableDetails as $timetable) { | |
if ($timetable->sbsID == 0 || $timetable->sbsID == NULL) { | |
$unAssignedTimeTable[] = $timetable; | |
} | |
} | |
if (! empty($unAssignedTimeTable)) { | |
$smsContent = " The following hour(s) are not defined - "; | |
foreach ($unAssignedTimeTable as $timetableUnAssigned) { | |
$smsContent .= " Batch -" . $batch->batchName . " S-" . $batch->semID . "" . " Hour- " . $timetableUnAssigned->hourID . " " . $this->getDayName($timetableUnAssigned->dayID) . "(" . date('d-m-Y', strtotime($timetableUnAssigned->timetableDate)) . "),"; | |
} | |
} | |
unset($unAssignedTimeTable); | |
} | |
} | |
} | |
$messageToSent = $noTimeTable . $smsContent; | |
if (empty($messageToSent)) { | |
// error_log(); | |
continue; | |
} | |
$combinedMessage .= ' ' . $messageToSent; | |
if ($hodDetail) { | |
$recipient = null; | |
$recipient = new NotificationRecipient(); | |
$recipient->recipientId = $hodDetail->staffID; | |
$recipient->recipientType = UserType::STAFF; | |
$recipient->templateParameters = [ | |
"message" => $messageToSent | |
]; | |
$notification->recipient[] = $recipient; | |
} | |
if (! empty($principalDetail)) { | |
$recipient = null; | |
$recipient = new NotificationRecipient(); | |
$recipient->recipientId = $principalDetail->staffID; | |
$recipient->recipientType = UserType::STAFF; | |
$recipient->templateParameters = [ | |
"message" => $messageToSent | |
]; | |
$notification->recipient[] = $recipient; | |
} | |
if (! empty($erpAdminDetail)) { | |
$recipient = null; | |
$recipient = new NotificationRecipient(); | |
$recipient->recipientId = $erpAdminDetail->staffID; | |
$recipient->recipientType = UserType::STAFF; | |
$recipient->templateParameters = [ | |
"message" => $messageToSent | |
]; | |
$notification->recipient[] = $recipient; | |
} | |
} | |
$smsContent = ""; | |
$noTimeTable = ""; | |
$messageToSent = ""; | |
unset($unAssignedTimeTable); | |
try { | |
NotificationService::getInstance()->sendNotification($notification); | |
} catch (\Exception $e) { | |
// log exception | |
$errorMsg = "Error Code : '" . $e->getCode() . "' . Error Message : " . $e->getMessage(); | |
error_log($errorMsg); | |
} | |
} | |
function getDayName($dayID) | |
{ | |
$dayArray = Array( | |
"1" => "Monday", | |
"2" => "TuesDay", | |
"3" => "Wednesday", | |
"4" => "Thursday", | |
"5" => "Friday", | |
"6" => "Saturday", | |
"7" => "Sunday" | |
); | |
return $dayArray[$dayID]; | |
} | |
public function unmarkedAttendanceReminder() | |
{ | |
// Send Notifications About Unmarked Attendance | |
$globalSettingsRequest = new GetGlobalSettingsRequest(); | |
$globalSettingsRequest->context = NotificationContextConstant::ATTENDANCE; | |
$globalSettingsRequest->feature = NotificationFeatureConstant::UNMARKED_ATTENDANCE_REMINDER; | |
$settings = NotificationSettingsService::getInstance()->getSingleGlobalSettings($globalSettingsRequest); | |
if (! $settings->smsEnabled) { | |
return null; | |
} | |
$notification = new Notification(); | |
$notification->context = NotificationContextConstant::ATTENDANCE; | |
$notification->feature = NotificationFeatureConstant::UNMARKED_ATTENDANCE_REMINDER; | |
$notification->recipientType = UserType::STAFF; | |
$notification->smsDeferred = 0; | |
$notification->createdBy = 0; | |
$notification->creatorType = UserType::STAFF; | |
$departments = DepartmentService::getInstance()->getDepartments(); | |
foreach ($departments as $department) { | |
$staffs = StaffService::getInstance()->getAssignedStaffByDepartment($department->id); | |
foreach ($staffs as $staff) { | |
$staffId = $staff->staffID; | |
$staffPhone = $staff->staffPhone; | |
if (preg_match("/^[6-9][0-9]{9}$/", $staffPhone)) { | |
$recipient = null; | |
$recipient = new NotificationRecipient(); | |
$recipient->recipientId = $staff->staffID; | |
$recipient->recipientType = UserType::STAFF; | |
$recipient->templateParameters = [ | |
"smsContent" => $settings->customSettingsValue->smsTemplate | |
]; | |
$notification->recipient[] = $recipient; | |
} | |
} | |
} | |
try { | |
NotificationService::getInstance()->sendNotification($notification); | |
} catch (\Exception $e) { | |
// log exception | |
$errorMsg = "Error Code : '" . $e->getCode() . "' . Error Message : " . $e->getMessage(); | |
error_log($errorMsg); | |
} | |
} | |
// Send Details Of Unmarked Hours | |
public function unmarkedHourDetails() | |
{ | |
$globalSettingsRequest = new GetGlobalSettingsRequest(); | |
$globalSettingsRequest->context = NotificationContextConstant::ATTENDANCE; | |
$globalSettingsRequest->feature = NotificationFeatureConstant::UNMARKED_HOUR_DETAILS; | |
$settings = NotificationSettingsService::getInstance()->getSingleGlobalSettings($globalSettingsRequest); | |
if (! $settings->emailEnabled && ! $settings->smsEnabled) { | |
return null; | |
} | |
$startDate = new \DateTime("first day of last month"); | |
$endDate = new \DateTime("last day of last month"); | |
$startDate = $startDate->format("Y-m-d"); | |
$endDate = $endDate->format("Y-m-d"); | |
$departments = DepartmentService::getInstance()->getDepartments(); | |
$html = "<table border='1' width='100%' cellpadding='2' cellspacing='0'><tr><th width='50%'>Name</th><th width='25%'>Department</th><th width='25%'>Unmarked Hours</th></tr>"; | |
$htmlPrincipal = ""; | |
$htmlHOD = ""; | |
$principalStaffCount = 0; | |
$departmentStaffCount = 0; | |
$PRINCIPAL_SMS_CONTENT = $settings->customSettingsValue->principal->smsTemplate; | |
$PRINCIPAL_EMAIL_CONTENT = $settings->customSettingsValue->principal->emailContent; | |
$PRINCIPAL_EMAIL_SUBJECT = $settings->customSettingsValue->principal->emailSubject; | |
$HOD_SMS_CONTENT = $settings->customSettingsValue->hod->smsTemplate; | |
$HOD_EMAIL_CONTENT = $settings->customSettingsValue->hod->emailContent; | |
$HOD_EMAIL_SUBJECT = $settings->customSettingsValue->hod->emailSubject; | |
$STAFF_SMS_CONTENT = $settings->customSettingsValue->staff->smsTemplate; | |
$UNMARKED_HOUR_LIMIT = $settings->customSettingsValue->minNoOfUnmarkedHours; | |
$UNMARKED_HOUR_SEND_DATE = $settings->customSettingsValue->date; | |
$principalDetails = StaffService::getInstance()->getPrincipalDetails(); | |
$notification = new Notification(); | |
$notification->context = NotificationContextConstant::ATTENDANCE; | |
$notification->feature = NotificationFeatureConstant::UNMARKED_HOUR_DETAILS; | |
$notification->recipientType = UserType::STAFF; | |
$notification->smsDeferred = 0; | |
$notification->emailDeferred = 0; | |
$notification->createdBy = 0; | |
$notification->creatorType = UserType::STAFF; | |
if (date("d") == $UNMARKED_HOUR_SEND_DATE && $UNMARKED_HOUR_LIMIT > 0) { | |
foreach ($departments as $department) { | |
$htmlHOD = ""; | |
$departmentStaffCount = 0; | |
$staffs = StaffService::getInstance()->getStaffByDepartment($department->id); | |
$hodDetails = StaffService::getInstance()->getHodDetailsByDeptID($department->id); | |
foreach ($staffs as $staff) { | |
$unmarkedHoursResponse = AttendanceService::getInstance()->getUnmarkedHourAndDateDetails($staff->staffID, $startDate, $endDate); | |
$hours = count($unmarkedHoursResponse->unmarkedHourandDate); | |
if ($hours > $UNMARKED_HOUR_LIMIT) { | |
$departmentStaffCount ++; | |
$htmlHOD .= "<tr><td>" . $staff->staffName . "</td><td align='center'>" . $department->name . "</td><td align='center'>" . $hours . "</td></tr>"; | |
$principalStaffCount ++; | |
$smsForStaff = ""; | |
$smsForStaff = str_replace("[[count-hrs]]", $hours, $STAFF_SMS_CONTENT); | |
if (trim($smsForStaff) == "") { | |
continue; | |
} | |
$recipient = null; | |
$recipient = new NotificationRecipient(); | |
$recipient->recipientId = $staff->staffID; | |
$recipient->recipientType = UserType::STAFF; | |
$recipient->templateParameters = [ | |
'smsContent' => $smsForStaff | |
]; | |
$notification->recipient[] = $recipient; | |
} | |
} | |
$htmlPrincipal .= $htmlHOD; | |
$htmlHOD = $html . $htmlHOD . "</table>"; | |
$smsForHod = ""; | |
$smsForHod = str_replace([ | |
"[[count-staff]]" | |
], [ | |
$departmentStaffCount | |
], $HOD_SMS_CONTENT); | |
$emailSubjectForHod = $HOD_EMAIL_SUBJECT; | |
$emailContentForHod = str_replace([ | |
"[[count-staff]]", | |
"[[staff-details]]" | |
], [ | |
$departmentStaffCount, | |
$htmlHOD | |
], $HOD_EMAIL_CONTENT); | |
if ($departmentStaffCount > 0) { | |
$recipient = null; | |
$recipient = new NotificationRecipient(); | |
$recipient->recipientId = $hodDetails->staffID; | |
$recipient->recipientType = UserType::STAFF; | |
if (trim($smsForHod) == "" && trim($emailContentForHod) == "" && trim($emailSubjectForHod) == "") { | |
continue; | |
} | |
$recipient->templateParameters = [ | |
'smsContent' => $smsForHod, | |
'emailContent' => $emailContentForHod, | |
'emailSubject' => $emailSubjectForHod | |
]; | |
$notification->recipient[] = $recipient; | |
} | |
} | |
$smsForPrincipal = ""; | |
$smsForPrincipal = str_replace([ | |
"[[count-staff]]" | |
], [ | |
$principalStaffCount | |
], $PRINCIPAL_SMS_CONTENT); | |
$emailSubjectForPrincipal = $PRINCIPAL_EMAIL_SUBJECT; | |
$emailContentForPrincipal = str_replace([ | |
"[[count-staff]]", | |
"[[staff-details]]" | |
], [ | |
$principalStaffCount, | |
$html . $htmlPrincipal . "</table>" | |
], $PRINCIPAL_EMAIL_CONTENT); | |
if ($principalStaffCount > 0) { | |
$recipient = null; | |
$recipient = new NotificationRecipient(); | |
$recipient->recipientId = $principalDetails->staffID; | |
$recipient->recipientType = UserType::STAFF; | |
$recipient->templateParameters = [ | |
'smsContent' => $smsForPrincipal, | |
'emailContent' => $emailContentForPrincipal, | |
'emailSubject' => $emailSubjectForPrincipal | |
]; | |
if (trim($smsForPrincipal) != "" || trim($emailContentForPrincipal) != "" || trim($emailSubjectForPrincipal) != "") { | |
$notification->recipient[] = $recipient; | |
} | |
} | |
} | |
try { | |
NotificationService::getInstance()->sendNotification($notification); | |
} catch (\Exception $e) { | |
// log exception | |
$errorMsg = "Error Code : '" . $e->getCode() . "' . Error Message : " . $e->getMessage(); | |
error_log($errorMsg); | |
} | |
} | |
/** | |
* Method for handling Notify parent on student attendance at specified time | |
* | |
* @return NULL | |
*/ | |
public function notifyParentOnStudentAttendanceOnSpecifiedTime() | |
{ | |
$sqlCount = null; | |
$sql = null; | |
$sqlStudentIds = null; | |
$totalStudents = 0; | |
$customSettingsValue = null; | |
$currentDate = null; | |
$chunkSize = 50; | |
$includeOnlyAbsentHourSqlCriteria = ""; | |
$studentIdsObjList = []; | |
$studentIds = []; | |
$smsMsgTemplate = null; | |
$smsMsgTags = []; | |
$attendanceDate = null; | |
$studentsList = []; | |
$startIndex = 0; | |
// Send Notifications student attendance at specified time | |
$globalSettingsRequest = new GetGlobalSettingsRequest(); | |
$globalSettingsRequest->context = NotificationContextConstant::ATTENDANCE; | |
$globalSettingsRequest->feature = NotificationFeatureConstant::NOTIFY_PARENTS_ON_STUDENT_ATTENDANCE_SPECIFIED_TIME; | |
$settings = NotificationSettingsService::getInstance()->getSingleGlobalSettings($globalSettingsRequest); | |
$notificationType = NotificationUtilityService::getInstance()->getNotificationType(NotificationContextConstant::ATTENDANCE, NotificationFeatureConstant::NOTIFY_PARENTS_ON_STUDENT_ATTENDANCE_SPECIFIED_TIME); | |
$attendanceNotify = json_decode( CommonService::getInstance()->getSettings(SettingsConstants::SMS_ATTENDANCE_NOTIFICATION,SettingsConstants::SMS_ATTENDANCE_NOTIFICATION)); | |
$sendToParent = $attendanceNotify->parent; | |
$sendToStudent = $attendanceNotify->student; | |
// Currenlty SMS only handled. | |
// TODO Email | |
if (empty($settings) || ! $settings->smsEnabled || empty($notificationType->customTemplate)) { | |
error_log('Settings not found'); | |
return null; | |
} | |
$customSettingsValue = $settings->customSettingsValue; | |
if (empty($notificationType->customTemplate)) { | |
// log exception | |
$errorMsg = "SMS Message content is empty or null in notifyParentOnStudentAttendanceOnSpecifiedTime "; | |
error_log($errorMsg); | |
return; | |
} | |
// TODO Excluding batches. | |
$currentDate = date('Y-m-d'); | |
$attendanceDate = $customSettingsValue->previousDayAttendance ? CommonUtil::getPreviousDate($currentDate) : $currentDate; | |
// $attendanceDate = "2019-07-30"; | |
try { | |
$sqlCount = "SELECT DISTINCT count(distinct stu.studentID) as totalStudents FROM attendance att INNER JOIN studentaccount stu ON att.studentID = stu.studentID AND att.attendanceDate = '$attendanceDate' WHERE 1=1 "; | |
if ($customSettingsValue->includeOnlyAbsentHours) { | |
$includeOnlyAbsentHourSqlCriteria = " AND att.isAbsent = 1"; | |
} | |
$sqlCount .= $includeOnlyAbsentHourSqlCriteria; | |
$totalStudents = $this->executeQueryForObject($sqlCount)->totalStudents; | |
if ($totalStudents > 0) { | |
$noOfLoops = ceil($totalStudents / $chunkSize); | |
for ($i = 0; $i < $noOfLoops; $i ++) { | |
$studentsList = []; | |
$sqlStudentIds = "SELECT DISTINCT stu.studentID as studentId FROM attendance att INNER JOIN studentaccount stu ON att.studentID = stu.studentID AND att.attendanceDate ='$attendanceDate' WHERE 1=1 $includeOnlyAbsentHourSqlCriteria LIMIT $startIndex,$chunkSize"; | |
$studentIdsObjList = $this->executeQueryForList($sqlStudentIds); | |
$studentIdsObjListMap = []; | |
$studentIdsObjListMap = array_map(function($stuObj) { return $stuObj->studentId; }, | |
$studentIdsObjList); | |
$studentIds = implode(',', $studentIdsObjListMap); | |
$sql = "SELECT DISTINCT stu.studentId,stu.studentName,stu.parentPhone,stu.studentPhone,att.id as attendanceId,att.attendanceDate,att.hour,att.isAbsent,bt.stratTime as hourStartTime,bt.endTime as hourEndTime FROM attendance att INNER JOIN studentaccount stu ON att.studentID = stu.studentID AND att.attendanceDate = '$attendanceDate' left join batch_timetable bt on bt.batchId = stu.batchID | |
and bt.timetableDate = att.attendanceDate and bt.hourID=att.hour where stu.studentId in ($studentIds) order by stu.studentID,att.hour; "; | |
$studentsList = $this->executeQueryForList($sql, $this->mapper[SchedulerNotificationMapper::GET_STUDENT_SMS_ATTENDANCE_DETAILS]); | |
// Removing invalid parent phone students | |
$studentsList = $this->filterOutInvalidParentPhoneNumber($studentsList); | |
// Starting send sms to student parent | |
foreach ($studentsList as $student) { | |
// if (empty($alreadySMSSendStudents[$student->studentId])) { | |
$smsNotificationTemplateDetails = NotificationService::getInstance()->checkTemplateForSmsNotification(NotificationFeatureConstant::NOTIFY_PARENTS_ON_STUDENT_ATTENDANCE_SPECIFIED_TIME,NotificationContextConstant::ATTENDANCE); | |
$templateProperties = json_decode($smsNotificationTemplateDetails->properties); | |
$templateProperties->templateId = $templateProperties->templateId != NULL? $templateProperties->templateId: NULL; | |
$smsMsgTemplate = $templateProperties->content?$templateProperties->content:$notificationType->customTemplate; | |
$smsMsgTags = $this->getStudentAttendanceSMSSendOnSpecifiedTimeMsgParamValues($student, $attendanceDate); | |
$smsMsg = StringUtil::replace_tags($smsMsgTemplate, $smsMsgTags); | |
if($templateProperties->footerContent != NULL){ | |
$smsMsg .= " ".$templateProperties->footerContent; | |
} | |
$sms = new SMS(); | |
$sms->context = SMSContext::SCHEDULER_NOTIFY_PARENT_STUDENT_ATTENDANCE_ON_SPECIFIED_TIME; | |
$sms->message = $smsMsg; | |
if($sendToParent) | |
{ | |
$sms->mobileNos[] = $student->parentPhone; | |
} | |
if($sendToStudent) | |
{ | |
$sms->mobileNos[] = $student->studentPhone; | |
} | |
$sms->module = "ACADEMICS"; | |
$sms->route = SMS::ROUTE_TRANSACTIONAL; | |
$sms->createdBy = 0; | |
$sms->createdByUserType = \com\linways\base\constant\UserType::SYSTEM; | |
try { | |
SMSService::getInstance()->sendSMS($sms,$templateProperties->templateId); | |
error_log($smsMsg); | |
} catch (\Exception $e) { | |
// log exception | |
$errorMsg = "SMS Send failed for studentId:$student->studentId. Error Code : '" . $e->getCode() . "' . Error Message : " . $e->getMessage(); | |
error_log($errorMsg); | |
} | |
// } | |
} | |
$startIndex += $chunkSize; | |
} | |
} else { | |
// log exception | |
$errorMsg = "There are no students found for notifyParentOnStudentAttendanceOnSpecifiedTime on $attendanceDate "; | |
error_log($errorMsg); | |
} | |
} catch (\Exception $e) { | |
// log exception | |
$errorMsg = "Error Code : '" . $e->getCode() . "' . Error Message : " . $e->getMessage(); | |
error_log($errorMsg); | |
} | |
} | |
/** | |
* GetStudentAttendacnedetails to parent on specified time sms tag replacement values | |
* @param \stdClass $student | |
* @param string $attendanceDate | |
* @return array of tags and value | |
*/ | |
private function getStudentAttendanceSMSSendOnSpecifiedTimeMsgParamValues($student, $attendanceDate) | |
{ | |
$smsMsgTags = []; | |
$absentHourDeatils = null; | |
$absentHourTimeDetails = null; | |
$presentHourDetails = null; | |
$presentHourTimeDetails = null; | |
if (! empty($student)) { | |
if (! empty($student->attendance)) { | |
foreach ($student->attendance as $attendance) { | |
// Setting absentHourDeatils | |
if ($attendance->isAbsent == 1) { | |
if (empty($absentHourDeatils)) { | |
$absentHourDeatils = $attendance->hour; | |
} else { | |
$absentHourDeatils .= "," . $attendance->hour; | |
} | |
// Setting absentHourTimeDetails | |
if (empty($absentHourTimeDetails)) { | |
$absentHourTimeDetails = $attendance->hourStartTime . " to " . $attendance->hourEndTime; | |
} else { | |
$absentHourTimeDetails .= "," . $attendance->hourStartTime . " to " . $attendance->hourEndTime; | |
} | |
} | |
// Setting presentHourDetails | |
if ($attendance->isAbsent == 0) { | |
if (empty($presentHourDetails)) { | |
$presentHourDetails = $attendance->hour; | |
} else { | |
$presentHourDetails .= "," . $attendance->hour; | |
} | |
// Setting presentHourTimeDetails | |
if (empty($presentHourTimeDetails)) { | |
$presentHourTimeDetails = $attendance->hourStartTime . " to " . $attendance->hourEndTime; | |
} else { | |
$presentHourTimeDetails .= "," . $attendance->hourStartTime . " to " . $attendance->hourEndTime; | |
} | |
} | |
} | |
} | |
$dateAndHours = date("d-m-Y", strtotime($attendanceDate))." for hours".$absentHourDeatils; | |
$smsMsgTags = array( | |
"StudentName" => $student->studentName, | |
"AttendanceDate" => date("d-m-Y", strtotime($attendanceDate)), | |
"AbsentHourDeatils" => $absentHourDeatils, | |
"AbsentHourTimeDetails" => $absentHourTimeDetails, | |
"PresentHourDetails" => $presentHourDetails, | |
"PresentHourTimeDetails" => $presentHourTimeDetails, | |
"absentDetailsWithHours"=>$dateAndHours | |
); | |
} | |
return $smsMsgTags; | |
} | |
/** | |
* Filter out invalid phone number students | |
* | |
* @param array $studentAndParentPhoneNumberList | |
* @return array | |
*/ | |
private function filterOutInvalidParentPhoneNumber($studentList) | |
{ | |
if (! $studentList) | |
return []; | |
$response = []; | |
foreach ($studentList as $student) { | |
if (preg_match("/^91[0-9]{10}$/", $student->parentPhone)) { | |
$response[] = $student; | |
} else { | |
if (preg_match("/^[0-9]{10}$/", $student->parentPhone)) { | |
$student->parentPhone = "91" . $student->parentPhone; | |
$response[] = $student; | |
} | |
} | |
} | |
return $response; | |
} | |
/** | |
* | |
* @param GetStudentAttendanceDetailsForNotification $getStudentAttendanceDetailsForNotification | |
* @return array | |
*/ | |
public function getStudentAttendanceDetailsForNotification(GetStudentAttendanceDetailsForNotification $getStudentAttendanceDetailsForNotification) | |
{ | |
$studentList = []; | |
$sql = null; | |
$getStudentAttendanceDetailsForNotification = $this->realEscapeObject($getStudentAttendanceDetailsForNotification); | |
$currentDate = date('Y-m-d'); | |
$attendanceDate = $getStudentAttendanceDetailsForNotification->previousDayAttendance ? CommonUtil::getPreviousDate($currentDate) : $currentDate; | |
// | |
try { | |
$sql = "SELECT DISTINCT stu.parentPhone as parentPhoneNo, stu.studentID as studentId FROM studentaccount stu INNER JOIN attendance att ON att.studentID = stu.studentID where att.attendanceDate = '$attendanceDate' "; | |
$studentList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $studentList; | |
} | |
public function sendEmailNotificationToFaculteesAbsenteesStudentList(){ | |
$notificationDetails = NotificationUtilityService::getInstance()->getNotificationGlobalSettings("ATTENDANCE","EMAIL_NOTIFICATION_TO_FACULTYS_OF_ABSENTEES_STUDENT_REPORT"); | |
if($notificationDetails->feature_enabled != '1'){ | |
return; | |
} | |
$request = new GetAllBatchesRequest(); | |
$request->excludeCourseCompleted = 1; | |
$batchList = BatchService::getInstance()->getAllBatchesByRequest($request); | |
GLOBAL $COLLEGE_NAME, $COLLEGE_NAME_NEW, $COLLEGE_CODE; | |
$imgPath = realpath(DOCUMENT_ROOT . "/libcommon/images/college/".$COLLEGE_CODE."/logo.png"); | |
$htmlContent = " | |
<html> | |
<head> | |
<style> | |
#report { | |
border-collapse: collapse; | |
width: 100%; | |
font-size: 15px; | |
} | |
#report td, #report th { | |
border: 1px solid #ddd; | |
padding: 8px; | |
} | |
#report tr:nth-child(even){background-color: #f2f2f2;} | |
#report tr:hover {background-color: #ddd;} | |
#report th { | |
padding-top: 12px; | |
padding-bottom: 12px; | |
text-align: left; | |
background-color: grey; | |
color: white; | |
} | |
</style> | |
</head> | |
<body> | |
<div class='container'> | |
<div class='text-center'> | |
<h3>".($COLLEGE_NAME_NEW?$COLLEGE_NAME_NEW:$COLLEGE_NAME)."</h3> | |
</div> | |
Dear Sir/Madam,<br> | |
The attendance report for <u><b>".date("d-m-Y")."</b></u> as updated by your staff through Linways interface is detailed below:<br><br> | |
"; | |
foreach($batchList as $batch){ | |
$req = new stdClass(); | |
$req->batchId = $batch->id;//116 | |
$req->semId = $batch->semID;//3 | |
$reportDetails = AttendanceService::getInstance()->generateSubjectWiseAbsenteesAttendanceDetails($req); | |
if(!$reportDetails){ | |
continue; | |
} | |
$htmlContent .=" | |
<table id='report'> | |
<thead > | |
<tr> | |
<th colspan='8'><u><b>Batch</b> - ".$batch->name." <b>Sem - </b>".$batch->semName."</u></th> | |
</tr> | |
<tr> | |
<th>#</th> | |
<th>Subject Name - Staff</th> | |
<th>Period</th> | |
<th>Total</th> | |
<th>Present</th> | |
<th>Absent</th> | |
<th>%</th> | |
<th>Absentees (RollNo -Student Name)</th> | |
</tr> | |
</thead> | |
<tbody>"; | |
$index = 0; | |
$absenteesList = []; | |
$allSubjectAbsentees = []; | |
$allSubjectAbsent = true; | |
$subjectId = 0; | |
foreach($reportDetails as $report){ | |
$index ++; | |
if($allSubjectAbsent){ | |
$absenteesList = $report->absentees?explode(',',$report->absentees):[]; | |
if(empty($allSubjectAbsentees) && !empty($absenteesList)){ | |
$allSubjectAbsentees = $absenteesList; | |
} | |
if($absenteesList){ | |
$length = count($allSubjectAbsentees); | |
foreach($absenteesList as $student){ | |
$allSubjectAbsentees[$length] = $student; | |
$length++; | |
} | |
$allSubjectAbsentees = array_unique($allSubjectAbsentees); | |
} | |
} | |
if($subjectId !=0 && $subjectId != $report->subjectID){ | |
$allSubjectAbsent = false; | |
} | |
$subjectId = $report->subjectID; | |
$htmlContent .= " | |
<tr> | |
<td>$index</td> | |
<td>$report->subjectDesc <br>$report->staffName </td> | |
<td>$report->hour</td> | |
<td>$report->total_hours</td> | |
<td>$report->attended_hourIds</td> | |
<td>$report->isAbsent</td> | |
<td>$report->hour_percentage</td> | |
<td>$report->absentees</td> | |
</tr> | |
"; | |
} | |
if(!$allSubjectAbsent){ | |
$allSubjectAbsentees = []; | |
} | |
$allSubjectAbsentees = empty($allSubjectAbsentees)?'':$$allSubjectAbsentees = implode(',',$allSubjectAbsentees); | |
$htmlContent .=" | |
<tr> | |
<td colspan='7'>All Subject Absentees</td> | |
<td colspan='1'>$allSubjectAbsentees</td> | |
</tr> | |
</tbody> | |
</table><br> | |
"; | |
} | |
$htmlContent .= " | |
</div> | |
</body> | |
</html> | |
"; | |
$pdf = new Pdf(array( | |
'no-outline', // Make Chrome not complain | |
'margin-top' => 10, | |
'margin-right' => 10, | |
'margin-bottom' => 10, | |
'margin-left' => 10, | |
'user-style-sheet' => realpath(DOCUMENT_ROOT . "/libcommon/bootstrap/css/bootstrap.min.css") | |
)); | |
// Add a HTML file, a HTML string or a page from a URL | |
//$pdf->addPage('/home/joe/page.html'); | |
$pdf->addPage($htmlContent); | |
// Save the PDF | |
$tempDir = sys_get_temp_dir(); | |
$file = $pdf->saveAs($tempDir.'/AbsenteesReport.pdf'); | |
// if(!$file){ | |
// $eror = $pdf->_error; | |
// } | |
$fileExist = file_exists($tempDir.'/AbsenteesReport.pdf'); | |
if(!$fileExist){ | |
return; | |
} | |
$notificationDetails->custom_settings_value = json_decode($notificationDetails->custom_settings_value,true); | |
$emailIds = explode(",",$notificationDetails->custom_settings_value['emailIds']); | |
global $college_MailFromID; | |
$emailBody = "Dear Sir/Madam,<br> | |
The Attendance pdf report for <b> ".date("d-m-Y")."</b> as updated by your staff through Linways Interface is attached below:<br><br> | |
Kind Regards,<br> | |
Linways Technologies Pvt Ltd"; | |
$emailSubject = 'Absentees Attendance Notification | Linways'; | |
foreach($emailIds as $emailId){ | |
$emailObj = new Email(); | |
$emailFrom = new EmailFrom(); | |
$emailFrom->email = "Linways Mail"; | |
$emailFrom->name = $college_MailFromID; | |
$emailTo = new EmailTo(); | |
$emailTo->email = $emailId; | |
$emailTo->name = ''; | |
$emailObj->subject = $emailSubject; | |
$emailObj->body = $emailBody; | |
$emailObj->from = $emailFrom; | |
$emailObj->to = $emailTo; | |
$emailObj->mailerType = Email::SMTP; | |
$attachments = []; | |
$fileAttach = new stdClass(); | |
$fileAttach->path = "/tmp/AbsenteesReport.pdf"; | |
$fileAttach->fileName = "AbsenteesReport.pdf"; | |
$fileAttach->encoding = "base64"; | |
$fileAttach->type = "application/octet-stream"; | |
$attachments['file'] = $fileAttach; | |
$emailObj->attachments = $attachments; | |
EmailService::getInstance()->sendEmail($emailObj); | |
} | |
} | |
public function v4IntimationRequest($request){ | |
try{ | |
V4IntimationService::getInstance()->setSchedulerForIntimation($request); | |
}catch (\Exception $e) { | |
// log exception | |
$errorMsg = "Error Code : '" . $e->getCode() . "' . Error Message : " . $e->getMessage(); | |
error_log($errorMsg); | |
} | |
} | |
} |