EduCoursesAction.class.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. class EduCoursesAction extends CommonAction
  3. {
  4. public function index()
  5. {
  6. $map = array('is_delete' => 0);
  7. $title = strim($_REQUEST['title']);
  8. if (!empty($title)) {
  9. $map['title'] = array('like', '%' . $title . '%');
  10. }
  11. $this->assign("default_map", $map);
  12. $this->assign("category_list", M("EduCourseCategory")->findAll());
  13. parent::index();
  14. }
  15. public function add()
  16. {
  17. $user_id = intval($_REQUEST['user_id']);
  18. $authentication_type = M('User')->where(array('id' => $user_id))->getField('authentication_type');
  19. if ($authentication_type == '教师') {
  20. $teacher = M("EduTeacher")->where(array('user_id' => $user_id))->find();
  21. $image = $teacher['desc_image'];
  22. $this->assign("jumpUrl", u("EduTeacher/edit", array('id' => $teacher['id'])));
  23. } elseif ($authentication_type == '机构') {
  24. $org = M("EduOrg")->where(array('user_id' => $user_id))->find();
  25. $image = $org['desc_video_image'];
  26. $this->assign("jumpUrl", u("EduOrg/edit", array('id' => $org['id'])));
  27. }
  28. if (empty($image)) {
  29. $this->error("请先上传封面");
  30. }
  31. $this->assign("category_list", M("EduCourseCategory")->findAll());
  32. $this->assign("tags", M("EduTags")->where('type=2')->findAll());
  33. $this->assign("user_id", $user_id);
  34. $this->assign("image", $image);
  35. $this->display();
  36. }
  37. //设置推荐
  38. public function set_recommend()
  39. {
  40. $id = intval($_REQUEST['id']);
  41. $course = M(MODULE_NAME)->where("id=" . $id)->find(); //当前状态
  42. $user = M('User')->where("id=" . $course['user_id'])->find(); //当前状态
  43. if ($user['is_authentication'] != 2) {
  44. $this->ajaxReturn(0, "未通过认证,推荐失败", 0);
  45. } elseif ($course['courses_count'] <= 0) {
  46. $this->ajaxReturn(0, "请先添加课时,推荐失败", 0);
  47. } else {
  48. $n_is_effect = $course['is_recommend'] == 0 ? 1 : 0; //需设置的状态
  49. M(MODULE_NAME)->where("id=" . $id)->setField("is_recommend", $n_is_effect);
  50. save_log($course['title'] . l("SET_RECOMMEND_" . $n_is_effect), 1);
  51. load_auto_cache("edu_index_courses", array(
  52. "list_type" => 'recommend',
  53. "is_recommend" => '1',
  54. "limit" => '4'
  55. ), true);
  56. $this->ajaxReturn($n_is_effect, l("SET_RECOMMEND_" . $n_is_effect), 1);
  57. }
  58. }
  59. public function delete()
  60. {
  61. //删除指定记录
  62. $ajax = intval($_REQUEST['ajax']);
  63. $id = $_REQUEST ['id'];
  64. if (isset ($id)) {
  65. $info = M(MODULE_NAME)->where(array('id' => $id))->getField('title');
  66. $list = M(MODULE_NAME)->save(array('id' => $id, 'is_delete' => 1));
  67. if ($list !== false) {
  68. save_log($info . l("DELETE_SUCCESS"), 1);
  69. $this->success(l("DELETE_SUCCESS"), $ajax);
  70. } else {
  71. save_log($info . l("DELETE_FAILED"), 0);
  72. $this->error(l("DELETE_FAILED"), $ajax);
  73. }
  74. } else {
  75. $this->error(l("INVALID_OPERATION"), $ajax);
  76. }
  77. }
  78. public function edit()
  79. {
  80. $id = intval($_REQUEST ['id']);
  81. $vo = M(MODULE_NAME)->where(array('id' => $id))->find();
  82. $vo['tags'] = empty($vo['tags']) ? array() : explode(',', $vo['tags']);
  83. $tags = M("EduTags")->where('type=2')->findAll();
  84. foreach ($tags as &$tag) {
  85. if (in_array($tag['title'], $vo['tags'])) {
  86. $tag['is_checked'] = true;
  87. }
  88. }
  89. unset($tag);
  90. $this->assign('vo', $vo);
  91. $this->assign("tags", $tags);
  92. $this->assign("category_list", M("EduCourseCategory")->findAll());
  93. $this->display();
  94. }
  95. public function insert()
  96. {
  97. B('FilterString');
  98. $data = M(MODULE_NAME)->create();
  99. //开始验证有效性
  100. $this->assign("jumpUrl", u(MODULE_NAME . "/add", array('user_id' => $data['user_id'])));
  101. if (!check_empty($data['title'])) {
  102. $this->error("请输入标题");
  103. }
  104. if (!check_empty($data['image'])) {
  105. $this->error("请上传封面");
  106. }
  107. if (empty($data['tags'])) {
  108. $data['tags'] = array();
  109. }
  110. $data['tags'] = implode(',', array_slice($data['tags'], 0, 3));
  111. // 更新数据
  112. $log_info = $data['title'];
  113. $list = M(MODULE_NAME)->add($data);
  114. if (false !== $list) {
  115. //成功提示
  116. save_log($log_info . L("INSERT_SUCCESS"), 1);
  117. $this->success(L("INSERT_SUCCESS"));
  118. } else {
  119. //错误提示
  120. save_log($log_info . L("INSERT_FAILED"), 0);
  121. $this->error(L("INSERT_FAILED"));
  122. }
  123. }
  124. public function update()
  125. {
  126. B('FilterString');
  127. $data = M(MODULE_NAME)->create();
  128. $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("title");
  129. //开始验证有效性
  130. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  131. if (!check_empty($data['title'])) {
  132. $this->error("请输入标题");
  133. }
  134. if (!check_empty($data['image'])) {
  135. $this->error("请上传封面");
  136. }
  137. if (empty($data['tags'])) {
  138. $data['tags'] = array();
  139. }
  140. $data['tags'] = implode(',', array_slice($data['tags'], 0, 3));
  141. $list = M(MODULE_NAME)->save($data);
  142. if (false !== $list) {
  143. //成功提示
  144. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  145. $this->success(L("UPDATE_SUCCESS"));
  146. } else {
  147. //错误提示
  148. save_log($log_info . L("UPDATE_FAILED"), 0);
  149. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  150. }
  151. }
  152. }