コード例 #1
0
 /**
  * update employee
  * 
  * @param Zend_Console_Getopt $opts
  * @param HumanResources_Model_Employee $employee
  * @param HumanResources_Model_Employee $currentEmployee
  * @return HumanResources_Model_Employee
  */
 protected function _updateImportedEmployee($opts, $employee, $currentEmployee)
 {
     if ($opts->v) {
         echo "Updating employee " . $employee->n_fn . ".\n";
     }
     // update only some fields
     $fieldsToUpdate = array('postalcode', 'locality', 'street', 'bday', 'employment_begin', 'employment_end', 'bank_account_number', 'bank_name', 'bank_code_number', 'health_insurance', 'number', 'contracts');
     $changed = FALSE;
     foreach ($fieldsToUpdate as $field) {
         if (!empty($employee->{$field}) && $currentEmployee->{$field} !== $employee->{$field}) {
             if ($field === 'contracts' && !empty($currentEmployee->{$field})) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($currentEmployee->toArray(), TRUE));
                 }
             } else {
                 $currentEmployee->{$field} = $employee->{$field};
             }
             $changed = TRUE;
         }
     }
     if ($opts->d || !$changed) {
         $result = $currentEmployee;
     } else {
         $json = new HumanResources_Frontend_Json();
         $result = $json->saveEmployee($currentEmployee->toArray());
         if ($currentEmployee->contracts) {
             $rs = new Tinebase_Record_RecordSet('HumanResources_Model_Contract');
             foreach ($currentEmployee->contracts as $contract) {
                 $rs->addRecord(new HumanResources_Model_Contract($contract));
             }
             $currentEmployee->contracts = $rs;
         }
         if ($currentEmployee->costcenters) {
             $ccrs = new Tinebase_Record_RecordSet('HumanResources_Model_CostCenter');
             foreach ($currentEmployee->costcenters as $costcenter) {
                 $ccrs->addRecord(new HumanResources_Model_CostCenter($costcenter));
             }
             $currentEmployee->costcenters = $ccrs;
         }
         $result = HumanResources_Controller_Employee::getInstance()->update($currentEmployee);
     }
     return $result;
 }