/** * function getHTML * <pre> * This method returns the HTML data generated by this object. * </pre> * @return [STRING] HTML Display data. */ function getHTML() { // Uncomment the following line if you want to create a template // tailored for this page: $path = $this->pathModuleRoot . 'templates/'; // Otherwise use the standard Templates for the site: //$path = SITE_PATH_TEMPLATES; /* * store the link values */ // example: // $this->linkValues[ 'view' ] = 'add/new/href/data/here'; // store the link labels // Disable form? // if ($this->disableForm != true) // { $this->linkLabels['edit'] = $this->labels->getLabel('[Edit]'); $this->linkLabels['del'] = $this->labels->getLabel('[Delete]'); // } $this->linkLabels['cont'] = $this->labels->getLabel('[Continue]'); // $this->linkLabels[ 'view' ] = 'new link label here'; /* * store any additional link Columns */ // example: //$title = $this->labels->getLabel( '[title_groups]'); //$columnLabel = $this->labels->getLabel( '[groups]'); //$link = $this->linkValues[ 'groups' ]; //$fieldName = 'accessgroup_id'; //$this->addLinkColumn( $title, $columnLabel, $link, $fieldName); /* * Update any label tags ... */ // example: // $name = $user->getName(); // $this->labels->setLabelTag( '[Title]', '[userName]', $name); // NOTE: this parent method prepares the $this->template with the // common AdminBox data. $this->prepareTemplate($path); // store the statevar id to edit $this->template->set('editEntryID', $this->staffactivity_id); $this->formValues['form_name'] = 'scheduledActivityForm'; // store all the fields to the template $this->setFormFieldsToTemplate(); /* * Form related Template variables: */ // Disable form? if ($this->disableForm == true) { $this->template->set('disableForm', $this->disableForm); } /* * Insert the date start/end values for the following date fields: */ // example: //$this->template->set( 'startYear_[fieldName]', 2000); //$this->template->set( 'endYear_[fieldName]', 2010); $this->template->set('startYear_staffactivity_startdate', 2000); $this->template->set('endYear_staffactivity_startdate', 2010); $this->template->set('startYear_staffactivity_enddate', 2000); $this->template->set('endYear_staffactivity_enddate', 2010); /* * List related Template variables : */ // Store the XML Node name for the Data Access Field List $xmlNodeName = RowManager_StaffActivityManager::XML_NODE_NAME; $this->template->set('rowManagerXMLNodeName', $xmlNodeName); // store the primary key field name for the data being displayed $this->template->set('primaryKeyFieldName', 'staffactivity_id'); // store data list to the template // NOTE: we initialize it here to make sure we capture any new data // from a recent processData() call. $dataAccessManager = new RowManager_StaffActivityManager(); if ($this->form_start_date != '' && $this->form_end_date != '') { $dataAccessManager->constructSearchCondition('staffactivity_startdate', '>=', $this->form_start_date, true); $dataAccessManager->constructSearchCondition('staffactivity_enddate', '<=', $this->form_end_date, true); } // if ($this->showOnlyVacation == true) // { // $dataAccessManager->setActivityTypeID('1'); // **HACK** activitytype set to vacation // } if (count($this->activityTypesFilter) > 0) { $activityTypesList = implode(',', $this->activityTypesFilter); $dataAccessManager->addSearchCondition('activitytype_id in (' . $activityTypesList . ')'); // $dataAccessManager->constructSearchCondition('activitytype_id','=',$activityTypesList, true); } $dataAccessManager->setPersonID($this->person_id); $dataAccessManager->setSortOrder($this->sortBy); // $this->dataList = new StaffActivityList( $this->sortBy ); $this->dataList = $dataAccessManager->getListIterator(); // $dataAccessManager $this->template->setXML('dataList', $this->dataList->getXML()); /* * Add any additional data required by the template here */ $this->template->set('disableHeading', $this->disableHeading); $activitytype = new RowManager_ActivityTypeManager(); // if ($this->showOnlyVacation == true) // { // $activitytype->setActivityTypeID('1'); // **HACK** activitytype set to vacation // } if (count($this->activityTypesFilter) > 0) { $activityTypesList = implode(',', $this->activityTypesFilter); if ($activityTypesList != '') { $activitytype->addSearchCondition('activitytype_id in (' . $activityTypesList . ')'); } } $activitytype->setSortOrder('activitytype_desc'); // $activitytypeList = new ListIterator($activitytype); // $activitytypeArray = $activitytypeList->getDropListArray(); $activitytypeList = $activitytype->getListIterator(); $activitytypeArray = $activitytypeList->getDataList(); foreach (array_keys($activitytypeArray) as $key) { $record = current($activitytypeArray); $colorCode = $record['activitytype_color']; $eventDesc = $record['activitytype_desc']; $activitytypeArray[$key] = '<span style="color:' . $colorCode . ';">' . $eventDesc . '</span>'; next($activitytypeArray); } $this->template->set('list_activitytype_id', $activitytypeArray); /* First check to see whether start date > end date * then check if date matches form date context */ if (isset($this->dateSwitchMessage)) { $this->template->set('date_error_msg', $this->dateSwitchMessage); } else { if (isset($this->dateContextMessage)) { $this->template->set('date_error_msg', $this->dateContextMessage); } } // $templateName = 'siteAdminBox.php'; // if you are creating a custom template for this page then // replace $templateName with the following: $this->template->set('formName', $this->formValues['form_name']); $templateName = 'page_EditStaffActivity.tpl.php'; return $this->template->fetch($templateName); }
/** * 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); }