/** * function __construct * <pre> * Initialize the object. * </pre> * @param $pathModuleRoot [STRING] The path to the module's root dir. * @param $viewer [OBJECT] The viewer object. * @param $sortBy [STRING] Field data to sort listManager by. * @param $managerInit [INTEGER] Initialization value for the listManager. * @return [void] */ function __construct($pathModuleRoot, $viewer, $sortBy, $staffscheduletype_id) { parent::__construct(page_FormApprovalListing::DISPLAY_FIELDS); $this->pathModuleRoot = $pathModuleRoot; $this->viewer = $viewer; $this->formtype_id = $staffscheduletype_id; $this->sortBy = $sortBy; if ($this->sortBy == '') { $this->sortBy = 'staffschedule_approved,person_lname,person_fname'; } else { if ($this->sortBy == 'person_id') { $this->sortBy = 'person_lname,person_fname'; } } // Now load the access Priviledge manager of this viewer $this->adminManager = new RowManager_AdminManager(); // Get the person ID $accessManager = new RowManager_AccessManager(); $accessManager->loadByViewerID($this->viewer->getViewerID()); $personID = $accessManager->getPersonID(); // Get the permissions the person has. $this->adminManager->loadByPersonID($personID); // Super-admin if ($this->adminManager->hasSitePriv()) { $dataAccessObject = new MultiTableManager(); $schedules = new RowManager_StaffScheduleManager(); $schedules->setFormID($this->formtype_id); $persons = new RowManager_PersonManager(); $dataAccessObject->addRowManager($schedules); $dataAccessObject->addRowManager($persons, new JoinPair($schedules->getJoinOnPersonID(), $persons->getJoinOnPersonID())); $dataAccessObject->setSortOrder($this->sortBy); // $this->listManager = new StaffScheduleList( $sortBy ); $this->listManager = $dataAccessObject->getListIterator(); } else { if ($this->adminManager->isStaff($viewer->getID())) { $director_id = $this->getStaffIDfromViewerID(); $staffManager = new RowManager_StaffDirectorManager(); $staffManager->setDirectorID($director_id); /* Retrieve all directors under the current director */ $hierarchy_result = $staffManager->getDirectorHierarchy($director_id); $hierarchy_result->setFirst(); $hierarchy_array = array(); $directed_staff = ''; while ($hierarchy_result->moveNext()) { $staff_ids = $hierarchy_result->getCurrentRow(); // echo 'array = <pre>'.print_r($hierarchy_array,true).'</pre>'; for ($lvl = 1; $lvl <= MAX_DIRECTOR_LEVELS; $lvl++) { $staff_id = $staff_ids['staff_lvl' . $lvl]; if ($staff_id != null) { $directed_staff .= $staff_id . ','; } } } if ($directed_staff != '') { $directed_staff = substr($directed_staff, 0, -1); } else { $directed_staff = page_FormApprovalListing::NO_SUPERVISEES; } // // Filter approval records by those staff persons found in the list of staff under the direction of the current viewer $schedules = new RowManager_StaffScheduleManager(); $schedules->setFormID($this->formtype_id); $person_info = new RowManager_PersonManager(); $staff = new RowManager_StaffManager(); $dataAccessObject = new MultiTableManager(); $dataAccessObject->addRowManager($staff); $dataAccessObject->addRowManager($person_info, new JoinPair($staff->getJoinOnPersonID(), $person_info->getJoinOnPersonID())); $dataAccessObject->addRowManager($schedules, new JoinPair($person_info->getJoinOnPersonID(), $schedules->getJoinOnPersonID())); $dataAccessObject->addSearchCondition('staff_id in (' . $directed_staff . ')'); $dataAccessObject->setSortOrder($this->sortBy); $this->listManager = $dataAccessObject->getListIterator(); } else { $dataAccessObject = new MultiTableManager(); $schedules = new RowManager_StaffScheduleManager(); $schedules->setFormID(page_FormApprovalListing::UNAUTHORIZED_DIRECTOR); $dataAccessObject->addRowManager($schedules); $dataAccessObject->setSortOrder($this->sortBy); // $this->listManager = new StaffScheduleList( $sortBy ); $this->listManager = $dataAccessObject->getListIterator(); } } // now initialize the labels for this page // start by loading the default field labels for this Module $languageID = $viewer->getLanguageID(); $seriesKey = modulecim_hrdb::MULTILINGUAL_SERIES_KEY; $pageKey = modulecim_hrdb::MULTILINGUAL_PAGE_FIELDS; $this->labels = new MultilingualManager($languageID, $seriesKey, $pageKey); // then load the page specific labels for this page $pageKey = page_FormApprovalListing::MULTILINGUAL_PAGE_KEY; $this->labels->loadPageLabels($pageKey); $this->labels->setSeriesKey(SITE_LABEL_SERIES_SITE); $this->labels->loadPageLabels(SITE_LABEL_PAGE_FORM_LINKS); }
/** * function __construct * <pre> * Initialize the object. * </pre> * @param $pathModuleRoot [STRING] The path to the module's root dir. * @param $viewer [OBJECT] The viewer object. * @param $sortBy [STRING] Field data to sort listManager by. * @param $managerInit [INTEGER] Initialization value for the listManager. * @return [void] */ function __construct($pathModuleRoot, $viewer, $customreport_id, $disable_heading = false) { $this->is_blank_page = false; $this->disable_heading = $disable_heading; // store field display types $DISPLAY_FIELDS = $this->getDisplayFields($customreport_id); parent::__construct($DISPLAY_FIELDS); // parent::__construct( page_ViewCustomReport::DISPLAY_FIELDS ); $this->pathModuleRoot = $pathModuleRoot; $this->viewer = $viewer; $this->disableHeading = $disable_heading; $this->customreport_id = $customreport_id; $this->fields_id_array = array(); $this->listLabels = array(); // Get fields for the custom report; required for retrieving data in column format // $columns = 'customfields_id,report_id,cim_hrdb_customfields.fields_id,count(person_id)'; $groupBy = 'cim_hrdb_customfields.fields_id'; $dbFunction = 'COUNT'; $funcParam = 'person_id'; $reportFields = new MultiTableManager(); $customfields = new RowManager_CustomFieldsManager(); $customfields->setReportID($this->customreport_id); // TODO? error checking on ID $fieldvalues = new RowManager_FormFieldValueManager(); $reportFields->addRowManager($customfields); $reportFields->addRowManager($fieldvalues, new JoinPair($customfields->getJoinOnFieldID(), $fieldvalues->getJoinOnFieldID())); // use GROUP BY and $dbFunction = 'COUNT' to quickly get summary data per campus if ($groupBy != '') { $reportFields->setGroupBy($groupBy); //'campus_desc'); } if ($dbFunction != '') { $reportFields->setFunctionCall($dbFunction, $funcParam); } $reportFields->setSortOrder('COUNT(person_id) DESC'); // $reportFields->setFieldList($columns); $customFieldsList = $reportFields->getListIterator(); $customFieldsArray = $customFieldsList->getDataList(); // echo '<pre>'.print_r($customFieldsArray,true).'</pre>'; $i = 0; foreach (array_keys($customFieldsArray) as $key) { $record = current($customFieldsArray); $this->fields_id_array[$i] = $record['fields_id']; $i++; next($customFieldsArray); } // Ensure that the custom report has been given at least one field if (count($this->fields_id_array) > 0) { // Default sorting: by person name, since this is the only standard field $this->sortBy = 'person_lname,person_fname'; // TODO: need to add person table to allow person_name sorting // Now load the access Privilege manager of this viewer $this->adminManager = new RowManager_AdminManager(); // Get the person ID $accessManager = new RowManager_AccessManager(); $accessManager->loadByViewerID($this->viewer->getViewerID()); $personID = $accessManager->getPersonID(); // Get the permissions the person has. $this->adminManager->loadByPersonID($personID); $directed_staff = ''; $directed_people = ''; // Super-admin if ($this->adminManager->hasSitePriv()) { $this->access_level = page_ViewCustomReport::SUPERADMIN; } else { if ($this->adminManager->isStaff($viewer->getID())) { $director_id = $this->getStaffIDfromViewerID(); $staffManager = new RowManager_StaffDirectorManager(); $staffManager->setDirectorID($director_id); /* Retrieve all directors under the current director */ $hierarchy_result = $staffManager->getDirectorHierarchy($director_id); $hierarchy_result->setFirst(); $hierarchy_array = array(); $directed_staff = ''; while ($hierarchy_result->moveNext()) { $staff_ids = $hierarchy_result->getCurrentRow(); // echo 'array = <pre>'.print_r($hierarchy_array,true).'</pre>'; for ($lvl = 1; $lvl <= MAX_DIRECTOR_LEVELS; $lvl++) { $staff_id = $staff_ids['staff_lvl' . $lvl]; if ($staff_id != null) { $directed_staff .= $staff_id . ','; } } } if ($directed_staff != '') { $directed_staff = substr($directed_staff, 0, -1); $this->access_level = page_ViewCustomReport::DIRECTOR; } else { $directed_staff = page_ViewCustomReport::NON_DIRECTOR; $this->access_level = page_ViewCustomReport::NON_DIRECTOR; } $personGetter = new MultiTableManager(); $person_info = new RowManager_PersonManager(); $staff = new RowManager_StaffManager(); $personGetter->addRowManager($person_info); $personGetter->addRowManager($staff, new JoinPair($staff->getJoinOnPersonID(), $person_info->getJoinOnPersonID())); $personGetter->addSearchCondition('staff_id in (' . $directed_staff . ')'); $staffPersonList = $personGetter->getListIterator(); $staffPersonArray = $staffPersonList->getDataList(); foreach (array_keys($staffPersonArray) as $key) { $record = current($staffPersonArray); $directed_people .= $record['person_id'] . ','; next($staffPersonArray); } $directed_people = substr($directed_people, 0, -1); //remove last comma } else { $this->access_level = page_ViewCustomReport::UNAUTHORIZED_DIRECTOR; } } // Retrieve custom report fields and store them in data columns for easy display $dataAccessObject = new MultiTableManager(); $person_manager = new RowManager_PersonManager(); $dataAccessObject->addRowManager($person_manager); $fieldList = ''; $temp_tables = array(); for ($i = 0; $i < count($this->fields_id_array); $i++) { $tempTableCreationSQLmaker = new MultiTableManager(); $fieldvalue_manager = new RowManager_FormFieldValueManager(); $fieldvalue_manager->setFieldID($this->fields_id_array[$i]); // if ($this->access_level == page_ViewCustomReport::UNAUTHORIZED_DIRECTOR) // { // $fieldvalue_manager->setPersonID($personID); // only show staff's own data // } // else if ($this->access_level == page_ViewCustomReport::DIRECTOR) // { // $fieldvalue_manager->addSearchCondition('person_id in ('.$directed_people.')'); // } // else if ($this->access_level == page_ViewCustomReport::NON_DIRECTOR) // director with no underlings // { // $fieldvalue_manager->setPersonID($personID); // only show staff's own data // } // else if ($this->access_level == page_ViewCustomReport::SUPERADMIN) // { // // no restrictions // } // Create a temporary table from a SQL join retrieving the data for a particular form field $tempTableCreationSQLmaker->addRowManager($fieldvalue_manager); $fields_manager = new RowManager_FormFieldManager(); $tempTableCreationSQLmaker->addRowManager($fields_manager, new JoinPair($fieldvalue_manager->getJoinOnFieldID(), $fields_manager->getJoinOnFieldID())); $customfields_manager = new RowManager_CustomFieldsManager(); $customfields_manager->setReportID($this->customreport_id); $tempTableCreationSQLmaker->addRowManager($customfields_manager, new JoinPair($fieldvalue_manager->getJoinOnFieldID(), $customfields_manager->getJoinOnFieldID())); $tempFieldList = 'person_id,fieldvalues_value'; $tempTableCreationSQLmaker->setFieldList($tempFieldList); $tempTableCreationSQL = $tempTableCreationSQLmaker->createSQL(); $temp_tables[$i] = new TempTableManager('temptable' . $i, $tempTableCreationSQL, $tempFieldList, 'temptable' . $i); //$PRIMARY_ID=-1 $temp_tables[$i]->createTable(true); // Join the temporary tables together to get a table of n+1 columns where n = count($this->field_ids_array) and the extra column stores person_id if ($i > 0) { $fieldList .= ',temptable' . $i . '.fieldvalues_value as value' . $i; $i_minus = $i - 1; $dataAccessObject->addRowManager($temp_tables[$i], new JoinPair($temp_tables[$i_minus]->getJoinOnFieldX(page_ViewCustomReport::JOIN_FIELD), $temp_tables[$i]->getJoinOnFieldX(page_ViewCustomReport::JOIN_FIELD), JOIN_TYPE_LEFT)); } else { $fieldList .= 'cim_hrdb_person.person_id,temptable' . $i . '.fieldvalues_value as value' . $i; $dataAccessObject->addRowManager($temp_tables[0], new JoinPair($person_manager->getJoinOnFieldX(page_ViewCustomReport::JOIN_FIELD), $temp_tables[0]->getJoinOnFieldX(page_ViewCustomReport::JOIN_FIELD))); } } // Filter results by directed people IDs (if viewer is NOT super-admin) if ($this->access_level != page_ViewCustomReport::SUPERADMIN) { // for ($i=0; $i < count($this->fields_id_array); $i++) // { // if ($this->access_level == page_ViewCustomReport::UNAUTHORIZED_DIRECTOR) // { // $dataAccessObject->addSearchCondition('temptable'.$i.'.person_id in ('.$personID.')'); // only show staff's own data // } // else if ($this->access_level == page_ViewCustomReport::DIRECTOR) // { // $dataAccessObject->addSearchCondition('temptable'.$i.'.person_id in ('.$directed_people.')'); // } // else if ($this->access_level == page_ViewCustomReport::NON_DIRECTOR) // director with no underlings // { // $dataAccessObject->addSearchCondition('temptable'.$i.'.person_id in ('.$personID.')'); // only show staff's own data // } // } $dataAccessObject->addSearchCondition('cim_hrdb_person.person_id in (' . $directed_people . ')'); } // echo '<pre>'.print_r($temp_tables[0]->getListIterator()->getDataList(),true).'</pre>'; // $temp_tables[0]->db->runSQL('select * from temptable0'); $dataAccessObject->setFieldList($fieldList); $dataAccessObject->setSortOrder($this->sortBy); $this->listManager = $dataAccessObject->getListIterator(); // echo '<pre>'.print_r($this->listManager->getDataList(),true).'</pre>'; } else { $dataAccessObject = new MultiTableManager(); $person_manager = new RowManager_PersonManager(); $person_manager->setPersonID(page_ViewCustomReport::NO_FIELDS_SET); $dataAccessObject->addRowManager($person_manager); $dataAccessObject->setSortOrder($this->sortBy); $this->listManager = $dataAccessObject->getListIterator(); $this->is_blank_page = true; } // now initialize the labels for this page // start by loading the default field labels for this Module $languageID = $viewer->getLanguageID(); $seriesKey = modulecim_hrdb::MULTILINGUAL_SERIES_KEY; $pageKey = modulecim_hrdb::MULTILINGUAL_PAGE_FIELDS; $this->labels = new MultilingualManager($languageID, $seriesKey, $pageKey); // then load the page specific labels for this page $pageKey = page_ViewCustomReport::MULTILINGUAL_PAGE_KEY; $this->labels->loadPageLabels($pageKey); $this->labels->setSeriesKey(SITE_LABEL_SERIES_SITE); $this->labels->loadPageLabels(SITE_LABEL_PAGE_FORM_LINKS); $this->listLabels = $this->getListLabels($this->customreport_id); // NOTE: parameter *required* // foreach (array_keys($this->listLabels,true) as $key) // { // $label = current($this->listLabels); // $this->labels->setLabelTag('[title_value0]', '<title in tool_setup>', 'Monthly Support Goal'); // NOTE: cannot be used because nothing set in tool_setup // echo 'labels = <pre>'.print_r($this->listLabels,true).'</pre>'; }
/** * function __construct * <pre> * Initialize the object. * </pre> * @param $pathModuleRoot [STRING] The path to the module's root dir. * @param $viewer [OBJECT] The viewer object. * @param $sortBy [STRING] Field data to sort listManager by. * @param $managerInit [INTEGER] Initialization value for the listManager. * @return [void] */ function __construct($pathModuleRoot, $viewer, $sortBy, $month_id = '') { parent::__construct(page_ViewScheduleCalendar::DISPLAY_FIELDS); $this->pathModuleRoot = $pathModuleRoot; $this->viewer = $viewer; if ($month_id == '') { $month_id = date('n'); } $this->month_id = $month_id; $this->year_id = date('Y'); $this->first_weekday = page_ViewScheduleCalendar::SUNDAY; $this->monthValues = $this->getMonthValues(); //$this->yearValueList->getDropListArray(); // Now load the access Privilege manager of this viewer $this->adminManager = new RowManager_AdminManager(); // Get the person ID $accessManager = new RowManager_AccessManager(); $accessManager->loadByViewerID($this->viewer->getViewerID()); $personID = $accessManager->getPersonID(); // Get the permissions the person has. $this->adminManager->loadByPersonID($personID); // Super-admin if ($this->adminManager->hasSitePriv()) { $dataAccessObject = new MultiTableManager(); $activities = new RowManager_StaffActivityManager(); $activityTypes = new RowManager_ActivityTypeManager(); $person_info = new RowManager_PersonManager(); $dataAccessObject->addRowManager($activities); $dataAccessObject->addRowManager($activityTypes, new JoinPair($activityTypes->getJoinOnActivityTypeID(), $activities->getJoinOnActivityTypeID())); $dataAccessObject->addRowManager($person_info, new JoinPair($person_info->getJoinOnPersonID(), $activities->getJoinOnPersonID())); $dataAccessObject->setSortOrder($sortBy); $this->listManager = $dataAccessObject->getListIterator(); } else { if ($this->adminManager->isStaff($viewer->getID())) { $director_id = $this->getStaffIDfromViewerID(); // $staffPersonManager = new MultiTableManager(); $staffManager = new RowManager_StaffDirectorManager(); $staffManager->setDirectorID($director_id); // $staffInfoManager = new RowManager_StaffManager(); // $staffPersonManager->addRowManager($staffInfoManager); // $staffPersonManager->addRowManager($staffManager, new JoinPair($staffManager->getJoinOnStaffID(),$staffInfoManager->getJoinOnStaffID())); // $staffList = $staffPersonManager->getListIterator(); // $staffArray = $staffList->getDataList(); /* Retrieve all directors under the current director */ $hierarchy_result = $staffManager->getDirectorHierarchy($director_id); $hierarchy_result->setFirst(); $hierarchy_array = array(); $directed_staff = ''; while ($hierarchy_result->moveNext()) { $staff_ids = $hierarchy_result->getCurrentRow(); // echo 'array = <pre>'.print_r($hierarchy_array,true).'</pre>'; for ($lvl = 1; $lvl <= MAX_DIRECTOR_LEVELS; $lvl++) { $staff_id = $staff_ids['staff_lvl' . $lvl]; if ($staff_id != null) { $directed_staff .= $staff_id . ','; } } } if ($directed_staff != '') { $directed_staff .= $director_id; //= substr( $directed_staff, 0, -1 ); } else { $directed_staff = $director_id; //page_ViewScheduleCalendar::NON_DIRECTOR; } // echo '<pre>'.print_r($staffArray,true).'</pre>'; // // Retrieve the list of staff supervised by current viewer // $directed_staff = ''; // foreach (array_keys($staffArray) as $key) // { // $record = current($staffArray); // $directed_staff .= $record['person_id'].','; // next($staffArray); // } // $directed_staff = substr($directed_staff,0,-1); // if ($directed_staff == '') // { // $directed_staff = page_FormApprovalListing::NO_SUPERVISEES; // don't match any person IDs // } // Filter activities by those staff persons found in the list of staff under the direction of the current viewer $dataAccessObject = new MultiTableManager(); $schedules = new RowManager_StaffScheduleManager(); // $schedules->addSearchCondition('person_id in ('.$directed_staff.')'); $schedule_activities = new RowManager_ActivityScheduleManager(); $activities = new RowManager_StaffActivityManager(); $activityTypes = new RowManager_ActivityTypeManager(); $person_info = new RowManager_PersonManager(); $staff = new RowManager_StaffManager(); $dataAccessObject->addRowManager($activities); $dataAccessObject->addRowManager($schedule_activities, new JoinPair($activities->getJoinOnActivityID(), $schedule_activities->getJoinOnActivityID())); $dataAccessObject->addRowManager($schedules, new JoinPair($schedules->getJoinOnScheduleID(), $schedule_activities->getJoinOnScheduleID())); $dataAccessObject->addRowManager($activityTypes, new JoinPair($activityTypes->getJoinOnActivityTypeID(), $activities->getJoinOnActivityTypeID())); $dataAccessObject->addRowManager($person_info, new JoinPair($person_info->getJoinOnPersonID(), $activities->getJoinOnPersonID())); $dataAccessObject->addRowManager($staff, new JoinPair($staff->getJoinOnPersonID(), $person_info->getJoinOnPersonID())); $dataAccessObject->addSearchCondition('staff_id in (' . $directed_staff . ')'); $dataAccessObject->setSortOrder($sortBy); $this->listManager = $dataAccessObject->getListIterator(); } else { $dataAccessObject = new RowManager_StaffActivityManager(page_ViewScheduleCalendar::UNAUTHORIZED_DIRECTOR); $this->listManager = $dataAccessObject->getListIterator(); } } $this->monthEvents = array(); // $eventsOfType = array(); // stores events/activities of a specific type // $eventDetails = array(); // stores details for a specific person's event $eventsArray = $this->listManager->getDataList(); reset($eventsArray); if (count($eventsArray) > 0) { // Search through found activities foreach (array_keys($eventsArray) as $key) { $record = current($eventsArray); $activity_id = $record['staffactivity_id']; $activity_desc = $record['activitytype_desc']; $person_name = $record['person_fname'] . ' ' . $record['person_lname']; $contact_phone = $record['staffactivity_contactPhone']; $activity_type = $record['activitytype_abbr']; // $eventDetails[$activity_id][0] = $person_name; // $eventDetails[$activity_id][1] = $contact_phone; // // $eventsOfType[$activity_type] = $eventDetails; $startdate_parts = explode('-', $record['staffactivity_startdate']); $enddate_parts = explode('-', $record['staffactivity_enddate']); // Store event information by weekday for ($month_id = $startdate_parts[1]; $month_id <= $enddate_parts[1]; $month_id++) { if ($this->month_id == $month_id) { $start_day = $startdate_parts[2]; if (substr($start_day, 0, 1) == 0) { $start_day = substr($start_day, 1); } $end_day = $enddate_parts[2]; if (substr($end_day, 0, 1) == 0) { $end_day = substr($end_day, 1); } // Store the event data (name and contact #) for each valid day of the month $init_day = page_ViewScheduleCalendar::FIRST_MONTH_DATE; $last_day = page_ViewScheduleCalendar::MAX_MONTH_DATE; if ($startdate_parts[1] == $enddate_parts[1]) { $init_day = $start_day; $last_day = $end_day; } else { if ($month_id == $startdate_parts[1]) { $init_day = $start_day; $last_day = page_ViewScheduleCalendar::MAX_MONTH_DATE; } else { if ($month_id == $enddate_parts[1]) { $init_day = page_ViewScheduleCalendar::FIRST_MONTH_DATE; $last_day = $end_day; } else { $init_day = page_ViewScheduleCalendar::FIRST_MONTH_DATE; $last_day = page_ViewScheduleCalendar::MAX_MONTH_DATE; } } } // Use the init and last day values as set based on above conditions for ($day_id = $init_day; $day_id <= $last_day; $day_id++) { $this->monthEvents[$day_id][$activity_type][$activity_id][0] = $activity_desc; $this->monthEvents[$day_id][$activity_type][$activity_id][1] = $person_name; $this->monthEvents[$day_id][$activity_type][$activity_id][2] = $contact_phone; //$this->monthEvents[$day_id] = $eventsOfType; } } } next($eventsArray); } } /** TEST **/ // $values = $this->listManager->getDataList(); // echo 'values found = <pre>'.print_r($values,true).'</pre>'; /** END TEST **/ // now initialize the labels for this page // start by loading the default field labels for this Module $languageID = $viewer->getLanguageID(); $seriesKey = modulecim_hrdb::MULTILINGUAL_SERIES_KEY; $pageKey = modulecim_hrdb::MULTILINGUAL_PAGE_FIELDS; $this->labels = new MultilingualManager($languageID, $seriesKey, $pageKey); // then load the page specific labels for this page $pageKey = page_ViewScheduleCalendar::MULTILINGUAL_PAGE_KEY; $this->labels->loadPageLabels($pageKey); $this->labels->setSeriesKey(SITE_LABEL_SERIES_SITE); $this->labels->loadPageLabels(SITE_LABEL_PAGE_FORM_LINKS); }
/** * function __construct * <pre> * Initialize the object. * </pre> * @param $pathModuleRoot [STRING] The path to the module's root dir. * @param $viewer [OBJECT] The viewer object. * @param $sortBy [STRING] Field data to sort listManager by. * @param $managerInit [INTEGER] Initialization value for the listManager. * @return [void] */ function __construct($pathModuleRoot, $viewer, $sortBy, $staffactivity_id = '', $activitytype_id = '', $disable_heading = false, $start_date = '', $end_date = '') { // remove activity types from page listing if there is only one common activity type if ($activitytype_id != '') { $DISPLAY_FIELDS = 'person_id,staffactivity_startdate,staffactivity_enddate,staffactivity_contactPhone'; parent::__construct($DISPLAY_FIELDS); } else { parent::__construct(page_ViewStaffActivities::DISPLAY_FIELDS); } // $this->testdate = $start_date; // echo 'dates = '.$start_date.' and '.$end_date; $this->pathModuleRoot = $pathModuleRoot; $this->viewer = $viewer; $this->staffactivityID = $staffactivity_id; $this->activityTypeID = $activitytype_id; $this->disableHeading = $disable_heading; // Default sorting: person_id, start_date, end_date // TODO: use person name not person_id if ($sortBy == '') { $sortBy = 'person_id,staffactivity_startdate,staffactivity_enddate'; } // Now load the access Priviledge manager of this viewer $this->adminManager = new RowManager_AdminManager(); // Get the person ID $accessManager = new RowManager_AccessManager(); $accessManager->loadByViewerID($this->viewer->getViewerID()); $personID = $accessManager->getPersonID(); // Get the permissions the person has. $this->adminManager->loadByPersonID($personID); // Super-admin if ($this->adminManager->hasSitePriv()) { /*** Setup basic details for Staff Activity data-access object **/ if ($this->staffactivityID != '') { $dataAccessObject = new RowManager_StaffActivityManager($this->staffactivityID); } else { $dataAccessObject = new RowManager_StaffActivityManager(); } if ($this->activityTypeID != '') { $dataAccessObject->setActivityTypeID($this->activityTypeID); } if ($start_date != '' && $end_date != '') { // Create sub-query 1: activity date-range falls exactly within (or equal to) the date-range parameters $activities1 = new RowManager_StaffActivityManager(); $activities_manager1 = new MultiTableManager(); $activities_manager1->addRowManager($activities1); $activities_manager1->setFieldList('staffactivity_id'); $dateWithinRange = "staffactivity_startdate >= '" . $start_date . "' and staffactivity_enddate <= '" . $end_date . "'"; $activities_manager1->addSearchCondition($dateWithinRange); $internalRange_subQuery = $activities_manager1->createSQL(); // Create sub-query 2: activity date-range encloses (or is equal to) the date-range parameters $activities2 = new RowManager_StaffActivityManager(); $activities_manager2 = new MultiTableManager(); $activities_manager2->addRowManager($activities2); $activities_manager2->setFieldList('staffactivity_id'); $dateWithinRange = "staffactivity_startdate <= '" . $start_date . "' and staffactivity_enddate >= '" . $end_date . "'"; $activities_manager2->addSearchCondition($dateWithinRange); $containsRange_subQuery = $activities_manager2->createSQL(); // Create final query condition which includes Case 3: date-range parameters are intersected by activity date-range $validDateConditions = "staffactivity_startdate between '" . $start_date . "' and '" . $end_date . "' or "; $validDateConditions .= "staffactivity_enddate between '" . $start_date . "' and '" . $end_date . "' or "; $validDateConditions .= "staffactivity_id in (" . $internalRange_subQuery . ") or "; $validDateConditions .= "staffactivity_id in (" . $containsRange_subQuery . ")"; $dataAccessObject->addSearchCondition($validDateConditions); } $dataAccessObject->setSortOrder($sortBy); $this->listManager = $dataAccessObject->getListIterator(); } else { if ($this->adminManager->isStaff($viewer->getID())) { $director_id = $this->getStaffIDfromViewerID(); // $staffPersonManager = new MultiTableManager(); $staffManager = new RowManager_StaffDirectorManager(); $staffManager->setDirectorID($director_id); // $staffInfoManager = new RowManager_StaffManager(); // $staffPersonManager->addRowManager($staffInfoManager); // $staffPersonManager->addRowManager($staffManager, new JoinPair($staffManager->getJoinOnStaffID(),$staffInfoManager->getJoinOnStaffID())); // $staffList = $staffPersonManager->getListIterator(); // $staffArray = $staffList->getDataList(); /* Retrieve all directors under the current director */ $hierarchy_result = $staffManager->getDirectorHierarchy($director_id); $hierarchy_result->setFirst(); $hierarchy_array = array(); $directed_staff = ''; while ($hierarchy_result->moveNext()) { $staff_ids = $hierarchy_result->getCurrentRow(); // echo 'array = <pre>'.print_r($hierarchy_array,true).'</pre>'; for ($lvl = 1; $lvl <= MAX_DIRECTOR_LEVELS; $lvl++) { $staff_id = $staff_ids['staff_lvl' . $lvl]; if ($staff_id != null) { $directed_staff .= $staff_id . ','; } } } if ($directed_staff != '') { $directed_staff .= $director_id; //= substr( $directed_staff, 0, -1 ); } else { $directed_staff = $director_id; //page_ViewScheduleCalendar::NON_DIRECTOR; } // Filter activities by those staff persons found in the list of staff under the direction of the current viewer $dataAccessObject = new MultiTableManager(); $schedules = new RowManager_StaffScheduleManager(); // $schedules->addSearchCondition('person_id in ('.$directed_staff.')'); $schedule_activities = new RowManager_ActivityScheduleManager(); $activities = new RowManager_StaffActivityManager(); if ($this->staffactivityID != '') { $activities = new RowManager_StaffActivityManager($this->staffactivityID); } if ($this->activityTypeID != '') { $activities->setActivityTypeID($this->activityTypeID); } $validDateConditions = ''; if ($start_date != '' && $end_date != '') { // Create sub-query 1: activity date-range falls exactly within (or equal to) the date-range parameters $activities1 = new RowManager_StaffActivityManager(); $activities_manager1 = new MultiTableManager(); $activities_manager1->addRowManager($activities1); $activities_manager1->setFieldList('staffactivity_id'); $dateWithinRange = "staffactivity_startdate >= '" . $start_date . "' and staffactivity_enddate <= '" . $end_date . "'"; $activities_manager1->addSearchCondition($dateWithinRange); $internalRange_subQuery = $activities_manager1->createSQL(); // Create sub-query 2: activity date-range falls exactly within (or equal to) the date-range parameters $activities2 = new RowManager_StaffActivityManager(); $activities_manager2 = new MultiTableManager(); $activities_manager2->addRowManager($activities2); $activities_manager2->setFieldList('staffactivity_id'); $dateWithinRange = "staffactivity_startdate <= '" . $start_date . "' and staffactivity_enddate >= '" . $end_date . "'"; $activities_manager2->addSearchCondition($dateWithinRange); $containsRange_subQuery = $activities_manager2->createSQL(); // Create final query condition which includes Case 3: date-range parameters are intersected by activity date-range $validDateConditions = "staffactivity_startdate between '" . $start_date . "' and '" . $end_date . "' or "; $validDateConditions .= "staffactivity_enddate between '" . $start_date . "' and '" . $end_date . "' or "; $validDateConditions .= "cim_hrdb_staffactivity.staffactivity_id in (" . $internalRange_subQuery . ") or "; $validDateConditions .= "cim_hrdb_staffactivity.staffactivity_id in (" . $containsRange_subQuery . ")"; // $activities->addSearchCondition($validDateConditions); } // $activityTypes = new RowManager_ActivityTypeManager(); $person_info = new RowManager_PersonManager(); $staff = new RowManager_StaffManager(); $dataAccessObject->addRowManager($activities); $dataAccessObject->addRowManager($schedule_activities, new JoinPair($activities->getJoinOnActivityID(), $schedule_activities->getJoinOnActivityID())); $dataAccessObject->addRowManager($schedules, new JoinPair($schedules->getJoinOnScheduleID(), $schedule_activities->getJoinOnScheduleID())); // $dataAccessObject->addRowManager($activityTypes, new JoinPair($activityTypes->getJoinOnActivityTypeID(), $activities->getJoinOnActivityTypeID())); $dataAccessObject->addRowManager($person_info, new JoinPair($person_info->getJoinOnPersonID(), $activities->getJoinOnPersonID())); $dataAccessObject->addRowManager($staff, new JoinPair($staff->getJoinOnPersonID(), $person_info->getJoinOnPersonID())); $dataAccessObject->addSearchCondition('staff_id in (' . $directed_staff . ')'); // $dataAccessObject->setFieldList('cim_hrdb_staffactivity.person_id,staffactivity_startdate,staffactivity_enddate,staffactivity_contactPhone'); //page_ViewStaffActivities::DISPLAY_FIELDS); if ($validDateConditions != '') { $dataAccessObject->addSearchCondition($validDateConditions); } // if (!isset($sortBy)||($sortBy == '')) // { // $sortBy = 'person_lname'; // TODO: remove this once we figure how to sort person even if name is cover for person_id // } // $dataAccessObject->setSortOrder( $sortBy ); $list_iterator = $dataAccessObject->getListIterator(); $data_array = $list_iterator->getDataList(); // Go through the inefficient process of grabbing staff activity IDs (could do min. as subquery) $staff_activities = ''; reset($data_array); foreach (array_keys($data_array) as $key) { $row = current($data_array); $staff_activities .= $row['staffactivity_id'] . ','; next($data_array); } if ($staff_activities != '') { $staff_activities = substr($staff_activities, 0, -1); } else { $staff_activities = page_ViewStaffActivities::NO_ACTIVITIES; } // echo "<pre>".print_r($data_array,true)."</pre>"; // echo '<br>activities = '.$staff_activities.'<br>'; /** Apparently we need to use single row manager for staff activity table: therefore use found activity IDs... **/ $activities2 = new RowManager_StaffActivityManager($this->staffactivityID); $activities2->addSearchCondition('staffactivity_id in (' . $staff_activities . ')'); if (!isset($sortBy) || $sortBy == '' || $sortBy == 'person_id') { $sortBy = 'person_lname'; // TODO: remove this once we figure how to sort person even if name is cover for person_id } $activities2->setSortOrder($sortBy); $this->listManager = $activities2->getListIterator(); // dataAccessObject // echo "<pre>".print_r($this->listManager->getDataList(),true)."</pre>"; } else { $dataAccessObject = new RowManager_StaffActivityManager(page_ViewStaffActivities::UNAUTHORIZED_DIRECTOR); $this->listManager = $dataAccessObject->getListIterator(); } } // now initialize the labels for this page // start by loading the default field labels for this Module $languageID = $viewer->getLanguageID(); $seriesKey = modulecim_hrdb::MULTILINGUAL_SERIES_KEY; $pageKey = modulecim_hrdb::MULTILINGUAL_PAGE_FIELDS; $this->labels = new MultilingualManager($languageID, $seriesKey, $pageKey); // then load the page specific labels for this page $pageKey = page_ViewStaffActivities::MULTILINGUAL_PAGE_KEY; $this->labels->loadPageLabels($pageKey); $this->labels->setSeriesKey(SITE_LABEL_SERIES_SITE); $this->labels->loadPageLabels(SITE_LABEL_PAGE_FORM_LINKS); }