function getScheduleArray($filter_data) { global $current_user, $current_user_prefs; //Get all schedule data by general filter criteria. Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__, 10); if (!isset($filter_data['start_date']) or $filter_data['start_date'] == '') { return FALSE; } if (!isset($filter_data['end_date']) or $filter_data['end_date'] == '') { return FALSE; } $filter_data['start_date'] = TTDate::getBeginDayEpoch($filter_data['start_date']); $filter_data['end_date'] = TTDate::getEndDayEpoch($filter_data['end_date']); $blf = new BranchListFactory(); $branch_options = $blf->getByCompanyIdArray($current_user->getCompany(), FALSE); $dlf = new DepartmentListFactory(); $department_options = $dlf->getByCompanyIdArray($current_user->getCompany(), FALSE); $slf = new ScheduleListFactory(); $slf->getSearchByCompanyIdAndArrayCriteria($current_user->getCompany(), $filter_data); Debug::text('Found Scheduled Rows: ' . $slf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($slf->getRecordCount() > 0) { foreach ($slf as $s_obj) { Debug::text('Schedule ID: ' . $s_obj->getId() . ' User ID: ' . $s_obj->getColumn('user_id') . ' Start Time: ' . $s_obj->getStartTime(), __FILE__, __LINE__, __METHOD__, 10); if (is_object($s_obj->getAbsencePolicyObject())) { $absence_policy_name = (string) $s_obj->getAbsencePolicyObject()->getName(); } else { $absence_policy_name = 'N/A'; } $iso_date_stamp = TTDate::getISODateStamp($s_obj->getStartTime()); $schedule_shifts[$iso_date_stamp][$s_obj->getColumn('user_id') . $s_obj->getStartTime()] = array('id' => (int) $s_obj->getID(), 'user_id' => (int) $s_obj->getColumn('user_id'), 'user_created_by' => (int) $s_obj->getColumn('user_created_by'), 'user_full_name' => Misc::getFullName($s_obj->getColumn('first_name'), NULL, $s_obj->getColumn('last_name'), FALSE, FALSE), 'first_name' => $s_obj->getColumn('first_name'), 'last_name' => $s_obj->getColumn('last_name'), 'status_id' => (int) $s_obj->getStatus(), 'date_stamp' => TTDate::getAPIDate('DATE', TTDate::parseDateTime($s_obj->getColumn('date_stamp'))), 'start_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $s_obj->getStartTime()) : $s_obj->getStartTime(), 'end_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $s_obj->getEndTime()) : $s_obj->getEndTime(), 'start_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $s_obj->getStartTime()) : $s_obj->getStartTime(), 'end_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $s_obj->getEndTime()) : $s_obj->getEndTime(), 'total_time' => $s_obj->getTotalTime(), 'schedule_policy_id' => (int) $s_obj->getSchedulePolicyID(), 'absence_policy_id' => (int) $s_obj->getAbsencePolicyID(), 'absence_policy' => $absence_policy_name, 'branch_id' => (int) $s_obj->getBranch(), 'branch' => Option::getByKey($s_obj->getBranch(), $branch_options, NULL), 'department_id' => (int) $s_obj->getDepartment(), 'department' => Option::getByKey($s_obj->getDepartment(), $department_options, NULL)); $schedule_shifts_index[$iso_date_stamp][$s_obj->getColumn('user_id')][] = $s_obj->getColumn('user_id') . $s_obj->getStartTime(); unset($absence_policy_name); } //Debug::Arr($schedule_shifts, 'Committed Schedule Shifts: ', __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($schedule_shifts_index, 'Committed Schedule Shifts Index: ', __FILE__, __LINE__, __METHOD__, 10); } else { $schedule_shifts = array(); } unset($slf); //Get holidays //FIXME: What if there are two holiday policies, one that defaults to working, and another that defaults to not working, and they are assigned //to two different groups of employees? For that matter what if the holiday policy isn't assigned to a specific user at all. $holiday_data = array(); $hlf = new HolidayListFactory(); $hlf->getByCompanyIdAndStartDateAndEndDate($current_user->getCompany(), $filter_data['start_date'], $filter_data['end_date']); Debug::text('Found Holiday Rows: ' . $hlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($hlf as $h_obj) { if (is_object($h_obj->getHolidayPolicyObject()) and is_object($h_obj->getHolidayPolicyObject()->getAbsencePolicyObject())) { $holiday_data[TTDate::getISODateStamp($h_obj->getDateStamp())] = array('status_id' => (int) $h_obj->getHolidayPolicyObject()->getDefaultScheduleStatus(), 'absence_policy_id' => $h_obj->getHolidayPolicyObject()->getAbsencePolicyID(), 'absence_policy' => $h_obj->getHolidayPolicyObject()->getAbsencePolicyObject()->getName()); } else { $holiday_data[TTDate::getISODateStamp($h_obj->getDateStamp())] = array('status_id' => 10); //Working } } unset($hlf); $recurring_schedule_shifts = array(); $recurring_schedule_shifts_index = array(); $rstlf = new RecurringScheduleTemplateListFactory(); $rstlf->getSearchByCompanyIdAndArrayCriteria($current_user->getCompany(), $filter_data); Debug::text('Found Recurring Schedule Template Rows: ' . $rstlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($rstlf->getRecordCount() > 0) { foreach ($rstlf as $rst_obj) { //Debug::text('Recurring Schedule Template ID: '. $rst_obj->getID() , __FILE__, __LINE__, __METHOD__, 10); $rst_obj->getShifts($filter_data['start_date'], $filter_data['end_date'], $holiday_data, $branch_options, $department_options, &$schedule_shifts, &$schedule_shifts_index); } } else { Debug::text('DID NOT find Recurring Schedule for this time period: ', __FILE__, __LINE__, __METHOD__, 10); } //Debug::Arr($schedule_shifts, 'Schedule Shifts: ', __FILE__, __LINE__, __METHOD__, 10); unset($schedule_shifts_index, $recurring_schedule_shifts_index); if (isset($schedule_shifts)) { return $schedule_shifts; } return FALSE; }
$filter_data['permission_children_ids'] = $permission_children_ids; } if ($permission->Check('punch', 'view_own')) { $filter_data['permission_children_ids'][] = $current_user->getId(); } } $pplf = new PayPeriodListFactory(); $pplf->getByCompanyId($current_company->getId()); $pay_period_options = $pplf->getArrayByListFactory($pplf, FALSE, FALSE); $pay_period_ids = array_keys((array) $pay_period_options); if (isset($pay_period_ids[0]) and (!isset($filter_data['pay_period_ids']) or $filter_data['pay_period_ids'] == '')) { $filter_data['pay_period_ids'] = '-1'; } //Order In punches before Out punches. $sort_array = Misc::prependArray($sort_array, array('c.pay_period_id' => 'asc', 'c.user_id' => 'asc', 'a.start_time' => 'asc', 'a.status_id' => 'asc')); $slf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data, $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array); $pager = new Pager($slf); $schedule_status_options = $slf->getOptions('status'); $splf = new SchedulePolicyListFactory(); $schedule_policy_options = $splf->getByCompanyIdArray($current_company->getId(), FALSE); $utlf = new UserTitleListFactory(); $utlf->getByCompanyId($current_company->getId()); $title_options = $utlf->getArrayByListFactory($utlf, FALSE, TRUE); $blf = new BranchListFactory(); $blf->getByCompanyId($current_company->getId()); $branch_options = $blf->getArrayByListFactory($blf, FALSE, TRUE); $dlf = new DepartmentListFactory(); $dlf->getByCompanyId($current_company->getId()); $department_options = $dlf->getArrayByListFactory($dlf, FALSE, TRUE); $uglf = new UserGroupListFactory(); $group_options = $uglf->getArrayByNodes(FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'TEXT', TRUE));