function setUser($ids) { Debug::text('Setting User IDs : ', __FILE__, __LINE__, __METHOD__, 10); if (is_array($ids)) { if (!$this->isNew()) { //If needed, delete mappings first. $pgulf = new PolicyGroupUserListFactory(); $pgulf->getByPolicyGroupId($this->getId()); $tmp_ids = array(); foreach ($pgulf as $obj) { $id = $obj->getUser(); Debug::text('Policy ID: ' . $obj->getPolicyGroup() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10); //Delete users that are not selected. if (!in_array($id, $ids)) { Debug::text('Deleting: ' . $id, __FILE__, __LINE__, __METHOD__, 10); $obj->Delete(); } else { //Save ID's that need to be updated. Debug::text('NOT Deleting : ' . $id, __FILE__, __LINE__, __METHOD__, 10); $tmp_ids[] = $id; } } unset($id, $obj); } //Insert new mappings. $ulf = new UserListFactory(); foreach ($ids as $id) { if (isset($ids) and !in_array($id, $tmp_ids)) { $pguf = new PolicyGroupUserFactory(); $pguf->setPolicyGroup($this->getId()); $pguf->setUser($id); $ulf->getById($id); if ($ulf->getRecordCount() > 0) { $obj = $ulf->getCurrent(); if ($this->Validator->isTrue('user', $pguf->Validator->isValid(), TTi18n::gettext('Selected employee is invalid or already assigned to another policy group ') . ' (' . $obj->getFullName() . ')')) { $pguf->save(); } } } } return TRUE; } Debug::text('No User IDs to set.', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
/** * Get absence policy data for one or more absence policyes. * @param array $data filter data * @return array */ function getAbsencePolicy($data = NULL, $disable_paging = FALSE) { if (!$this->getPermissionObject()->Check('absence_policy', 'enabled') or !($this->getPermissionObject()->Check('absence_policy', 'view') or $this->getPermissionObject()->Check('absence_policy', 'view_own') or $this->getPermissionObject()->Check('absence_policy', 'view_child'))) { //return $this->getPermissionObject()->PermissionDenied(); $data['filter_columns'] = $this->handlePermissionFilterColumns(isset($data['filter_columns']) ? $data['filter_columns'] : NULL, Misc::trimSortPrefix($this->getOptions('list_columns'))); } $data = $this->initializeFilterAndPager($data, $disable_paging); //Make sure we filter absence policies to just those assigned to the policy group when user_id filter is passed. if (isset($data['filter_data']['user_id'])) { $user_ids = (array) $data['filter_data']['user_id']; $pgulf = new PolicyGroupUserListFactory(); $pgulf->getByUserId($user_ids); if ($pgulf->getRecordCount() > 0) { $pguf_obj = $pgulf->getCurrent(); $policy_group_id = $pguf_obj->getPolicyGroup(); } if (isset($policy_group_id)) { $cgmlf = new CompanyGenericMapListFactory(); $cgmlf->getByObjectTypeAndObjectID(170, $policy_group_id); if ($cgmlf->getRecordCount() > 0) { foreach ($cgmlf as $cgm_obj) { $absence_policy_ids[] = $cgm_obj->getMapID(); } } } if (isset($absence_policy_ids)) { $data['filter_data']['id'] = $absence_policy_ids; } else { //Make sure that is no absence policies are assigned to the policy group, we don't display any. $data['filter_data']['id'] = array(0); } unset($data['filter_data']['user_id']); } $data['filter_data']['permission_children_ids'] = $this->getPermissionObject()->getPermissionChildren('absence_policy', 'view'); $blf = TTnew('AbsencePolicyListFactory'); $blf->getAPISearchByCompanyIdAndArrayCriteria($this->getCurrentCompanyObject()->getId(), $data['filter_data'], $data['filter_items_per_page'], $data['filter_page'], NULL, $data['filter_sort']); Debug::Text('Record Count: ' . $blf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($blf->getRecordCount() > 0) { $this->setPagerObject($blf); foreach ($blf as $b_obj) { $retarr[] = $b_obj->getObjectAsArray($data['filter_columns']); } return $this->returnHandler($retarr); } return $this->returnHandler(TRUE); //No records returned. }
function Validate() { //Make sure status/type combinations are correct. if (!in_array($this->getType(), $this->getOptions('status_type', $this->getStatus()))) { Debug::text('Type doesnt match status: Type: ' . $this->getType() . ' Status: ' . $this->getStatus(), __FILE__, __LINE__, __METHOD__, 10); $this->Validator->isTRUE('type', FALSE, TTi18n::gettext('Incorrect Type')); } //Check to make sure if this is an absence row, the absence policy is actually set. if ($this->getStatus() == 30 and $this->getAbsencePolicyID() == FALSE) { $this->Validator->isTRUE('absence_policy_id', FALSE, TTi18n::gettext('Please specify an absence type')); } //Check to make sure if this is an overtime row, the overtime policy is actually set. if ($this->getStatus() == 10 and $this->getType() == 30 and $this->getOverTimePolicyID() == FALSE) { $this->Validator->isTRUE('over_time_policy_id', FALSE, TTi18n::gettext('Invalid Overtime Policy')); } //Check to make sure if this is an premium row, the premium policy is actually set. if ($this->getStatus() == 10 and $this->getType() == 40 and $this->getPremiumPolicyID() == FALSE) { $this->Validator->isTRUE('premium_policy_id', FALSE, TTi18n::gettext('Invalid Premium Policy')); } //Check to make sure if this is an meal row, the meal policy is actually set. if ($this->getStatus() == 10 and $this->getType() == 100 and $this->getMealPolicyID() == FALSE) { $this->Validator->isTRUE('meal_policy_id', FALSE, TTi18n::gettext('Invalid Meal Policy')); } //check that the user is allowed to be assigned to the absence policy if ($this->getStatus() == 30 and $this->getAbsencePolicyID() != FALSE and $this->getUserId() != FALSE) { $cgmlf = new CompanyGenericMapListFactory(); $cgmlf->getByCompanyIDAndObjectTypeAndMapID($this->getUserObject()->getCompany(), 170, $this->getAbsencePolicyID()); if ($cgmlf->getRecordCount() > 0) { foreach ($cgmlf as $cgm_obj) { $policy_group_ids[] = $cgm_obj->getObjectID(); } } if (isset($policy_group_ids)) { $pgulf = new PolicyGroupUserListFactory(); foreach ($policy_group_ids as $policy_group_id) { $pgulf->getByPolicyGroupId($policy_group_id); if ($pgulf->getRecordCount() > 0) { foreach ($pgulf as $pgu_obj) { $user_ids[] = $pgu_obj->getUser(); } } } } if (isset($user_ids) and in_array($this->getUserId(), $user_ids) == FALSE) { $this->Validator->isTRUE('absence_policy_id', FALSE, TTi18n::gettext('This absence policy is not available for this employee')); } } //This is likely caused by employee not being assigned to a pay period schedule? //Make sure to allow entries in the future (ie: absences) where no pay period exists yet. if ($this->getDeleted() == FALSE and $this->getUserDateObject() == FALSE) { $this->Validator->isTRUE('date_stamp', FALSE, TTi18n::gettext('Date is incorrect, or pay period does not exist for this date. Please create a pay period schedule and assign this employee to it if you have not done so already')); } elseif (($this->getOverride() == TRUE or $this->getOverride() == FALSE and $this->getStatus() == 30) and is_object($this->getUserDateObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()) and $this->getUserDateObject()->getPayPeriodObject()->getIsLocked() == TRUE) { //Make sure we only check for pay period being locked if override is TRUE, otherwise it can prevent recalculations from occurring //after the pay period is locked (ie: recalculating exceptions each day from maintenance jobs?) //We need to be able to stop absences (non-overridden ones too) from being deleted in closed pay periods. $this->Validator->isTRUE('date_stamp', FALSE, TTi18n::gettext('Pay Period is Currently Locked')); } //Make sure that we aren't trying to overwrite an already overridden entry made by the user for some special purpose. if ($this->getDeleted() == FALSE and $this->isNew() == TRUE and in_array($this->getStatus(), array(10, 20, 30))) { Debug::text('Checking over already existing overridden entries ... User Date ID: ' . $this->getUserDateID() . ' Status ID: ' . $this->getStatus() . ' Type ID: ' . $this->getType(), __FILE__, __LINE__, __METHOD__, 10); $udtlf = TTnew('UserDateTotalListFactory'); if ($this->getStatus() == 20 and $this->getPunchControlID() > 0) { $udtlf->getByUserDateIdAndStatusAndTypeAndPunchControlIdAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getPunchControlID(), TRUE); } elseif ($this->getStatus() == 30) { $udtlf->getByUserDateIdAndStatusAndTypeAndAbsencePolicyIDAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getAbsencePolicyID(), TRUE); } elseif ($this->getStatus() == 10 and $this->getType() == 30) { $udtlf->getByUserDateIdAndStatusAndTypeAndOvertimePolicyIDAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getOverTimePolicyID(), TRUE); } elseif ($this->getStatus() == 10 and $this->getType() == 40) { $udtlf->getByUserDateIdAndStatusAndTypeAndPremiumPolicyIDAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getPremiumPolicyID(), TRUE); } elseif ($this->getStatus() == 10 and $this->getType() == 100) { $udtlf->getByUserDateIdAndStatusAndTypeAndMealPolicyIDAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getMealPolicyID(), TRUE); } elseif ($this->getStatus() == 10 and ($this->getType() == 10 or $this->getType() == 20 and $this->getPunchControlID() > 0)) { $udtlf->getByUserDateIdAndStatusAndTypeAndPunchControlIdAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getPunchControlID(), TRUE); } Debug::text('Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($udtlf->getRecordCount() > 0) { Debug::text('Found an overridden row... NOT SAVING: ' . $udtlf->getCurrent()->getId(), __FILE__, __LINE__, __METHOD__, 10); $this->Validator->isTRUE('absence_policy_id', FALSE, TTi18n::gettext('Similar entry already exists, not overriding')); } } return TRUE; }
function postSave() { $this->removeCache($this->getId()); if ($this->getDeleted() == FALSE and $this->getPermissionControl() !== FALSE) { Debug::text('Permission Group is set...', __FILE__, __LINE__, __METHOD__, 10); $pclf = new PermissionControlListFactory(); $pclf->getByCompanyIdAndUserID($this->getCompany(), $this->getId()); if ($pclf->getRecordCount() > 0) { Debug::text('Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10); $pc_obj = $pclf->getCurrent(); if ($pc_obj->getId() == $this->getPermissionControl()) { $add_permission_control = FALSE; } else { Debug::text('Permission Group has changed...', __FILE__, __LINE__, __METHOD__, 10); //Remove user from current schedule. $pulf = new PermissionUserListFactory(); $pulf->getByPermissionControlIdAndUserID($pc_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $pulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($pulf->getRecordCount() > 0) { foreach ($pulf as $pu_obj) { Debug::text('Deleteing from Permission Group: ' . $pu_obj->getPermissionControl(), __FILE__, __LINE__, __METHOD__, 10); $pu_obj->Delete(); } } $add_permission_control = TRUE; } } else { Debug::text('NOT Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10); $add_permission_control = TRUE; } if ($this->getPermissionControl() !== FALSE and $add_permission_control == TRUE) { Debug::text('Adding user to Permission Group...', __FILE__, __LINE__, __METHOD__, 10); //Add to new permission group $puf = new PermissionUserFactory(); $puf->setPermissionControl($this->getPermissionControl()); $puf->setUser($this->getID()); if ($puf->isValid()) { $puf->Save(); //Clear permission class for this employee. $pf = new PermissionFactory(); $pf->clearCache($this->getID(), $this->getCompany()); } } unset($add_permission_control); } if ($this->getDeleted() == FALSE and $this->getPayPeriodSchedule() !== FALSE) { Debug::text('Pay Period Schedule is set...', __FILE__, __LINE__, __METHOD__, 10); $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getByUserId($this->getId()); if ($ppslf->getRecordCount() > 0) { $pps_obj = $ppslf->getCurrent(); if ($this->getPayPeriodSchedule() == $pps_obj->getId()) { Debug::text('Already assigned to this Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10); $add_pay_period_schedule = FALSE; } else { Debug::text('Changing Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10); //Remove user from current schedule. $ppsulf = new PayPeriodScheduleUserListFactory(); $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($ppsulf->getRecordCount() > 0) { foreach ($ppsulf as $ppsu_obj) { Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10); $ppsu_obj->Delete(); } } $add_pay_period_schedule = TRUE; } } else { Debug::text('Not assigned to ANY Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10); $add_pay_period_schedule = TRUE; } if ($this->getPayPeriodSchedule() !== FALSE and $add_pay_period_schedule == TRUE) { //Add to new pay period schedule $ppsuf = new PayPeriodScheduleUserFactory(); $ppsuf->setPayPeriodSchedule($this->getPayPeriodSchedule()); $ppsuf->setUser($this->getID()); if ($ppsuf->isValid()) { $ppsuf->Save(); } } unset($add_pay_period_schedule); } if ($this->getDeleted() == FALSE and $this->getPolicyGroup() !== FALSE) { Debug::text('Policy Group is set...', __FILE__, __LINE__, __METHOD__, 10); $pglf = new PolicyGroupListFactory(); $pglf->getByUserIds($this->getId()); if ($pglf->getRecordCount() > 0) { $pg_obj = $pglf->getCurrent(); if ($this->getPolicyGroup() == $pg_obj->getId()) { Debug::text('Already assigned to this Policy Group...', __FILE__, __LINE__, __METHOD__, 10); $add_policy_group = FALSE; } else { Debug::text('Changing Policy Group...', __FILE__, __LINE__, __METHOD__, 10); //Remove user from current schedule. $pgulf = new PolicyGroupUserListFactory(); $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($pgulf->getRecordCount() > 0) { foreach ($pgulf as $pgu_obj) { Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10); $pgu_obj->Delete(); } } $add_policy_group = TRUE; } } else { Debug::text('Not assigned to ANY Policy Group...', __FILE__, __LINE__, __METHOD__, 10); $add_policy_group = TRUE; } if ($this->getPolicyGroup() !== FALSE and $add_policy_group == TRUE) { //Add to new policy group $pguf = new PolicyGroupUserFactory(); $pguf->setPolicyGroup($this->getPolicyGroup()); $pguf->setUser($this->getID()); if ($pguf->isValid()) { $pguf->Save(); } } unset($add_policy_group); } if ($this->getDeleted() == FALSE and $this->getHierarchyControl() !== FALSE) { Debug::text('Hierarchies are set...', __FILE__, __LINE__, __METHOD__, 10); $hierarchy_control_data = array_unique(array_values((array) $this->getHierarchyControl())); //Debug::Arr($hierarchy_control_data, 'Setting hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10); if (is_array($hierarchy_control_data)) { $hclf = new HierarchyControlListFactory(); $hclf->getObjectTypeAppendedListByCompanyIDAndUserID($this->getCompany(), $this->getID()); $existing_hierarchy_control_data = array_unique(array_values((array) $hclf->getArrayByListFactory($hclf, FALSE, TRUE, FALSE))); //Debug::Arr($existing_hierarchy_control_data, 'Existing hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10); $hierarchy_control_delete_diff = array_diff($existing_hierarchy_control_data, $hierarchy_control_data); //Debug::Arr($hierarchy_control_delete_diff, 'Hierarchy control delete diff: ', __FILE__, __LINE__, __METHOD__, 10); //Remove user from existing hierarchy control if (is_array($hierarchy_control_delete_diff)) { foreach ($hierarchy_control_delete_diff as $hierarchy_control_id) { if ($hierarchy_control_id != 0) { $hulf = new HierarchyUserListFactory(); $hulf->getByHierarchyControlAndUserID($hierarchy_control_id, $this->getID()); if ($hulf->getRecordCount() > 0) { Debug::text('Deleting user from hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10); $hulf->getCurrent()->Delete(); } } } } unset($hierarchy_control_delete_diff, $hulf, $hclf, $hierarchy_control_id); $hierarchy_control_add_diff = array_diff($hierarchy_control_data, $existing_hierarchy_control_data); //Debug::Arr($hierarchy_control_add_diff, 'Hierarchy control add diff: ', __FILE__, __LINE__, __METHOD__, 10); if (is_array($hierarchy_control_add_diff)) { foreach ($hierarchy_control_add_diff as $hierarchy_control_id) { Debug::text('Hierarchy data changed...', __FILE__, __LINE__, __METHOD__, 10); if ($hierarchy_control_id != 0) { $huf = new HierarchyUserFactory(); $huf->setHierarchyControl($hierarchy_control_id); $huf->setUser($this->getId()); if ($huf->isValid()) { Debug::text('Adding user to hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10); $huf->Save(); } } } } unset($hierarchy_control_add, $huf, $hierarchy_control_id); } } if (isset($this->is_new) and $this->is_new == TRUE) { $udlf = new UserDefaultListFactory(); $udlf->getByCompanyId($this->getCompany()); if ($udlf->getRecordCount() > 0) { Debug::Text('Using User Defaults', __FILE__, __LINE__, __METHOD__, 10); $udf_obj = $udlf->getCurrent(); Debug::text('Inserting Default Deductions...', __FILE__, __LINE__, __METHOD__, 10); $company_deduction_ids = $udf_obj->getCompanyDeduction(); if (is_array($company_deduction_ids) and count($company_deduction_ids) > 0) { foreach ($company_deduction_ids as $company_deduction_id) { $udf = new UserDeductionFactory(); $udf->setUser($this->getId()); $udf->setCompanyDeduction($company_deduction_id); if ($udf->isValid()) { $udf->Save(); } } } unset($company_deduction_ids, $company_deduction_id, $udf); Debug::text('Inserting Default Prefs...', __FILE__, __LINE__, __METHOD__, 10); $upf = new UserPreferenceFactory(); $upf->setUser($this->getId()); $upf->setLanguage($udf_obj->getLanguage()); $upf->setDateFormat($udf_obj->getDateFormat()); $upf->setTimeFormat($udf_obj->getTimeFormat()); $upf->setTimeUnitFormat($udf_obj->getTimeUnitFormat()); $upf->setTimeZone($udf_obj->getTimeZone()); $upf->setItemsPerPage($udf_obj->getItemsPerPage()); $upf->setStartWeekDay($udf_obj->getStartWeekDay()); $upf->setEnableEmailNotificationException($udf_obj->getEnableEmailNotificationException()); $upf->setEnableEmailNotificationMessage($udf_obj->getEnableEmailNotificationMessage()); $upf->setEnableEmailNotificationHome($udf_obj->getEnableEmailNotificationHome()); if ($upf->isValid()) { $upf->Save(); } } } if ($this->getDeleted() == TRUE) { //Remove them from the authorization hierarchy, policy group, and pay period schedule. //Delete any accruals for them as well. //Pay Period Schedule $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getByUserId($this->getId()); if ($ppslf->getRecordCount() > 0) { $pps_obj = $ppslf->getCurrent(); //Remove user from current schedule. $ppsulf = new PayPeriodScheduleUserListFactory(); $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($ppsulf->getRecordCount() > 0) { foreach ($ppsulf as $ppsu_obj) { Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10); $ppsu_obj->Delete(); } } } //Policy Group $pglf = new PolicyGroupListFactory(); $pglf->getByUserIds($this->getId()); if ($pglf->getRecordCount() > 0) { $pg_obj = $pglf->getCurrent(); $pgulf = new PolicyGroupUserListFactory(); $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($pgulf->getRecordCount() > 0) { foreach ($pgulf as $pgu_obj) { Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10); $pgu_obj->Delete(); } } } //Hierarchy $hclf = new HierarchyControlListFactory(); $hclf->getByCompanyId($this->getCompany()); if ($hclf->getRecordCount() > 0) { foreach ($hclf as $hc_obj) { $hf = new HierarchyListFactory(); $hf->setUser($this->getID()); $hf->setHierarchyControl($hc_obj->getId()); $hf->Delete(); } $hf->removeCache(NULL, $hf->getTable(TRUE)); //On delete we have to delete the entire group. unset($hf); } //Accrual balances $alf = new AccrualListFactory(); $alf->getByUserIdAndCompanyId($this->getId(), $this->getCompany()); if ($alf->getRecordCount() > 0) { foreach ($alf as $a_obj) { $a_obj->setDeleted(TRUE); if ($a_obj->isValid()) { $a_obj->Save(); } } } } return TRUE; }