model.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /**
  3. * The model file of entry 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 Gang Liu <liugang@cnezsoft.com>
  8. * @package entry
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. class entryModel extends model
  13. {
  14. /**
  15. * 通过ID获取应用。
  16. * Get an entry by id.
  17. *
  18. * @param int $entryID
  19. * @access public
  20. * @return object|false
  21. */
  22. public function getById($entryID)
  23. {
  24. return $this->dao->select('*')->from(TABLE_ENTRY)->where('id')->eq($entryID)->fetch();
  25. }
  26. /**
  27. * 通过代号获取应用。
  28. * Get an entry by code.
  29. *
  30. * @param string $code
  31. * @access public
  32. * @return object|false
  33. */
  34. public function getByCode($code)
  35. {
  36. return $this->dao->select('*')->from(TABLE_ENTRY)->where('deleted')->eq('0')->andWhere('code')->eq($code)->fetch();
  37. }
  38. /**
  39. * 通过密钥获取应用。
  40. * Get an entry by key.
  41. *
  42. * @param string $key
  43. * @access public
  44. * @return object|false
  45. */
  46. public function getByKey($key)
  47. {
  48. return $this->dao->select('*')->from(TABLE_ENTRY)->where('deleted')->eq('0')->andWhere('`key`')->eq($key)->fetch();
  49. }
  50. /**
  51. * 获取应用列表。
  52. * Get entry list.
  53. *
  54. * @param string $orderBy
  55. * @param object $pager
  56. * @access public
  57. * @return array
  58. */
  59. public function getList($orderBy = 'id_desc', $pager = null)
  60. {
  61. if(strpos($orderBy, 'desc_') !== false) $orderBy = str_replace('desc_', '`desc`_', $orderBy);
  62. return $this->dao->select('*')->from(TABLE_ENTRY)->where('deleted')->eq('0')->orderBy($orderBy)->page($pager)->fetchAll('id');
  63. }
  64. /**
  65. * 获取应用的日志列表。
  66. * Get log list of an entry .
  67. *
  68. * @param int $id
  69. * @param string $orderBy
  70. * @param object $pager
  71. * @access public
  72. * @return array
  73. */
  74. public function getLogs($id, $orderBy = 'date_desc', $pager = null)
  75. {
  76. return $this->dao->select('*')->from(TABLE_LOG)
  77. ->where('objectType')->eq('entry')
  78. ->andWhere('objectID')->eq($id)
  79. ->orderBy($orderBy)
  80. ->page($pager)
  81. ->fetchAll('id');
  82. }
  83. /**
  84. * 创建一个应用。
  85. * Create an entry.
  86. *
  87. * @param object $entry
  88. * @access public
  89. * @return false|int
  90. */
  91. public function create($entry)
  92. {
  93. if($entry->freePasswd == 1) $this->config->entry->create->requiredFields = 'name, code, key';
  94. $this->dao->insert(TABLE_ENTRY)->data($entry)
  95. ->batchCheck($this->config->entry->create->requiredFields, 'notempty')
  96. ->check('code', 'code')
  97. ->check('code', 'unique')
  98. ->autoCheck()
  99. ->exec();
  100. if(dao::isError()) return false;
  101. return $this->dao->lastInsertId();
  102. }
  103. /**
  104. * 更新一个应用。
  105. * Update an entry.
  106. *
  107. * @param int $entryID
  108. * @param object $entry
  109. * @access public
  110. * @return false|array
  111. */
  112. public function update($entryID, $entry)
  113. {
  114. $oldEntry = $this->getById($entryID);
  115. if($entry->freePasswd == 1) $this->config->entry->edit->requiredFields = 'name, code, key';
  116. $this->dao->update(TABLE_ENTRY)->data($entry)
  117. ->batchCheck($this->config->entry->edit->requiredFields, 'notempty')
  118. ->check('code', 'code')
  119. ->check('code', 'unique', "id!=$entryID")
  120. ->autoCheck()
  121. ->where('id')->eq($entryID)
  122. ->exec();
  123. if(dao::isError()) return false;
  124. return common::createChanges($oldEntry, $entry);
  125. }
  126. /**
  127. * 更新调用时间。
  128. * Update called time.
  129. *
  130. * @param string $code
  131. * @param int $time
  132. * @access public
  133. * @return bool
  134. */
  135. public function updateCalledTime($code, $time)
  136. {
  137. $this->dao->update(TABLE_ENTRY)->set('calledTime')->eq($time)->where('code')->eq($code)->exec();
  138. return !dao::isError();
  139. }
  140. /**
  141. * 保存日志。
  142. * Save log of an entry.
  143. *
  144. * @params int $entryID
  145. * @params string $url
  146. * @access public
  147. * @return bool
  148. * @param int $entryID
  149. * @param string $url
  150. */
  151. public function saveLog($entryID, $url)
  152. {
  153. $log = new stdclass();
  154. $log->objectType = 'entry';
  155. $log->objectID = $entryID;
  156. $log->url = $url;
  157. $log->date = helper::now();
  158. $this->dao->insert(TABLE_LOG)->data($log)->exec();
  159. return !dao::isError();
  160. }
  161. /**
  162. * 判断操作是否可以点击。
  163. * Judge an action is clickable or not.
  164. *
  165. * @param object $report
  166. * @param string $action
  167. * @access public
  168. * @return bool
  169. * @param object $entry
  170. */
  171. public function isClickable($entry, $action)
  172. {
  173. return true;
  174. }
  175. }