function save(&$person_data, &$employee_data, &$grants_data, $employee_id = false) { $success = false; //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); if (parent::save($person_data, $employee_id)) { if (!$employee_id or !$this->exists($employee_id)) { $employee_data['person_id'] = $employee_id = $person_data['person_id']; $success = $this->db->insert('employees', $employee_data); } else { $this->db->where('person_id', $employee_id); $success = $this->db->update('employees', $employee_data); } //We have either inserted or updated a new employee, now lets set permissions. if ($success) { //First lets clear out any grants the employee currently has. $success = $this->db->delete('grants', array('person_id' => $employee_id)); //Now insert the new grants if ($success) { foreach ($grants_data as $permission_id) { $success = $this->db->insert('grants', array('permission_id' => $permission_id, 'person_id' => $employee_id)); } } } } $this->db->trans_complete(); return $success; }
function save(&$person_data, &$supplier_data, $supplier_id = false) { $success = false; //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); if (parent::save($person_data, $supplier_id)) { if (!$supplier_id or !$this->exists($supplier_id)) { $supplier_data['person_id'] = $person_data['person_id']; $success = $this->db->insert('suppliers', $supplier_data); } else { $this->db->where('person_id', $supplier_id); $success = $this->db->update('suppliers', $supplier_data); } } $this->db->trans_complete(); return $success; }