📄 mailnotifications.php
字号:
$recordArr[] = preg_replace(array('/#date/', '/#type/', '/#duration/', '/#comments/'), array($date, $type, $duration, $comments), $recordTxt);
}
}
$recordTxt = "";
if (isset($recordArr)) {
$recordTxt = join("\r\n", $recordArr);
}
$txt = $txtArr[0].$recordTxt.$txtArr[2];
if (isset($leaveObjs[0])) {
$employeeName = $leaveObjs[0]->getEmployeeName();
$employeeId = $leaveObjs[0]->getEmployeeId();
$this->_getAddresses($employeeId);
$txt = preg_replace('/#'.self::MAILNOTIFICATIONS_VARIABLE_SUBORDINATE.'/', $employeeName, $txt);
$this->subject = $this->_getMailSubject(self::MAILNOTIFICATIONS_TEMPLATE_REJECT_SUBJECT,
$employeeName, $fulldays);
$this->to = $this->subordinateMail;
}
$this->mail = $txt;
}
/**
* builds leave applied notification
*
*/
private function _applyMail() {
$this->notificationTypeId = EmailNotificationConfiguration::EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_PENDING_APPROVAL;
$this->templateFile = file_get_contents(ROOT_PATH."/templates/leave/mails/".self::MAILNOTIFICATIONS_TEMPLATE_APPLY);
$txt = $this->templateFile;
$leaveObjs = $this->getLeaveObjs();
$txtArr = preg_split('/#\{(.*)\}/', $txt, null, PREG_SPLIT_DELIM_CAPTURE);
$recordTxt = $txtArr[1];
$recordArr = null;
$fulldays = 0;
if (is_array($leaveObjs)) {
foreach ($leaveObjs as $leaveObj) {
if ($leaveObj->getLeaveStatus() == Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL) {
$leaveLength = $leaveObj->getLeaveLengthHours();
$fulldays+=$leaveObj->getLeaveLengthDays();
$duration = $leaveObj->getLeaveLengthHours();
$date = $leaveObj->getLeaveDate();
$type = $leaveObj->getLeaveTypeName();
$comments = $leaveObj->getLeaveComments();
$recordArr[] = preg_replace(array('/#date/', '/#type/', '/#duration/', '/#comments/'), array($date, $type, $duration, $comments), $recordTxt);
}
}
}
$recordTxt = "";
if (isset($recordArr)) {
$recordTxt = join("\r\n", $recordArr);
}
$txt = $txtArr[0].$recordTxt.$txtArr[2];
if (isset($leaveObjs[0])) {
$employeeName = $leaveObjs[0]->getEmployeeName();
$employeeId = $leaveObjs[0]->getEmployeeId();
$this->_getAddresses($employeeId);
$txt = preg_replace('/#'.self::MAILNOTIFICATIONS_VARIABLE_SUBORDINATE.'/', $employeeName, $txt);
$this->subject = $this->_getMailSubject(self::MAILNOTIFICATIONS_TEMPLATE_APPLY_SUBJECT,
$employeeName, $fulldays);
$this->to = $this->supervisorMail;
}
$this->mail = $txt;
}
private function _assignMail() {
$this->notificationTypeId = EmailNotificationConfiguration::EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_PENDING_APPROVAL;
$this->templateFile = file_get_contents(ROOT_PATH."/templates/leave/mails/".self::MAILNOTIFICATIONS_TEMPLATE_ASSIGN);
$txt = $this->templateFile;
$leaveObjs = $this->getLeaveObjs();
$txtArr = preg_split('/#\{(.*)\}/', $txt, null, PREG_SPLIT_DELIM_CAPTURE);
$recordTxt = $txtArr[1];
$recordArr = null;
$fulldays = 0;
if (is_array($leaveObjs)) {
foreach ($leaveObjs as $leaveObj) {
if ($leaveObj->getLeaveStatus() == Leave::LEAVE_STATUS_LEAVE_APPROVED) {
$leaveLength = $leaveObj->getLeaveLengthHours();
$fulldays+=$leaveObj->getLeaveLengthDays();
$duration = $leaveObj->getLeaveLengthHours();
$date = $leaveObj->getLeaveDate();
$type = $leaveObj->getLeaveTypeName();
$comments = $leaveObj->getLeaveComments();
$recordArr[] = preg_replace(array('/#date/', '/#type/', '/#duration/', '/#comments/'), array($date, $type, $duration, $comments), $recordTxt);
}
}
}
$recordTxt = "";
if (isset($recordArr)) {
$recordTxt = join("\r\n", $recordArr);
}
$txt = $txtArr[0].$recordTxt.$txtArr[2];
if (isset($leaveObjs[0])) {
$employeeName = $leaveObjs[0]->getEmployeeName();
$employeeId = $leaveObjs[0]->getEmployeeId();
$this->_getAddresses($employeeId);
$txt = preg_replace('/#'.self::MAILNOTIFICATIONS_VARIABLE_SUBORDINATE.'/', $employeeName, $txt);
$this->subject = $this->_getMailSubject(self::MAILNOTIFICATIONS_TEMPLATE_ASSIGN_SUBJECT,
$employeeName, $fulldays);
$this->to = $this->subordinateMail;
}
$this->mail = $txt;
}
/**
* Builds leave cancellation notice
*
*/
private function _cancelMail() {
$this->notificationTypeId = EmailNotificationConfiguration::EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_CANCELLED;
if ($this->action == self::MAILNOTIFICATIONS_ACTION_SUPERVISOR_CANCEL) {
$this->templateFile = file_get_contents(ROOT_PATH."/templates/leave/mails/".self::MAILNOTIFICATIONS_TEMPLATE_SUPERVISOR_CANCEL);
} else {
$this->templateFile = file_get_contents(ROOT_PATH."/templates/leave/mails/".self::MAILNOTIFICATIONS_TEMPLATE_CANCEL);
}
$txt = $this->templateFile;
$leaveObjs = $this->getLeaveObjs();
$txtArr = preg_split('/#\{(.*)\}/', $txt, null, PREG_SPLIT_DELIM_CAPTURE);
$recordTxt = $txtArr[1];
$recordArr = null;
$fulldays = 0;
foreach ($leaveObjs as $leaveObj) {
if ($leaveObj->getLeaveStatus() == Leave::LEAVE_STATUS_LEAVE_CANCELLED) {
$leaveLength = $leaveObj->getLeaveLengthHours();
$fulldays+=$leaveObj->getLeaveLengthDays();
$duration = $leaveObj->getLeaveLengthHours();
$date = $leaveObj->getLeaveDate();
$type = $leaveObj->getLeaveTypeName();
$comments = $leaveObj->getLeaveComments();
$recordArr[] = preg_replace(array('/#date/', '/#type/', '/#duration/', '/#comments/'), array($date, $type, $duration, $comments), $recordTxt);
}
}
$recordTxt = "";
if (isset($recordArr)) {
$recordTxt = join("\r\n", $recordArr);
}
$txt = $txtArr[0].$recordTxt.$txtArr[2];
if (isset($leaveObjs[0])) {
$employeeName = $leaveObjs[0]->getEmployeeName();
$employeeId = $leaveObjs[0]->getEmployeeId();
$this->_getAddresses($employeeId);
$txt = preg_replace('/#'.self::MAILNOTIFICATIONS_VARIABLE_SUBORDINATE.'/', $employeeName, $txt);
if ($this->action == self::MAILNOTIFICATIONS_ACTION_SUPERVISOR_CANCEL) {
$subjectTemplate = self::MAILNOTIFICATIONS_TEMPLATE_SUPERVISOR_CANCEL_SUBJECT;
$this->to = $this->subordinateMail;
} else {
$subjectTemplate = self::MAILNOTIFICATIONS_TEMPLATE_CANCEL_SUBJECT;
$this->to = $this->supervisorMail;
}
$this->subject = $this->_getMailSubject($subjectTemplate,
$employeeName, $fulldays);
}
$this->mail = $txt;
}
/**
* Fetches the leaves of the leave request in the object
*
*/
private function _preFetchLeaves() {
$leaveObj = new Leave();
$leaveRequestObj = $this->getLeaveRequestObj();
$leaveObjs = $leaveObj->retrieveLeave($leaveRequestObj->getLeaveRequestId());
$this->setLeaveObjs($leaveObjs);
}
/**
* Refresh leave objects from the database, since leave objects extracted from request are
* missing some information like dates and leave lengths.
*/
private function _refreshLeaves() {
$leaveObjs = array();
foreach ($this->leaveObjs as $leaveObj) {
$leave = $leaveObj->retrieveIndividualLeave($leaveObj->getLeaveId());
$leaveObjs[] = $leave[0];
}
$this->leaveObjs = $leaveObjs;
}
/**
* Fetch required mail addresses related to the employee
*
* @param integer $employeeId - Employee ID
*/
private function _getAddresses($employeeId) {
$this->subordinateMail = array($this->_getEmpAddress(str_pad($employeeId, $this->employeeIdLength)));
$empRepToObj1 = new EmpRepTo();
$supInfo = $empRepToObj1->getEmpSup(str_pad($employeeId, $this->employeeIdLength, "0", STR_PAD_LEFT));
$supAddr = null;
if (isset($supInfo) && is_array($supInfo)) {
foreach ($supInfo as $supervisor) {
$supAddr[] = $this->_getEmpAddress($supervisor[1]);
}
}
$this->supervisorMail = $supAddr;
}
/**
* Fetch the mail address of the employee
*
* @param integer $employeeId - Employee ID
* @return String E-Mail
*/
private function _getEmpAddress($employeeId) {
$empInfoObj = new EmpInfo();
$empInfo = $empInfoObj->filterEmpContact($employeeId);
if (isset($empInfo[0][10])) {
return $empInfo[0][10];
}
return null;
}
/**
* Get the leave count as a string considering half days.
*
* @param interger $fulldays - Number of full days
* @param integer $halfdays - Number of half days
* @return String Number of leave days as a string (eg: 2 1/2 or 1/2 )
*/
private function _getLeaveCountStr($fulldays, $halfdays) {
$fulldays += floor($halfdays / 2);
$halfdayStr = ($halfdays % 2 == 1) ? " 1/2" : "";
$fulldayStr = ($fulldays > 0) ? sprintf("%d", $fulldays) : "";
$leaveStr = sprintf("%s%s", $fulldayStr, $halfdayStr);
return $leaveStr;
}
/**
* Get the description string for the leave length
* (Half day / Morning etc. )
*
* @param integer $leaveLength - The leave length constant
*
* @return String Leave length description
*/
private function _getLeaveLengthDesc($leaveLength) {
$lan = new Language();
require ROOT_PATH . '/language/default/lang_default_full.php';
require ($lan->getLangPath("full.php"));
$desc = "";
if ($leaveLength == Leave::LEAVE_LENGTH_FULL_DAY) {
$desc = $lang_Leave_Common_FullDay;
} else if ($leaveLength == Leave::LEAVE_LENGTH_HALF_DAY_MORNING) {
$desc = $lang_Leave_Common_HalfDayMorning;
} else if ($leaveLength == Leave::LEAVE_LENGTH_HALF_DAY_AFTERNOON) {
$desc = $lang_Leave_Common_HalfDayAfternoon;
}
return $desc;
}
/**
* Get the mail subject from given template
*
* @param string $template Mail subject template file
* @param string $subordinate The name of the employee applying for leave
* @param int $leaveCount The number of days of leave
*
* @return string Mail subject from the given file, with parameters replaced
*/
private function _getMailSubject($template, $subordinate, $leaveCount) {
$subject = file_get_contents(ROOT_PATH."/templates/leave/mails/".$template);
$pattern = array('/#'.self::MAILNOTIFICATIONS_VARIABLE_LEAVECOUNT.'/',
'/#'.self::MAILNOTIFICATIONS_VARIABLE_SUBORDINATE.'/',
"/\n/");
$replace = array($leaveCount, $subordinate, "");
$subject = preg_replace($pattern, $replace, $subject);
return $subject;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -