What would be a better/cleaner approach to this function which creates multiple records across different database tables in a codeigniter controller :
private function newConcern($data) {
$this->load->model('customer_model', 'customer');
$this->load->model('complaints_dealers_model', 'dealer');
$this->load->model('vehicle_model', 'vehicle');
$this->load->model('complaints_vehicles_model', 'complaints_vehicles');
$this->load->model('complaints_emails_model', 'emails');
// create customer record
$this->customer->create($data['customer']);
// create concern record
$this->create($data['concern']);
// create dealer record
$this->dealer->create($data['dealer']);
// create vehicle record
$this->vehicle->create($data['vehicle']);
// create complaint vehicle record
$this->complaints_vehicles->create($data['complaint_vehicle']);
// check whether we have any email recipients
if (!empty($data['department']) || !empty($data['recipients'])) {
// process branch email
$this->emails->processBranchEmail($data, $concern->id);
}
return true;
}
It feels like there's too much going on is this function, despite the necessity of all function calls.
Any suggestions for a better approach?