From 6077fbe4d8ff9aa8d8e56b1f3a1589d92926d718 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 9 Feb 2016 13:36:45 +0530 Subject: [PATCH 1/2] PCHR-831: Show leave requests in current managers calendar only --- .../civihr_employee_portal.module | 4 +++- .../src/Blocks/ManagerCalendar.php | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/civihr_employee_portal/civihr_employee_portal.module b/civihr_employee_portal/civihr_employee_portal.module index 01e5b0d6..86f03550 100644 --- a/civihr_employee_portal/civihr_employee_portal.module +++ b/civihr_employee_portal/civihr_employee_portal.module @@ -5356,6 +5356,8 @@ function _getManagerContacts($contact_id) { * @return boolean */ function relationActiveAndCurrent($relation){ - return $relation['is_active'] == 1 && (strtotime($relation['end_date']) >= time() || empty($relation['end_date'])) + $endDate = empty($relation['end_date']) ? $relation['end_date'] : $relation['end_date'] . " 23:59:59"; + + return $relation['is_active'] == 1 && (strtotime($endDate) >= time() || empty($endDate)) && (empty($relation['start_date']) || strtotime($relation['start_date']) <= time()); } diff --git a/civihr_employee_portal/src/Blocks/ManagerCalendar.php b/civihr_employee_portal/src/Blocks/ManagerCalendar.php index e813a1ff..5bf42780 100644 --- a/civihr_employee_portal/src/Blocks/ManagerCalendar.php +++ b/civihr_employee_portal/src/Blocks/ManagerCalendar.php @@ -18,12 +18,19 @@ public function generateBlock() { $months_data = array(); $uid = $user->uid; - $result = db_query('SELECT aal.employee_id, aal.id, aal.activity_type_id, aal.absence_title, aal.duration, aal.absence_start_date_timestamp, aal.absence_end_date_timestamp, absence_status - FROM {absence_approval_list} aal WHERE absence_status != :cancelled AND YEAR(absence_end_date) = YEAR(CURDATE())', array('cancelled' => 3)); + + $managerData = get_civihr_uf_match_data($uid); + $managerId = $managerData['contact_id']; + + $result = db_query('SELECT aal.employee_id, aal.id, aal.activity_type_id, aal.absence_title, aal.duration, aal.absence_start_date_timestamp, aal.absence_end_date_timestamp, absence_status, + manager_id FROM {absence_approval_list} aal WHERE absence_status != :cancelled AND YEAR(absence_end_date) = YEAR(CURDATE())', array('cancelled' => 3)); // Result is returned as a iterable object that returns a stdClass object on each iteration foreach ($result as $record) { - + $managers = _getManagerContacts($record->employee_id); + if(!in_array($managerId, $managers)){ + continue; + } $check_start_month = intval(date('n', $record->absence_start_date_timestamp + 3600)); // 1-12 $check_end_month = intval(date('n', $record->absence_end_date_timestamp + 3600)); // 1-12 $check_start_day = intval(date('d', $record->absence_start_date_timestamp + 3600)); From e684493341a68767dafca80c6dfdb90d59babf84 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 9 Feb 2016 13:47:31 +0530 Subject: [PATCH 2/2] PCHR-831: Use of NULL for better readability --- civihr_employee_portal/civihr_employee_portal.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/civihr_employee_portal/civihr_employee_portal.module b/civihr_employee_portal/civihr_employee_portal.module index 86f03550..772fcdbb 100644 --- a/civihr_employee_portal/civihr_employee_portal.module +++ b/civihr_employee_portal/civihr_employee_portal.module @@ -5356,7 +5356,7 @@ function _getManagerContacts($contact_id) { * @return boolean */ function relationActiveAndCurrent($relation){ - $endDate = empty($relation['end_date']) ? $relation['end_date'] : $relation['end_date'] . " 23:59:59"; + $endDate = empty($relation['end_date']) ? NULL : $relation['end_date'] . " 23:59:59"; return $relation['is_active'] == 1 && (strtotime($endDate) >= time() || empty($endDate)) && (empty($relation['start_date']) || strtotime($relation['start_date']) <= time());