model.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * The model file of mark module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2024 禅道软件(青岛)有限公司(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 Xinzhi Qi <qixinzhi@chandao.com>
  8. * @package mail
  9. * @link https://www.zentao.net
  10. */
  11. ?>
  12. <?php
  13. class markModel extends model
  14. {
  15. /**
  16. * 获取需要标记的对象。
  17. * Get needed mark sobjects.
  18. *
  19. * @param array $objectIDs
  20. * @param string $objectType
  21. * @param string $version
  22. * @param string $mark
  23. * @access public
  24. * @return array
  25. */
  26. public function getNeededMarks($objectIDs, $objectType, $version, $mark)
  27. {
  28. return $this->dao->select('objectID, version')->from(TABLE_MARK)
  29. ->where('objectType')->eq($objectType)
  30. ->andWhere('objectID')->in($objectIDs)
  31. ->beginIF($version != 'all')->andWhere('version')->eq($version)->fi()
  32. ->andWhere('account')->eq($this->app->user->account)
  33. ->andWhere('mark')->eq($mark)
  34. ->fetchAll();
  35. }
  36. /**
  37. * @param mixed[] $objects
  38. * @param string $objectType
  39. * @param string $mark
  40. */
  41. public function getMarks($objects, $objectType, $mark)
  42. {
  43. $objectIDs = array_column($objects, 'id');
  44. $marks = $this->getNeededMarks($objectIDs, $objectType, 'all', $mark);
  45. foreach($objects as $object)
  46. {
  47. $objectMarks = array_filter($marks, function($mark) use($object)
  48. {
  49. return $mark->objectID == $object->id && $mark->version == $object->version;
  50. });
  51. $object->mark = !empty($objectMarks);
  52. }
  53. return $objects;
  54. }
  55. /**
  56. * @param string $objectType
  57. * @param int $objectID
  58. * @param string $version
  59. * @param string $mark
  60. */
  61. public function isMark($objectType, $objectID, $version, $mark = 'view')
  62. {
  63. return $this->dao->select('*')->from(TABLE_MARK)
  64. ->where('objectType')->eq($objectType)
  65. ->andWhere('objectID')->in($objectID)
  66. ->andWhere('version')->eq($version)
  67. ->andWhere('account')->eq($this->app->user->account)
  68. ->andWhere('mark')->eq($mark)
  69. ->fetchAll();
  70. }
  71. /**
  72. * Judge has mark.
  73. *
  74. * @param string $objectType
  75. * @param int $objectID
  76. * @param string $version
  77. * @param string $mark
  78. * @param bool $onlyMajor
  79. * @access public
  80. * @return bool
  81. */
  82. public function hasMark($objectType, $objectID, $version = 'all', $mark = 'view', $onlyMajor = false)
  83. {
  84. $mark = $this->dao->select('id')->from(TABLE_MARK)
  85. ->where('objectType')->eq($objectType)
  86. ->andWhere('objectID')->in($objectID)
  87. ->beginIF($version != 'all')->andWhere('version')->eq($version)->fi()
  88. ->beginIF($onlyMajor)->andWhere('version')->notlike('%.%')->fi()
  89. ->andWhere('account')->eq($this->app->user->account)
  90. ->andWhere('mark')->eq($mark)
  91. ->fetch();
  92. return !empty($mark);
  93. }
  94. /**
  95. * 设置对象的标记。
  96. * Set object marks.
  97. *
  98. * @param array $objectIDs
  99. * @param string $objectType
  100. * @param string $version
  101. * @param string $mark
  102. * @param string $extra
  103. * @access public
  104. * @return bool
  105. */
  106. public function setMark($objectIDs, $objectType, $version, $mark, $extra = '')
  107. {
  108. $data = new stdclass();
  109. $data->objectType = $objectType;
  110. $data->version = $version;
  111. $data->account = $this->app->user->account;
  112. $data->mark = $mark;
  113. $data->extra = $extra;
  114. $data->date = helper::now();
  115. foreach($objectIDs as $objectID)
  116. {
  117. $data->objectID = $objectID;
  118. $this->dao->insert(TABLE_MARK)->data($data)->autocheck()->exec();
  119. }
  120. return dao::isError();
  121. }
  122. }