function postSave() { $this->removeCache($this->getId()); if ($this->getDeleted() == FALSE) { Debug::text('Setting Tags...', __FILE__, __LINE__, __METHOD__, 10); CompanyGenericTagMapFactory::setTags($this->getKPIObject()->getCompany(), 330, $this->getID(), $this->getTag()); } return TRUE; }
function postSave($data_diff = NULL) { $this->removeCache($this->getId()); if ($this->getDeleted() == FALSE and $this->getPermissionControl() !== FALSE) { Debug::text('Permission Group is set...', __FILE__, __LINE__, __METHOD__, 10); $pclf = TTnew('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); $pulf = TTnew('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 = TTnew('PermissionUserFactory'); $puf->setPermissionControl($this->getPermissionControl()); $puf->setUser($this->getID()); if ($puf->isValid()) { $puf->Save(); //Clear permission class for this employee. $pf = TTnew('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: ' . $this->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10); $add_pay_period_schedule = FALSE; $ppslf = TTnew('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 = TTnew('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; } } elseif ($this->getPayPeriodSchedule() > 0) { 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 = TTnew('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 = TTnew('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 = TTnew('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('Deleting 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 = TTnew('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 = TTnew('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 = TTnew('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 = TTnew('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 (DEMO_MODE != TRUE and $this->getDeleted() == FALSE and $this->getPasswordUpdatedDate() >= time() - 10) { //If the password was updated in the last 10 seconds. Debug::text('Password changed, saving it for historical purposes... Password: '******'UserIdentificationFactory'); $uif->setUser($this->getID()); $uif->setType(5); //Password History $uif->setNumber(0); $uif->setValue($this->getPassword()); if ($uif->isValid()) { $uif->Save(); } unset($uif); } if ($this->getDeleted() == FALSE) { Debug::text('Setting Tags...', __FILE__, __LINE__, __METHOD__, 10); CompanyGenericTagMapFactory::setTags($this->getCompany(), 200, $this->getID(), $this->getTag()); if (is_array($data_diff) and (isset($data_diff['address1']) or isset($data_diff['address2']) or isset($data_diff['city']) or isset($data_diff['province']) or isset($data_diff['country']) or isset($data_diff['postal_code']))) { //Run a separate custom query to clear the geocordinates. Do we really want to do this for so many objects though... Debug::text('Address has changed, clear geocordinates!', __FILE__, __LINE__, __METHOD__, 10); $query = 'UPDATE ' . $this->getTable() . ' SET longitude = NULL, latitude = NULL where id = ?'; $this->db->Execute($query, array('id' => $this->getID())); } } if (isset($this->is_new) and $this->is_new == TRUE) { $udlf = TTnew('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 = TTnew('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 = TTnew('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($upf->getLocationTimeZone($this->getCountry(), $this->getProvince(), $this->getWorkPhone(), $this->getHomePhone(), $udf_obj->getTimeZone())); Debug::text('Time Zone: ' . $upf->getTimeZone(), __FILE__, __LINE__, __METHOD__, 9); $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, pay period schedule, stations, jobs, etc... //Delete any accruals for them as well. //Pay Period Schedule $ppslf = TTnew('PayPeriodScheduleListFactory'); $ppslf->getByUserId($this->getId()); if ($ppslf->getRecordCount() > 0) { $pps_obj = $ppslf->getCurrent(); //Remove user from current schedule. $ppsulf = TTnew('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('Deleting from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10); $ppsu_obj->Delete(); } } } //Policy Group $pglf = TTnew('PolicyGroupListFactory'); $pglf->getByUserIds($this->getId()); if ($pglf->getRecordCount() > 0) { $pg_obj = $pglf->getCurrent(); $pgulf = TTnew('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 = TTnew('HierarchyControlListFactory'); $hclf->getByCompanyId($this->getCompany()); if ($hclf->getRecordCount() > 0) { foreach ($hclf as $hc_obj) { $hf = TTnew('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 = TTnew('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(); } } } //Station employee critiera $siuf = TTnew('StationIncludeUserFactory'); $seuf = TTnew('StationExcludeUserFactory'); $query = 'delete from ' . $siuf->getTable() . ' where user_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'delete from ' . $seuf->getTable() . ' where user_id = ' . (int) $this->getId(); $this->db->Execute($query); //Job employee criteria $cgmlf = TTnew('CompanyGenericMapListFactory'); $cgmlf->getByCompanyIDAndObjectTypeAndMapID($this->getCompany(), array(1040, 1050), $this->getID()); if ($cgmlf->getRecordCount() > 0) { foreach ($cgmlf as $cgm_obj) { Debug::text('Deleteing from Company Generic Map: ' . $cgm_obj->getID(), __FILE__, __LINE__, __METHOD__, 10); $cgm_obj->Delete(); } } } return TRUE; }
function postSave() { $this->removeCache($this->getId()); if ($this->getDeleted() == FALSE) { CompanyGenericTagMapFactory::setTags($this->getCompany(), 120, $this->getID(), $this->getTag()); } if ($this->getDeleted() == TRUE) { Debug::Text('UnAssign Hours from Department: ' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10); //Unassign hours from this department. $pcf = TTnew('PunchControlFactory'); $udtf = TTnew('UserDateTotalFactory'); $uf = TTnew('UserFactory'); $sf = TTnew('StationFactory'); $sdf = TTnew('StationDepartmentFactory'); $sf_b = TTnew('ScheduleFactory'); $udf = TTnew('UserDefaultFactory'); $rstf = TTnew('RecurringScheduleTemplateFactory'); $query = 'update ' . $pcf->getTable() . ' set department_id = 0 where department_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $udtf->getTable() . ' set department_id = 0 where department_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $sf_b->getTable() . ' set department_id = 0 where department_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $uf->getTable() . ' set default_department_id = 0 where company_id = ' . (int) $this->getCompany() . ' AND default_department_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $udf->getTable() . ' set default_department_id = 0 where company_id = ' . (int) $this->getCompany() . ' AND default_department_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $sf->getTable() . ' set department_id = 0 where company_id = ' . (int) $this->getCompany() . ' AND department_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'delete from ' . $sdf->getTable() . ' where department_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $rstf->getTable() . ' set department_id = 0 where department_id = ' . (int) $this->getId(); $this->db->Execute($query); //Job employee criteria $cgmlf = TTnew('CompanyGenericMapListFactory'); $cgmlf->getByCompanyIDAndObjectTypeAndMapID($this->getCompany(), 1020, $this->getID()); if ($cgmlf->getRecordCount() > 0) { foreach ($cgmlf as $cgm_obj) { Debug::text('Deleteing from Company Generic Map: ' . $cgm_obj->getID(), __FILE__, __LINE__, __METHOD__, 10); $cgm_obj->Delete(); } } } return TRUE; }
function postSave() { $this->removeCache($this->getId()); if ($this->getDeleted() == FALSE) { Debug::text('Setting Tags...', __FILE__, __LINE__, __METHOD__, 10); CompanyGenericTagMapFactory::setTags($this->getCompany(), 250, $this->getID(), $this->getTag()); } if ($this->getDeleted() == TRUE) { Debug::Text('UnAssign Hours from Qualification: ' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10); //Unassign hours from this qualification. $sf = TTnew('UserSkillFactory'); $ef = TTnew('UserEducationFactory'); $lf = TTnew('UserLicenseFactory'); $lg = TTnew('UserLanguageFactory'); $mf = TTnew('UserMembershipFactory'); $query = 'update ' . $sf->getTable() . ' set qualification_id = 0 where qualification_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $ef->getTable() . ' set qualification_id = 0 where qualification_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $lf->getTable() . ' set qualification_id = 0 where qualification_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $lg->getTable() . ' set qualification_id = 0 where qualification_id = ' . (int) $this->getId(); $this->db->Execute($query); $query = 'update ' . $mf->getTable() . ' set qualification_id = 0 where qualification_id = ' . (int) $this->getId(); $this->db->Execute($query); //Job employee criteria } return TRUE; }