function up() { if ($this->db->table_exists('training_attendees')) { $q = $this->db->get('training_attendees'); if ($q->num_rows() > 0) { foreach ($q->result_array() as $row) { $e = new Employee_m(); $e->get_by_id($row['employee_id']); if (!$e->exists()) { $this->db->where('id', $row['id']); $this->db->delete('training_attendees'); //echo $this->db->last_query().'<br>'; } } } $this->db->where('event_id', 0); $this->db->delete('training_attendees'); } }
function delete_office($office_id = '') { // Lets check if the office have associated employee $e = new Employee_m(); $e->where('office_id', $office_id); $e->get(); // If exists if ($e->exists()) { Session::flash('error_msg', 'Unable to delete office. Please delete all employee associated with the office.'); return Redirect::to('office_manage/view_offices', 'refresh'); } $this->Office->delete_office($office_id); // Delete the associated division $d = new Division(); $d->where('office_id', $office_id)->get(); $d->delete_all(); Session::flash('msg', 'Office deleted!'); return Redirect::to('office_manage/view_offices', 'refresh'); }