EduCourseCategoryAction.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. class EduCourseCategoryAction extends CommonAction
  3. {
  4. public function index()
  5. {
  6. $map = array();
  7. $title = strim($_REQUEST['title']);
  8. if (!empty($title)) {
  9. $map['title'] = array('like', '%' . $title . '%');
  10. }
  11. $this->assign("default_map", $map);
  12. parent::index();
  13. }
  14. //设置推荐
  15. public function set_recommend()
  16. {
  17. $id = intval($_REQUEST['id']);
  18. $category = M(MODULE_NAME)->where("id=" . $id)->find(); //当前状态
  19. $n_is_effect = $category['is_recommend'] == 0 ? 1 : 0; //需设置的状态
  20. M(MODULE_NAME)->where("id=" . $id)->setField("is_recommend", $n_is_effect);
  21. load_auto_cache("edu_course_category", array('act' => 'index', 'is_recommend' => 1), true);
  22. save_log($category['title'] . l("SET_RECOMMEND_" . $n_is_effect), 1);
  23. $this->ajaxReturn($n_is_effect, l("SET_BAN_" . $n_is_effect), 1);
  24. }
  25. public function set_sort()
  26. {
  27. $id = intval($_REQUEST['id']);
  28. $sort = intval($_REQUEST['sort']);
  29. $category = M(MODULE_NAME)->where("id=" . $id)->find();
  30. if (!check_sort($sort)) {
  31. $this->error(l("SORT_FAILED"), 1);
  32. }
  33. M(MODULE_NAME)->where("id=" . $id)->setField("sort", $sort);
  34. save_log($category['title'] . l("SORT_SUCCESS"), 1);
  35. $this->success(l("SORT_SUCCESS"), 1);
  36. }
  37. public function insert()
  38. {
  39. B('FilterString');
  40. $data = M(MODULE_NAME)->create();
  41. //开始验证有效性
  42. $this->assign("jumpUrl", u(MODULE_NAME . "/index"));
  43. if (!check_empty($data['title'])) {
  44. $this->error("请输入标题");
  45. }
  46. if (!check_empty($data['image'])) {
  47. $this->error("请上传图片");
  48. }
  49. // 更新数据
  50. $log_info = $data['title'];
  51. $list = M(MODULE_NAME)->add($data);
  52. if (false !== $list) {
  53. //成功提示
  54. save_log($log_info . L("INSERT_SUCCESS"), 1);
  55. $this->success(L("INSERT_SUCCESS"));
  56. } else {
  57. //错误提示
  58. save_log($log_info . L("INSERT_FAILED"), 0);
  59. $this->error(L("INSERT_FAILED"));
  60. }
  61. }
  62. public function delete()
  63. {
  64. //删除指定记录
  65. $ajax = intval($_REQUEST['ajax']);
  66. $id = $_REQUEST ['id'];
  67. if (isset ($id)) {
  68. $condition = array('id' => array('in', explode(',', $id)));
  69. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  70. foreach ($rel_data as $data) {
  71. $info[] = $data['title'];
  72. }
  73. if ($info) {
  74. $info = implode(",", $info);
  75. }
  76. $list = M(MODULE_NAME)->where($condition)->delete();
  77. if ($list !== false) {
  78. save_log($info . l("DELETE_SUCCESS"), 1);
  79. $this->success(l("DELETE_SUCCESS"), $ajax);
  80. } else {
  81. save_log($info . l("DELETE_FAILED"), 0);
  82. $this->error(l("DELETE_FAILED"), $ajax);
  83. }
  84. } else {
  85. $this->error(l("INVALID_OPERATION"), $ajax);
  86. }
  87. }
  88. public function edit()
  89. {
  90. $id = intval($_REQUEST ['id']);
  91. $vo = M(MODULE_NAME)->where(array('id' => $id))->find();
  92. $this->assign('vo', $vo);
  93. $this->display();
  94. }
  95. public function update()
  96. {
  97. B('FilterString');
  98. $data = M(MODULE_NAME)->create();
  99. $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("title");
  100. //开始验证有效性
  101. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  102. if (!check_empty($data['title'])) {
  103. $this->error("请输入标题");
  104. }
  105. if (!check_empty($data['image'])) {
  106. $this->error("请上传图片");
  107. }
  108. $list = M(MODULE_NAME)->save($data);
  109. if (false !== $list) {
  110. //成功提示
  111. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  112. $this->success(L("UPDATE_SUCCESS"));
  113. } else {
  114. //错误提示
  115. save_log($log_info . L("UPDATE_FAILED"), 0);
  116. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  117. }
  118. }
  119. }