model.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * The model file of company module 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 company
  9. * @version $Id: model.php 5086 2013-07-10 02:25:22Z wyd621@gmail.com $
  10. * @link https://www.zentao.net
  11. */
  12. ?>
  13. <?php
  14. class companyModel extends model
  15. {
  16. /**
  17. * 获取第一家公司。
  18. * Get the first company.
  19. *
  20. * @access public
  21. * @return object|bool
  22. */
  23. public function getFirst()
  24. {
  25. return $this->dao->select('*')->from(TABLE_COMPANY)->orderBy('id')->limit(1)->fetch();
  26. }
  27. /**
  28. * 根据id获取公司信息。
  29. * Get company info by id.
  30. *
  31. * @param int $companyID
  32. * @access public
  33. * @return object|bool
  34. */
  35. public function getByID($companyID)
  36. {
  37. return $this->dao->findById($companyID)->from(TABLE_COMPANY)->fetch();
  38. }
  39. /**
  40. * 获取用户。
  41. * Get users.
  42. *
  43. * @param string $browseType
  44. * @param string $type
  45. * @param string|int $queryID
  46. * @param int $deptID
  47. * @param string $sort
  48. * @param object $pager
  49. * @access public
  50. * @return array
  51. */
  52. public function getUsers($browseType = 'inside', $type = '', $queryID = 0, $deptID = 0, $sort = '', $pager = null)
  53. {
  54. if($type == 'bydept')
  55. {
  56. $childDeptIds = $this->loadModel('dept')->getAllChildID($deptID);
  57. return $this->dept->getUsers($browseType, $childDeptIds, $sort, $pager);
  58. }
  59. else
  60. {
  61. if($queryID)
  62. {
  63. $query = $this->loadModel('search')->getQuery($queryID);
  64. if($query)
  65. {
  66. $this->session->set('userQuery', $query->sql);
  67. $this->session->set('userForm', $query->form);
  68. }
  69. else
  70. {
  71. $this->session->set('userQuery', ' 1 = 1');
  72. }
  73. }
  74. return $this->loadModel('user')->getByQuery($browseType, $this->session->userQuery, $pager, $sort);
  75. }
  76. }
  77. /**
  78. * 获取外部公司。
  79. * Get outside companies.
  80. *
  81. * @access public
  82. * @return array
  83. */
  84. public function getOutsideCompanies()
  85. {
  86. return $this->dao->select('id, name')->from(TABLE_COMPANY)->where('id')->ne(1)->fetchPairs();
  87. }
  88. /**
  89. * 更新公司信息。
  90. * Update a company.
  91. *
  92. * @param int $companyID
  93. * @param object $compnay
  94. * @access public
  95. * @return bool
  96. * @param object $company
  97. */
  98. public function update($companyID, $company)
  99. {
  100. $this->dao->update(TABLE_COMPANY)
  101. ->data($company)
  102. ->autoCheck()
  103. ->batchCheck($this->config->company->edit->requiredFields, 'notempty')
  104. ->batchCheck('name', 'unique', "id != '$companyID'")
  105. ->where('id')->eq($companyID)
  106. ->exec();
  107. return !dao::isError();
  108. }
  109. /**
  110. * 搭建搜索表单。
  111. * Build search form.
  112. *
  113. * @param int $queryID
  114. * @param string $actionURL
  115. * @access public
  116. * @return void
  117. */
  118. public function buildSearchForm($queryID, $actionURL)
  119. {
  120. $this->config->company->browse->search['actionURL'] = $actionURL;
  121. $this->config->company->browse->search['queryID'] = $queryID;
  122. $this->config->company->browse->search['params']['dept']['values'] = $this->loadModel('dept')->getOptionMenu();
  123. $this->config->company->browse->search['params']['visions']['values'] = getVisions();
  124. $this->loadModel('search')->setSearchParams($this->config->company->browse->search);
  125. }
  126. }