/** * Imports the 'Ccg' CSV file. * * @param array $data */ private function importCcg(array $data) { if (!($ccg = CommissioningBody::model()->findByAttributes(array('code' => $data['code'], 'commissioning_body_type_id' => $this->cbtId)))) { $ccg = new CommissioningBody(); $ccg->code = $data['code']; $ccg->commissioning_body_type_id = $this->cbtId; } $isNewRecord = $ccg->isNewRecord; $ccg->name = $data['name']; if ($ccg->saveOnlyIfDirty()->save()) { if ($this->audit !== 'false') { Audit::add('ProcessHscicDataCommand', ($isNewRecord ? 'Insert' : 'Update') . ' CCG'); } } else { // save has not been carried out, either mode was not dirty or save() failed } $contact = $ccg->contact; if (!($address = $contact->address)) { $address = new Address(); $address->contact_id = $contact->id; } $isNewRecord = $address->isNewRecord; $this->importAddress($address, array($data['addr1'], $data['addr2'], $data['addr3'], $data['addr4'], $data['addr5'])); $address->postcode = $data['postcode']; $address->country_id = $this->countryId; if ($address->saveOnlyIfDirty()->save()) { if ($this->audit !== 'false') { Audit::add('ProcessHscicDataCommand', ($isNewRecord ? 'Insert' : 'Update') . ' CCG-Address'); } } else { // save has not been carried out, either mode was not dirty or save() failed } }