public function deleteAction($id) { //kiểm tra xem id này có phải là parent ko $parent = $this->findFirst(array("conditions" => "parents = :parents:", "bind" => array("parents" => $id), "columns" => "id")); if ($parent) { $this->flash->error("Thất bại! Kênh menu có mục con"); } else { $aricle = \Modules\Backend\Models\News_article::findFirst(array("conditions" => "category_id = :id:", "bind" => array("id" => $id), "columns" => "id")); if (!$aricle) { if ($this->delete($id)) { $this->flash->success("Thành công!"); } else { $this->flash->error("Thất bại!"); } } else { $this->flash->error("Thất bại! Kênh thông tin có bài viết"); } } $this->redirect(array("action" => "index")); }
/** * Hàm lấy menu item của từng menu * @param $menu_id */ protected function getMenuItem($menu_id) { $model = $this->getModel(); $result = $model::findByMenu_id($menu_id); $system = new \Modules\Library\System(); $result = $system->convert_object_to_array($result); $data = null; $system->recursive($result, 0, 1, $data); $this->view->data = $data; // Xử lý submit tùy chọn if ($this->request->isPost()) { // xóa nhiều if ($this->request->getPost("delete")) { $id = $this->request->getPost("checkbox"); if (count($id) > 0) { $id = implode(',', $id); $conditions = "id IN({$id})"; $model = $this->getModel(); $record = $model::find(array("conditions" => $conditions, "colums" => "id,title")); if (count($record) > 0) { $fail = ""; foreach ($record as $key => $value) { $parent = $this->findFirst(array("conditions" => "parents = :parents:", "bind" => array("parents" => $value->id), "columns" => "id,title")); if (!$parent) { $aricle = \Modules\Backend\Models\News_article::findFirst(array("conditions" => "category_id = :id:", "bind" => array("id" => $value->id), "columns" => "id")); if (!$aricle) { $value->delete(); } else { $fail .= $value->title . ","; } } else { $fail .= $value->title . ","; } } if (!empty($fail)) { $this->flash->error("Xóa thất bại: " . $fail); } $this->view->disable(); } } } // kích hoạt nhiều if ($this->request->getPost("active")) { $this->status_multiple(1); } // đóng kích hoạt nhiều if ($this->request->getPost("no_active")) { $this->status_multiple(0); } // sắp xếp nhiều if ($this->request->getPost("order")) { $this->update_multiple(array("position")); } $this->view->disable(); $this->redirect(array("action" => "index")); } //Plugin $plugin = new \Modules\Library\Plugin(); $this->view->plugin = $plugin; }