function setUser($ids) { Debug::text('Setting User IDs : ', __FILE__, __LINE__, __METHOD__, 10); if (is_array($ids)) { if (!$this->isNew()) { //If needed, delete mappings first. $udlf = new UserDeductionListFactory(); $udlf->getByCompanyIdAndCompanyDeductionId($this->getCompany(), $this->getId()); $tmp_ids = array(); foreach ($udlf as $obj) { $id = $obj->getUser(); Debug::text('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. //$psealf = new PayStubEntryAccountListFactory(); $ulf = new UserListFactory(); foreach ($ids as $id) { if ($id != FALSE and isset($ids) and !in_array($id, $tmp_ids)) { $udf = new UserDeductionFactory(); $udf->setUser($id); $udf->setCompanyDeduction($this->getId()); $obj = $ulf->getById($id)->getCurrent(); if ($this->Validator->isTrue('user', $udf->Validator->isValid(), TTi18n::gettext('Employee is invalid') . ' (' . $obj->getFullName() . ')')) { $udf->save(); } } } return TRUE; } Debug::text('No IDs to set.', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }