You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.6 KiB

7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. require APPPATH . '/libraries/REST_Controller.php';
  4. /**************************************************************
  5. * Board API
  6. *************************************************************/
  7. class Board extends REST_Controller
  8. {
  9. function __construct()
  10. {
  11. parent::__construct();
  12. if (!$this->input->is_ajax_request()) $this->response(array("result" => FALSE, "message" => langs('공통/msg/invalid_access')), 400);
  13. }
  14. function info_get()
  15. {
  16. $brd_key = $this->get('brd_key', TRUE);
  17. $is_raw = $this->get('is_raw', TRUE) == TRUE ? TRUE : FALSE;
  18. if (empty($brd_key)) $this->error_return("FAQ 고유키값이 없습니다.", 400);
  19. $this->load->model('board_model');
  20. $board = $this->board_model->get_board($brd_key, $is_raw);
  21. $this->response($board, 200);
  22. }
  23. function category_delete()
  24. {
  25. $bca_idx = $this->delete('bca_idx', TRUE);
  26. if( empty($bca_idx) ) $this->error_return("FAQ 고유키값이 없습니다.", 400);
  27. $this->db->where('bca_idx', $bca_idx);
  28. $result = $this->db->delete('board_category');
  29. $this->response(array('result'=>$result), 200);
  30. }
  31. /**
  32. * 카테고리 순서 정렬
  33. */
  34. function category_sort_post()
  35. {
  36. $this->load->model('board_model');
  37. $brd_key = $this->post('brd_key', TRUE);
  38. $idxs = $this->post('idxs', TRUE);
  39. $update_array = array();
  40. foreach($idxs as $i=>$idx)
  41. {
  42. $update_array[] = array(
  43. 'bca_idx' => $idx,
  44. 'bca_sort' => $i+1
  45. );
  46. }
  47. $this->db->update_batch("board_category", $update_array, "bca_idx");
  48. $this->board_model->delete_cache($brd_key);
  49. }
  50. function category_count_get()
  51. {
  52. $bca_idx = $this->get('bca_idx', TRUE);
  53. if( empty($bca_idx) ) $this->error_return("카테고리 지정이 잘못되었습니다.", 400);
  54. $count = (int) $this->db->select('COUNT(*) AS count')->where('bca_parent', $bca_idx)->get('board_category')->row(0)->count;
  55. $this->response(array("result"=>$count), 200);
  56. }
  57. function category_post_count_get()
  58. {
  59. $bca_idx = $this->get('bca_idx', TRUE);
  60. if( empty($bca_idx) ) $this->error_return("카테고리 지정이 잘못되었습니다.", 400);
  61. $count = (int) $this->db->select('COUNT(*) AS count')->where('bca_idx', $bca_idx)->where_in('post_status',array('Y','B'))->get('board_post')->row(0)->count;
  62. $this->response(array("result"=>$count), 200);
  63. }
  64. /**
  65. * 게시물 삭제
  66. */
  67. function posts_delete()
  68. {
  69. $idxs = $this->delete('post_idx', TRUE);
  70. if(count($idxs) <= 0)
  71. $this->response(array('status'=>FALSE, 'message'=>'삭제할 게시물을 선택해주세요'), 400);
  72. $this->db->where_in('post_idx', $idxs);
  73. $this->db->set('post_status', 'N');
  74. $this->db->update('board_post');
  75. }
  76. /**
  77. * 게시물 승인
  78. */
  79. function assign_post()
  80. {
  81. $post_idx = $this->post('post_idx', TRUE);
  82. $post_assign = $this->post('post_assign', TRUE);
  83. if(empty($post_idx))
  84. $this->response(array('status'=>FALSE, 'message'=>'잘못된 접근입니다.'), 400);
  85. if(! in_array($post_assign, array('Y','N')))
  86. $this->response(array('status'=>FALSE, 'message'=>'잘못된 접근입니다.'), 400);
  87. $this->db->where('post_idx', $post_idx);
  88. $this->db->set('post_assign',$post_assign);
  89. $this->db->update('board_post');
  90. }
  91. }