function getCompanyDeductionObject()
 {
     if (is_object($this->company_deduction_obj)) {
         return $this->company_deduction_obj;
     } else {
         $cdlf = new CompanyDeductionListFactory();
         $this->company_deduction_obj = $cdlf->getById($this->getCompanyDeduction())->getCurrent();
         return $this->company_deduction_obj;
     }
 }
 function setCompanyDeduction($ids)
 {
     Debug::text('Setting Company Deduction IDs : ', __FILE__, __LINE__, __METHOD__, 10);
     if (is_array($ids)) {
         if (!$this->isNew()) {
             //If needed, delete mappings first.
             $udcdlf = new UserDefaultCompanyDeductionListFactory();
             $udcdlf->getByUserDefaultId($this->getId());
             $tmp_ids = array();
             foreach ($udcdlf as $obj) {
                 $id = $obj->getCompanyDeduction();
                 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);
         } else {
             $tmp_ids = array();
         }
         //Insert new mappings.
         //$lf = new UserListFactory();
         $cdlf = new CompanyDeductionListFactory();
         foreach ($ids as $id) {
             if ($id != FALSE and isset($ids) and !in_array($id, $tmp_ids)) {
                 $udcdf = new UserDefaultCompanyDeductionFactory();
                 $udcdf->setUserDefault($this->getId());
                 $udcdf->setCompanyDeduction($id);
                 $obj = $cdlf->getById($id)->getCurrent();
                 if ($this->Validator->isTrue('company_deduction', $udcdf->Validator->isValid(), TTi18n::gettext('Deduction is invalid') . ' (' . $obj->getName() . ')')) {
                     $udcdf->save();
                 }
             }
         }
         return TRUE;
     }
     Debug::text('No IDs to set.', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }