/** * 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, $year_id = "", $campus_id = "") { parent::__construct(page_ViewStudentYearInSchool::DISPLAY_FIELDS); $this->pathModuleRoot = $pathModuleRoot; $this->viewer = $viewer; $this->year_id = $year_id; $this->campus_id = $campus_id; // echo 'campusID['.$this->campus_id.']<br/>'; // $this->managerInit = $managerInit; // 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); // need to filter displayed data by campus associated with campus admin $campusAdminSearchCondition = ''; if ($this->adminManager->hasSitePriv()) { $campusManager = new RowManager_CampusManager(); $campusManager->setSortOrder('campus_desc'); $this->campusList = $campusManager->getListIterator(); $this->accessibleCampuses = $this->campusList->getDropListArray(); } else { if ($this->adminManager->hasCampusPriv()) { $campusAdminManager = new RowManager_CampusAdminManager(); $adminID = $this->adminManager->getID(); // echo 'adminID['.$adminID.']<br/>'; $campusAdminManager->setAdminID($adminID); $campusList = $campusAdminManager->getListIterator(); //$multiTableManager->getListIterator(); $campusArray = $campusList->getDataList(); $campusIDsList = ""; // init the CSV of campus IDs associated with admin reset($campusArray); foreach (array_keys($campusArray) as $k) { $record = current($campusArray); $campusIDsList .= $record['campus_id'] . ','; // create list of admin campuses next($campusArray); } $campusIDsList = substr($campusIDsList, 0, -1); // remove last comma $campusAdminSearchCondition = 'cim_hrdb_assignment.campus_id in (' . $campusIDsList . ')'; } else { if ($this->adminManager->isStaff($viewer->getID())) { $staffManager = new RowManager_StaffManager(); $staffManager->setPersonID($personID); $multiTableManager = new MultiTableManager(); $multiTableManager->addRowManager($staffManager); $multiTableManager->setSortOrder('campus_desc'); $assignmentManager = new RowManager_AssignmentsManager(); $multiTableManager->addRowManager($assignmentManager, new JoinPair($assignmentManager->getJoinOnPersonID(), $staffManager->getJoinOnPersonID())); $campusManager = new RowManager_CampusManager(); $multiTableManager->addRowManager($campusManager, new JoinPair($campusManager->getJoinOnCampusID(), $assignmentManager->getJoinOnCampusID())); $this->campusList = $multiTableManager->getListIterator(); $campusIDsList = ""; // init the CSV of campus IDs associated with admin $this->campusList->setFirst(); while ($this->campusList->moveNext()) { $campusAssignObject = $this->campusList->getCurrent(new RowManager_AssignmentsManager()); $campusObject = $this->campusList->getCurrent(new RowManager_CampusManager()); $campusIDsList .= $campusAssignObject->getCampusID() . ','; // create list of admin campuses } $campusIDsList = substr($campusIDsList, 0, -1); // remove last comma $campusAdminSearchCondition = 'cim_hrdb_assignment.campus_id in (' . $campusIDsList . ')'; } } } $yearManager = new RowManager_YearInSchoolManager(); $yearManager->setSortOrder('year_id'); $this->yearValueList = $yearManager->getListIterator(); $this->yearValues = $this->yearValueList->getDropListArray(); // Add value to drop-list for showing person data for people not having person_year record $keys = array_keys($this->yearValues); $this->UNASSIGNED_IDX = $keys[count($this->yearValues) - 1] + 1; // assumes autoincrement is active on table $this->yearValues[$this->UNASSIGNED_IDX] = page_ViewStudentYearInSchool::UNASSIGNED; // echo 'values = <pre>'.print_r($this->yearValues, true).'</pre>'; // modify the year_id if necessary if ($this->year_id == page_ViewStudentYearInSchool::DISPLAY_ALL_ID) { // setting the year_id to blank will get entries from all the years $this->year_id = ''; } else { if ($this->year_id == '') { // no campus has been specified // choose a default campus if none specified // echo 'No campus specified<br/>'; // get the first element from the accessible list foreach ($this->yearValues as $key => $value) { $this->year_id = $key; break; } // assert campus_id should now be something if ($this->year_id == '') { die("ERROR - year_id not set to anything<br/>"); } } } $dataAccessObject = new MultiTableManager(); // Check if regular choice made (i.e. person has some year_in_school record) if ($this->year_id != $this->UNASSIGNED_IDX) { $personYearManager = new RowManager_PersonYearManager(); $personYearManager->setYear($this->year_id); // SOMEWHAT REDUNDANT GIVEN addSearchCondition (which is required) $dataAccessObject->addRowManager($personYearManager); $yearManager = new RowManager_YearInSchoolManager(); $joinPair = new JoinPair($personYearManager->getJoinOnYearID(), $yearManager->getJoinOnYearID()); $dataAccessObject->addRowManager($yearManager, $joinPair); $personManager = new RowManager_PersonManager(); $joinPair1 = new JoinPair($personManager->getJoinOnPersonID(), $personYearManager->getJoinOnPersonID()); $dataAccessObject->addRowManager($personManager, $joinPair1); $assignmentManager = new RowManager_AssignmentsManager(); $joinPair2 = new JoinPair($personYearManager->getJoinOnPersonID(), $assignmentManager->getJoinOnPersonID()); $dataAccessObject->addRowManager($assignmentManager, $joinPair2); $campusManager = new RowManager_CampusManager(); $joinPair3 = new JoinPair($assignmentManager->getJoinOnCampusID(), $campusManager->getJoinOnCampusID()); $dataAccessObject->addRowManager($campusManager, $joinPair3); if ($sortBy == '') { $sortBy = 'campus_shortDesc,person_lname'; } if ($this->year_id != '') { $dataAccessObject->addSearchCondition('cim_hrdb_person_year.year_id = ' . $this->year_id); } // filter by campuses assigned to this campus admin if ($campusAdminSearchCondition != '') { $dataAccessObject->addSearchCondition($campusAdminSearchCondition); } $dataAccessObject->setSortOrder($sortBy); $this->listManager = $dataAccessObject->getListIterator(); } else { // $personYearManager = new RowManager_PersonYearManager(); // $personYearManager->setYear($this->year_id); // SOMEWHAT REDUNDANT GIVEN addSearchCondition (which is required) // $dataAccessObject->addRowManager( $personYearManager ); // // $yearManager = new RowManager_YearInSchoolManager(); // $joinPair = new JoinPair($personYearManager->getJoinOnYearID(), $yearManager->getJoinOnYearID()); // $dataAccessObject->addRowManager( $yearManager, $joinPair ); $personManager = new RowManager_PersonManager(); $dataAccessObject->addRowManager($personManager); $assignmentManager = new RowManager_AssignmentsManager(); $joinPair2 = new JoinPair($personManager->getJoinOnPersonID(), $assignmentManager->getJoinOnPersonID()); $dataAccessObject->addRowManager($assignmentManager, $joinPair2); $campusManager = new RowManager_CampusManager(); $joinPair3 = new JoinPair($assignmentManager->getJoinOnCampusID(), $campusManager->getJoinOnCampusID()); $dataAccessObject->addRowManager($campusManager, $joinPair3); if ($sortBy == '') { $sortBy = 'campus_shortDesc,person_lname'; } // get sub-query data for filtering out registrants that have already been registered for event $subManager = new RowManager_PersonYearManager(); $personYearManager = new MultiTableManager(); $personYearManager->addRowManager($subManager); $personYearManager->setFieldList('person_id'); $registered_SQL = $personYearManager->createSQL(); // echo "<br>CREATED SQL 1 = ".$registered_SQL; // actually creates the sub-query ensuring that registrants listed do NOT have personyear records $negateSubQuery = true; $addSubQuery = true; $dataAccessObject->constructSubQuery('person_id', $registered_SQL, $negateSubQuery, $addSubQuery); // filter by campuses assigned to this campus admin if ($campusAdminSearchCondition != '') { $dataAccessObject->addSearchCondition($campusAdminSearchCondition); } $dataAccessObject->setSortOrder($sortBy); $this->listManager = $dataAccessObject->getListIterator(); } /** 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_ViewStudentYearInSchool::MULTILINGUAL_PAGE_KEY; $this->labels->loadPageLabels($pageKey); $this->labels->setSeriesKey(SITE_LABEL_SERIES_SITE); $this->labels->loadPageLabels(SITE_LABEL_PAGE_FORM_LINKS); }
/** * function getBasePriceForRegistrant * <pre> * Returns registration cost for a particular registration, not including scholarship discounts * </pre> * Pre-condition: all variables must be initialized with proper values * * @param $regID [INTEGER] registration ID * @param $eventID [INTEGER] event ID * @param $campusID [INTEGER] campus ID (precondition: must be associated directly with registration ID) * @param $eventBasePrice [INTEGER] the cost of the event per registration, before any discounts * @param $priceRulesArray [ARRAY] an array of the price rules applying to event denoted by $eventID * @param &$rulesApplied [ARRAY REFERENCE] reference to an array to be filled with applied rules * @return [INTEGER] $basePriceForThisGuy the new base price for registration $regID (before scholarships) */ function getBasePriceForRegistrant($regID, $eventID, $campusID, $eventBasePrice, $priceRulesArray, &$rulesApplied = array()) { // Need to manually calculate discounts for these exceptions: $BC_SUMMIT_2007 = 19; $MB_SUMMIT_2007 = 22; $LAKESHORE_SUMMIT_2007 = 25; $EASTERN_WC_2007 = 28; $AIA_NATIONAL_TRAINING = 33; $MARITIMES_SUMMIT_2008 = 34; $basePriceForThisGuy = $eventBasePrice; // echo "<pre>".print_r($priceRulesArray,true)."</pre>"; // PUT SPECIAL EVENT EXCEPTIONS HERE AS CONDITIONAL STATEMENTS: /* if ($eventID == $MARITIMES_SUMMIT_2008) { $FROSH_DISCOUNT_FIELD = 119; // first check for Frosh Discount $fieldValue = new RowManager_FieldValueManager(); // $fieldValue->loadByFieldIDandRegID($rule['fields_id'],$regID); $fieldValue->setFieldID($FROSH_DISCOUNT_FIELD); $fieldValue->setRegID($regID); $valueListManager = $fieldValue->getListIterator(); $fieldValueList = $valueListManager->getDataList(); // echo "<pre>".print_r($fieldValueList,true)."</pre>"; reset($fieldValueList); $record = current($fieldValueList); // CHECK TO SEE IF SOME FIELD VALUE HAS BEEN SET FOR GIVEN PARAMETERS // $userValue = ''; $userValue = $record['fieldvalues_value']; // $fieldValue->getFieldValue(); if ((isset($userValue))&&($userValue != '')) { // DETERMINE WHETHER PRICE RULE VALUE IS EQUIVALENT TO CURRENT FIELD VALUE if ( $userValue == '1') { // form criteria is met, apply the discount/penalty // $basePriceForThisGuy -= 15; // subtract $15 from $65 event base cost $basePriceForThisGuy = 50; // frosh cost $rulesApplied[] = $priceRulesArray['45']; return $basePriceForThisGuy; } } // if no frosh discount, THEN apply early bird discount (if conditions met) // echo "DATE RULE<BR>"; // get the user's registration date $registration = new RowManager_RegistrationManager(); $registration->setRegID($regID); $regListManager = $registration->getListIterator(); $regArray = $regListManager->getDataList(); // echo "<pre>".print_r($registration,true)."</pre>"; // set default date-time $regTime = ''; // retrieve registration date reset($regArray); $record = current($regArray); // should be only 1 record for regID $regTime = $record['registration_date']; // $regTime = $registration->getRegistrationDate(); if ($regTime != '') { // if the registrant signed up before a deadline, apply the rule if ( strtotime($regTime) < strtotime( '2008-04-01' ) ) //$rule['pricerules_value'] { // date criteria is met, apply the discount/penalty // $basePriceForThisGuy -= 15; // apply early bird discount to $65 event base cost to get $50 $basePriceForThisGuy = 50; $rulesApplied[] = $priceRulesArray['47']; return $basePriceForThisGuy; } } return $basePriceForThisGuy; // otherwise return unaltered base event cost ($125) } */ if ($eventID == $AIA_NATIONAL_TRAINING) { $FOOD_PASS_REQ_FIELD = 102; $HOUSING_REQ_FIELD = 103; // first check for Food Pass Fee $fieldValue = new RowManager_FieldValueManager(); // $fieldValue->loadByFieldIDandRegID($rule['fields_id'],$regID); $fieldValue->setFieldID($FOOD_PASS_REQ_FIELD); $fieldValue->setRegID($regID); $valueListManager = $fieldValue->getListIterator(); $fieldValueList = $valueListManager->getDataList(); // echo "<pre>".print_r($fieldValueList,true)."</pre>"; reset($fieldValueList); $record = current($fieldValueList); // CHECK TO SEE IF SOME FIELD VALUE HAS BEEN SET FOR $FOOD_PASS_REQ_FIELD // $userValue = ''; $userValue = $record['fieldvalues_value']; // $fieldValue->getFieldValue(); if (isset($userValue) && $userValue != '') { /** Get the user's registration date **/ $registration = new RowManager_RegistrationManager(); $registration->setRegID($regID); $regListManager = $registration->getListIterator(); $regArray = $regListManager->getDataList(); // echo "<pre>".print_r($registration,true)."</pre>"; // set default date-time $regTime = ''; // retrieve registration date-time reset($regArray); $record = current($regArray); // should be only 1 record for regID $regTime = $record['registration_date']; // DETERMINE WHETHER PRICE RULE VALUE IS EQUIVALENT TO CURRENT FIELD VALUE if ($userValue == '1') { // form criteria is met, apply the discount/penalty // $basePriceForThisGuy += 100; // add 150 to base 260 event price $basePriceForThisGuy += 150; $rulesApplied[] = $priceRulesArray['39']; // Apply early-bird discount on this if applicable if ($regTime != '') { // if the registrant signed up before a deadline, apply the rule if (strtotime($regTime) < strtotime('2008-04-16')) { $basePriceForThisGuy -= 50; // subtract 50 $rulesApplied[] = $priceRulesArray['42']; } } } } // second check for Housing Fee $fieldValue = new RowManager_FieldValueManager(); // $fieldValue->loadByFieldIDandRegID($rule['fields_id'],$regID); $fieldValue->setFieldID($HOUSING_REQ_FIELD); $fieldValue->setRegID($regID); $valueListManager = $fieldValue->getListIterator(); $fieldValueList = $valueListManager->getDataList(); // echo "<pre>".print_r($fieldValueList,true)."</pre>"; reset($fieldValueList); $record = current($fieldValueList); // CHECK TO SEE IF SOME FIELD VALUE HAS BEEN SET FOR $HOUSING_REQ_FIELD // $userValue = ''; $userValue = $record['fieldvalues_value']; // $fieldValue->getFieldValue(); if (isset($userValue) && $userValue != '') { /** Get the user's registration date **/ $registration = new RowManager_RegistrationManager(); $registration->setRegID($regID); $regListManager = $registration->getListIterator(); $regArray = $regListManager->getDataList(); // echo "<pre>".print_r($registration,true)."</pre>"; // set default date-time $regTime = ''; // retrieve registration date-time reset($regArray); $record = current($regArray); // should be only 1 record for regID $regTime = $record['registration_date']; // DETERMINE WHETHER PRICE RULE VALUE IS EQUIVALENT TO CURRENT FIELD VALUE if ($userValue == '1') { // form criteria is met, apply the discount/penalty // $basePriceForThisGuy += 180; // add 230 to base 260 event price $basePriceForThisGuy += 230; $rulesApplied[] = $priceRulesArray['41']; // Apply early-bird discount on this if applicable if ($regTime != '') { // if the registrant signed up before a deadline, apply the rule if (strtotime($regTime) < strtotime('2008-04-16')) { $basePriceForThisGuy -= 50; // subtract 50 $rulesApplied[] = $priceRulesArray['42']; } } return $basePriceForThisGuy; } } return $basePriceForThisGuy; // otherwise return unaltered base event cost ($125) } if ($eventID == $EASTERN_WC_2007) { $COMMUTER_DISCOUNT_FIELD = 86; // first check for Frosh Discount $fieldValue = new RowManager_FieldValueManager(); // $fieldValue->loadByFieldIDandRegID($rule['fields_id'],$regID); $fieldValue->setFieldID($COMMUTER_DISCOUNT_FIELD); $fieldValue->setRegID($regID); $valueListManager = $fieldValue->getListIterator(); $fieldValueList = $valueListManager->getDataList(); // echo "<pre>".print_r($fieldValueList,true)."</pre>"; reset($fieldValueList); $record = current($fieldValueList); // CHECK TO SEE IF SOME FIELD VALUE HAS BEEN SET FOR GIVEN PARAMETERS // $userValue = ''; $userValue = $record['fieldvalues_value']; // $fieldValue->getFieldValue(); if (isset($userValue) && $userValue != '') { // DETERMINE WHETHER PRICE RULE VALUE IS EQUIVALENT TO CURRENT FIELD VALUE if ($userValue == '1') { // form criteria is met, apply the discount/penalty // $basePriceForThisGuy -= 80; // subtract $80 from $279 event base cost $basePriceForThisGuy = 199; // commuter cost $rulesApplied[] = $priceRulesArray['38']; return $basePriceForThisGuy; } } // if no commuter discount, THEN apply early bird discount (if conditions met) // echo "DATE RULE<BR>"; // get the user's registration date $registration = new RowManager_RegistrationManager(); $registration->setRegID($regID); $regListManager = $registration->getListIterator(); $regArray = $regListManager->getDataList(); // echo "<pre>".print_r($registration,true)."</pre>"; // set default date-time $regTime = ''; // retrieve registration date reset($regArray); $record = current($regArray); // should be only 1 record for regID $regTime = $record['registration_date']; // $regTime = $registration->getRegistrationDate(); if ($regTime != '') { // if the registrant signed up before a deadline, apply the rule if (strtotime($regTime) < strtotime('2007-12-01')) { if (strtotime($regTime) < strtotime('2007-10-09')) { // date criteria is met, apply the discount/penalty // $basePriceForThisGuy -= 50; // apply early bird discounts to $279 event base cost to get $229 $basePriceForThisGuy = 229; $rulesApplied[] = $priceRulesArray['37']; $rulesApplied[] = $priceRulesArray['36']; return $basePriceForThisGuy; } else { // date criteria is met, apply the discount/penalty // $basePriceForThisGuy -= 50; // apply regular discount to $279 event base cost to get $259 $basePriceForThisGuy = 259; $rulesApplied[] = $priceRulesArray['36']; return $basePriceForThisGuy; } } } return $basePriceForThisGuy; // otherwise return unaltered base event cost ($125) } // PUT SPECIAL EVENT EXCEPTIONS HERE AS CONDITIONAL STATEMENTS: if ($eventID == $BC_SUMMIT_2007) { $FROSH_DISCOUNT_FIELD = 54; // first check for Frosh Discount $fieldValue = new RowManager_FieldValueManager(); // $fieldValue->loadByFieldIDandRegID($rule['fields_id'],$regID); $fieldValue->setFieldID($FROSH_DISCOUNT_FIELD); $fieldValue->setRegID($regID); $valueListManager = $fieldValue->getListIterator(); $fieldValueList = $valueListManager->getDataList(); // echo "<pre>".print_r($fieldValueList,true)."</pre>"; reset($fieldValueList); $record = current($fieldValueList); // CHECK TO SEE IF SOME FIELD VALUE HAS BEEN SET FOR GIVEN PARAMETERS // $userValue = ''; $userValue = $record['fieldvalues_value']; // $fieldValue->getFieldValue(); if (isset($userValue) && $userValue != '') { // DETERMINE WHETHER PRICE RULE VALUE IS EQUIVALENT TO CURRENT FIELD VALUE if ($userValue == '1') { // form criteria is met, apply the discount/penalty // $basePriceForThisGuy -= 46; // subtract $46 from $125 event base cost $basePriceForThisGuy = 79; // frosh cost $rulesApplied[] = $priceRulesArray['14']; return $basePriceForThisGuy; } } // if no frosh discount, THEN apply early bird discount (if conditions met) // echo "DATE RULE<BR>"; // get the user's registration date $registration = new RowManager_RegistrationManager(); $registration->setRegID($regID); $regListManager = $registration->getListIterator(); $regArray = $regListManager->getDataList(); // echo "<pre>".print_r($registration,true)."</pre>"; // set default date-time $regTime = ''; // retrieve registration date reset($regArray); $record = current($regArray); // should be only 1 record for regID $regTime = $record['registration_date']; // $regTime = $registration->getRegistrationDate(); if ($regTime != '') { // if the registrant signed up before a deadline, apply the rule if (strtotime($regTime) < strtotime('2007-09-21')) { // date criteria is met, apply the discount/penalty // $basePriceForThisGuy -= 26; // apply early bird discount to $125 event base cost to get $99 $basePriceForThisGuy = 99; $rulesApplied[] = $priceRulesArray['15']; return $basePriceForThisGuy; } } return $basePriceForThisGuy; // otherwise return unaltered base event cost ($125) } if ($eventID == $MB_SUMMIT_2007) { $FROSH_DISCOUNT_FIELD = 60; $FROSH_VOLUME_THRESHOLD = 20; $MB_EARLY_FROSH_TABLE = 'temp_mb_early_frosh'; // first check for Frosh Discount $fieldValue = new RowManager_FieldValueManager(); // $fieldValue->loadByFieldIDandRegID($rule['fields_id'],$regID); $fieldValue->setFieldID($FROSH_DISCOUNT_FIELD); $fieldValue->setRegID($regID); $valueListManager = $fieldValue->getListIterator(); $fieldValueList = $valueListManager->getDataList(); // echo "<pre>".print_r($fieldValueList,true)."</pre>"; reset($fieldValueList); $record = current($fieldValueList); // CHECK TO SEE IF SOME FIELD VALUE HAS BEEN SET FOR GIVEN PARAMETERS // $userValue = ''; $userValue = $record['fieldvalues_value']; // $fieldValue->getFieldValue(); if (isset($userValue) && $userValue != '') { // DETERMINE WHETHER PRICE RULE VALUE IS EQUIVALENT TO CURRENT FIELD VALUE if ($userValue == '1') { // check if there are 20 or more frosh already stored $froshValues = new RowManager_FieldValueManager(); $froshValues->setFieldID($FROSH_DISCOUNT_FIELD); $froshValues->setFieldValue('1'); // 1 = checked checkbox $fieldsManager = new MultiTableManager(); $fieldsManager->addRowManager($froshValues); // TODO: sub-query like 'SELECT <ALL FIELD VALUES FOR SPECIFIC FROSH DISCOUNT> WHERE REG_ID IN (SELECT ALL REGISTRATIONS FOR EVENT)' $regs = new RowManager_RegistrationManager(); $regs->setEventID($eventID); $regData = new MultiTableManager(); $regData->addRowManager($regs); $regData->setFieldList('registration_id'); $registered_SQL = $regData->createSQL(); // actually creates the sub-query in order to get an accurate count of discount field values stored $negateSubQuery = false; $addSubQuery = true; $fieldsManager->constructSubQuery('registration_id', $registered_SQL, $negateSubQuery, $addSubQuery); // $froshValues->setSortOrder('registration_id'); $froshList = $fieldsManager->getListIterator(); $froshArray = array(); $froshArray = $froshList->getDataList(); // echo "COUNT = ".count($froshArray); if (count($froshArray) <= $FROSH_VOLUME_THRESHOLD) { // form criteria is met, apply the discount/penalty // $basePriceForThisGuy -= 25; // subtract $46 from $125 event base cost $basePriceForThisGuy = 40; // frosh cost $rulesApplied[] = $priceRulesArray['25']; $db = new Database_MySQL(); $db->connectToDB(SITE_DB_NAME, SITE_DB_PATH, SITE_DB_USER, SITE_DB_PWORD); // precaution that avoids duplicates $sql = "DELETE FROM " . $MB_EARLY_FROSH_TABLE . " WHERE registration_id = " . $regID; $db->runSQL($sql); $sql = "INSERT INTO " . $MB_EARLY_FROSH_TABLE . " (registration_id) VALUES (" . $regID . ")"; $db->runSQL($sql); } else { $db = new Database_MySQL(); $db->connectToDB(SITE_DB_NAME, SITE_DB_PATH, SITE_DB_USER, SITE_DB_PWORD); $sql = "SELECT * FROM " . $MB_EARLY_FROSH_TABLE . " WHERE registration_id = " . $regID; $db->runSQL($sql); $temp_regID = ''; if ($row = $db->retrieveRow()) { $temp_regID = $row['registration_id']; } // apply rule despite there being >20 frosh because this registration existed before cut-off if ($regID == $temp_regID) { // $basePriceForThisGuy -= 25; // subtract $25 from $85 event base cost $basePriceForThisGuy = 40; // frosh cost $rulesApplied[] = $priceRulesArray['25']; } else { $basePriceForThisGuy = 60; // basic frosh cost $rulesApplied[] = $priceRulesArray['28']; } } return $basePriceForThisGuy; } } return $basePriceForThisGuy; // otherwise return unaltered base event cost ($85) } if ($eventID == $LAKESHORE_SUMMIT_2007) { $FROSH_DISCOUNT_FIELD = 64; // first check for Frosh Discount $fieldValue = new RowManager_FieldValueManager(); // $fieldValue->loadByFieldIDandRegID($rule['fields_id'],$regID); $fieldValue->setFieldID($FROSH_DISCOUNT_FIELD); $fieldValue->setRegID($regID); $valueListManager = $fieldValue->getListIterator(); $fieldValueList = $valueListManager->getDataList(); // echo "<pre>".print_r($fieldValueList,true)."</pre>"; reset($fieldValueList); $record = current($fieldValueList); // CHECK TO SEE IF SOME FIELD VALUE HAS BEEN SET FOR GIVEN PARAMETERS // $userValue = ''; $userValue = $record['fieldvalues_value']; // $fieldValue->getFieldValue(); if (isset($userValue) && $userValue != '') { // DETERMINE WHETHER PRICE RULE VALUE IS EQUIVALENT TO CURRENT FIELD VALUE if ($userValue == '1') { // form criteria is met, apply the discount/penalty // $basePriceForThisGuy -= <varies>; // subtract <varying amount> from $120/$115/$110/$105 to get $75 $basePriceForThisGuy = 75; // frosh cost $rulesApplied[] = $priceRulesArray['19']; return $basePriceForThisGuy; } } // if no frosh discount, THEN apply early bird discount (if conditions met) // echo "DATE RULE<BR>"; // get the user's registration date $registration = new RowManager_RegistrationManager(); $registration->setRegID($regID); $regListManager = $registration->getListIterator(); $regArray = $regListManager->getDataList(); // echo "<pre>".print_r($registration,true)."</pre>"; // set default date-time $regTime = ''; // retrieve registration date reset($regArray); $record = current($regArray); // should be only 1 record for regID $regTime = $record['registration_date']; // $regTime = $registration->getRegistrationDate(); if ($regTime != '') { // if the registrant signed up before a deadline, apply the rule if (strtotime($regTime) < strtotime('2007-09-26')) { // date criteria is met, apply the discount/penalty // $basePriceForThisGuy -= 15; // apply early bird discount to $115 event base cost to get $105 $basePriceForThisGuy = 105; $rulesApplied[] = $priceRulesArray['20']; return $basePriceForThisGuy; } } return $basePriceForThisGuy; // otherwise return unaltered base event cost ($120) } /**** END OF RULE EXCEPTIONS ****/ // apply any price rules foreach ($priceRulesArray as $key => $rule) { $ruleType = $rule['priceruletypes_id']; // form attribute rule: apply price rule based on whether some form field value exists (i.e. frosh discount) if ($ruleType == RowManager_PriceRuleTypeManager::FORM_ATTRIBUTE_RULE) { // echo "FORM RULE<BR>"; // get the user's input for this form attribute $fieldValue = new RowManager_FieldValueManager(); // $fieldValue->loadByFieldIDandRegID($rule['fields_id'],$regID); $fieldValue->setFieldID($rule['fields_id']); $fieldValue->setRegID($regID); $valueListManager = $fieldValue->getListIterator(); $fieldValueList = $valueListManager->getDataList(); // echo "<pre>".print_r($fieldValueList,true)."</pre>"; reset($fieldValueList); $record = current($fieldValueList); // CHECK TO SEE IF SOME FIELD VALUE HAS BEEN SET FOR GIVEN PARAMETERS // $userValue = ''; $userValue = $record['fieldvalues_value']; // $fieldValue->getFieldValue(); if (isset($userValue) && $userValue != '') { // DETERMINE WHETHER PRICE RULE VALUE IS EQUIVALENT TO CURRENT FIELD VALUE if ($rule['pricerules_value'] == $userValue) { // form criteria is met, apply the discount/penalty $basePriceForThisGuy += $rule['pricerules_discount']; $rulesApplied[] = $rule; } } } else { if ($ruleType == RowManager_PriceRuleTypeManager::DATE_RULE) { // echo "DATE RULE<BR>"; // get the user's registration date $registration = new RowManager_RegistrationManager(); $registration->setRegID($regID); $regListManager = $registration->getListIterator(); $regArray = $regListManager->getDataList(); // echo "<pre>".print_r($registration,true)."</pre>"; // set default date-time $regTime = ''; // retrieve registration date reset($regArray); $record = current($regArray); // should be only 1 record for regID $regTime = $record['registration_date']; // $regTime = $registration->getRegistrationDate(); if ($regTime != '') { // if the registrant signed up before a deadline, apply the rule if (strtotime($regTime) < strtotime($rule['pricerules_value'])) { // date criteria is met, apply the discount/penalty $basePriceForThisGuy += $rule['pricerules_discount']; $rulesApplied[] = $rule; } } } else { if ($ruleType == RowManager_PriceRuleTypeManager::VOLUME_RULE) { $volumeNeeded = $rule['pricerules_value']; // $correctCampus = false; // $pattern = RowManager_PriceRuleTypeManager::CAMPUS_VOLUME_REGEX; // $numMatches = preg_match($pattern, $rule['pricerules_value']); // if ($numMatches > 0) // { // // $pricingValues = explode('|',$rule['pricerules_value']); // // echo '<pre>'.print_r($pricingValues,true).'</pre>'; // // echo 'campus = '.$pricingValues[0].' cut-off = '.$pricingValues[1]; // if ((int)$pricingValues[0] == $campusID) // { // $correctCampus = true; // $volumeNeeded = $pricingValues[1]; // // /* if ($numRegistrantsMyCampus != '') // { // // if the # of registrants >= the bulk discount value... // if ( $numRegistrantsMyCampus >= $pricingValues[1] ) // { // // bulk discount criteria is met, apply the discount/penalty // $basePriceForThisGuy += $rule['pricerules_discount']; // // $rulesApplied[] = $rule; // } // } // else // try to calculate the # of registrants on our own // { // */ // // /** } // **/ // } // } // // // check volume rule if no specific campus associated or current campus is associated with rule // if (($numMatches == 0)||($correctCampus == true)) // { if (isset($campusID) && $campusID != '') { // get total registrations for specific campus and particular event $total = array(); $summary = new RegSummaryTools(); $total = $summary->getCampusRegistrations($eventID, '', false, $campusID, '', RowManager_RegistrationManager::STATUS_REGISTERED); if (isset($total[$campusID])) { $numRegistrantsMyCampus = $total[$campusID]; } else { $numRegistrantsMyCampus = 0; } if (count($total) > 0) { // if the # of registrants >= the bulk discount value... if ($numRegistrantsMyCampus >= $volumeNeeded) { // bulk discount criteria is met, apply the discount/penalty $basePriceForThisGuy += $rule['pricerules_discount']; $rulesApplied[] = $rule; } } } else { // should not occur, this function meant to be used with campusID set } } else { if ($ruleType == RowManager_PriceRuleTypeManager::CAMPUS_RULE) { // echo "CAMPUS RULE<BR>"; // check the campus ID against the one stored in the price rules table if ($campusID == $rule['pricerules_value']) { $basePriceForThisGuy += $rule['pricerules_discount']; $rulesApplied[] = $rule; } } else { die('unknown ruletype[' . $ruleType . ']'); } } } } } // foreach rule // special hack for Eastern Ontario/Montreal summit 2006 /* if ( $eventID == 4 ) { $basePriceForThisGuy = getBasePriceEasternSummit2006( $regID, $numRegistrantsMyCampus, $rulesApplied ); } else if ( $eventID == 11 ) { $basePriceForThisGuy = getBasePricePrairieSummit2006( $regID, $campusID, $numRegistrantsMyCampus, $rulesApplied ); } */ return $basePriceForThisGuy; }
/** * 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>'; }
private function generateRegistrantsDroplist() { // $content = $this->_controller->loadEditCampusRegistrations_OffflineRegBox(); //$content = $this->registrants_dropList->getHTML(); $people = new RowManager_PersonManager(); $access = new RowManager_AccessManager(); // ADDED Nov 21, 2007 $viewers = new RowManager_ViewerManager(); // ADDED Nov 21, 2007 $assignment = new RowManager_AssignmentsManager(); $assignment->setCampusID($this->campus_id); $registrants = new MultiTableManager(); $registrants->addRowManager($people); $registrants->addRowManager($assignment, new JoinPair($people->getJoinOnPersonID(), $assignment->getJoinOnPersonID())); $registrants->addRowManager($access, new JoinPair($people->getJoinOnPersonID(), $access->getJoinOnPersonID())); // ADDED Nov 21, 2007 $registrants->addRowManager($viewers, new JoinPair($access->getJoinOnViewerID(), $viewers->getJoinOnViewerID())); // ADDED Nov 21, 2007 // get sub-query data for filtering out registrants that have already been registered for event $regs = new RowManager_RegistrationManager(); $regs->setEventID($this->event_id); // $regs->setPersonID($this->person_id); $status = new RowManager_StatusManager(); $status->setStatusDesc(RowManager_StatusManager::REGISTERED); $regData = new MultiTableManager(); $regData->addRowManager($regs); $regData->addRowManager($status, new JoinPair($regs->getJoinOnStatus(), $status->getJoinOnStatusID())); $regData->setFieldList('person_id'); $registered_SQL = $regData->createSQL(); // echo "<br>CREATED SQL 1 = ".$registered_SQL; // actually creates the sub-query ensuring that registrants in drop-down list are NOT registered $negateSubQuery = true; $addSubQuery = true; $registrants->constructSubQuery('person_id', $registered_SQL, $negateSubQuery, $addSubQuery); $registrants->setSortOrder('person_lname'); $peopleManager = $registrants->getListIterator(); $registrantsArray = $peopleManager->getDataList(); // echo "<br>CREATED SQL 2 = ".$registrants->createSQL(); $registrant = array(); // NOTE: the drop-down list stealthily passes PERSON_ID to controller (see name="SV43") $dropList = '<form name="Form" id="Form" method="post" action="' . $this->registrant_formAction . '">' . 'Select a registrant for offline registration, or choose "New Registrant" :<br><br>' . '<select name="' . modulecim_reg::PERSON_ID . '">' . '<option selected="selected" value="-1">New Registrant</option>'; // retrieve person first and last name from database array reset($registrantsArray); foreach (array_keys($registrantsArray) as $k) { $personData = current($registrantsArray); // $registrant['person_fname'] = $personData['person_fname']; // $registrant['person_lname'] = $personData['person_lname']; // add registrant names to drop-down list // for ($i = 0; $i < $totalPeople; $i++) // { $dropList .= '<option value=' . $personData['person_id'] . '>' . $personData['person_lname'] . ', ' . $personData['person_fname'] . ' (' . $personData['viewer_userID'] . ')</option>'; // } next($registrantsArray); } // $totalPeople = count($ $dropList .= '</select>' . ' <input name="REGISTER" type="submit" value="REGISTER" /></form>'; return $dropList; }
/** * 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); }