department.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * The department entry point of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package entries
  9. * @version 1
  10. * @link https://www.zentao.net
  11. */
  12. class departmentEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $departmentID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($departmentID)
  22. {
  23. $dept = $this->loadModel('dept')->getByID($departmentID);
  24. if(!$dept) return $this->send404();
  25. return $this->send(200, $dept);
  26. }
  27. /**
  28. * PUT method.
  29. *
  30. * @param int $departmentID
  31. * @access public
  32. * @return string
  33. */
  34. public function put($departmentID)
  35. {
  36. $control = $this->loadController('dept', 'edit');
  37. $oldDept = $this->loadModel('dept')->getByID($departmentID);
  38. /* Set $_POST variables. */
  39. $fields = 'parent,name,manager';
  40. $this->batchSetPost($fields, $oldDept);
  41. $this->requireFields('name');
  42. $control->edit($departmentID);
  43. $this->getData();
  44. $department = $this->dept->getByID($departmentID);
  45. return $this->send(200, $department);
  46. }
  47. /**
  48. * DELETE method.
  49. *
  50. * @param int $departmentID
  51. * @access public
  52. * @return string
  53. */
  54. public function delete($departmentID)
  55. {
  56. $control = $this->loadController('dept', 'delete');
  57. $control->delete($departmentID, 'true');
  58. $data = $this->getData();
  59. if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
  60. return $this->sendSuccess(200, 'success');
  61. }
  62. }