public function delete($dish_id) { $this->common->authenticate(); $message = $this->common->get_message('delete_dish', array('delete_success', 'delete_failure')); if (Dishes_model::delete_dishes(array($dish_id))) { $image_file_name = $this->input->post('image_file_name'); $this->common->image_delete(SAVE_IMAGE_OF_DISHES . '/' . $image_file_name); $data = array('status' => 'success', 'message' => $message['delete_success']); } else { $data = array('status' => 'failure', 'message' => $message['delete_failure']); } echo json_encode($data); }
/** * Delete category * * @param int $category_id * @return bool */ function delete_category($category_id) { $this->db->trans_begin(); $data = array('id' => $category_id); $this->db->delete('categories', $data); $query = $this->db->get_where('dishes', array('category_id' => $category_id)); $have_dish_belong_to_this_category = $query->num_rows(); if ($have_dish_belong_to_this_category > 0) { $dishes_id_belong_to_category = array(); // Get all dishes id belongs to category foreach ($query->result() as $dish) { $dishes_id_belong_to_category[] = $dish->id; } // Delete list of dishes belongs to category $this->load->model('dishes_model'); if (Dishes_model::delete_dishes($dishes_id_belong_to_category)) { $this->load->model('menus_model'); // Delete list of dishes in menus have this category Menus_model::delete_dishes_in_menu_by_field('dish_id', $dishes_id_belong_to_category); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return FALSE; } else { $this->db->cache_delete('admin', 'dishes'); $this->db->trans_commit(); return TRUE; } }