Stat.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?php
  2. namespace Widget;
  3. if (!defined('__TYPECHO_ROOT_DIR__')) {
  4. exit;
  5. }
  6. /**
  7. * 全局统计组件
  8. *
  9. * @property-read int $publishedPostsNum
  10. * @property-read int $waitingPostsNum
  11. * @property-read int $draftPostsNum
  12. * @property-read int $myPublishedPostsNum
  13. * @property-read int $myWaitingPostsNum
  14. * @property-read int $myDraftPostsNum
  15. * @property-read int $currentPublishedPostsNum
  16. * @property-read int $currentWaitingPostsNum
  17. * @property-read int $currentDraftPostsNum
  18. * @property-read int $publishedPagesNum
  19. * @property-read int $draftPagesNum
  20. * @property-read int $publishedCommentsNum
  21. * @property-read int $waitingCommentsNum
  22. * @property-read int $spamCommentsNum
  23. * @property-read int $myPublishedCommentsNum
  24. * @property-read int $myWaitingCommentsNum
  25. * @property-read int $mySpamCommentsNum
  26. * @property-read int $currentCommentsNum
  27. * @property-read int $currentPublishedCommentsNum
  28. * @property-read int $currentWaitingCommentsNum
  29. * @property-read int $currentSpamCommentsNum
  30. * @property-read int $categoriesNum
  31. * @property-read int $tagsNum
  32. */
  33. class Stat extends Base
  34. {
  35. /**
  36. * @param int $components
  37. */
  38. protected function initComponents(int &$components)
  39. {
  40. $components = self::INIT_USER;
  41. }
  42. /**
  43. * 获取已发布的文章数目
  44. *
  45. * @return integer
  46. */
  47. protected function ___publishedPostsNum(): int
  48. {
  49. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  50. ->from('table.contents')
  51. ->where('table.contents.type = ?', 'post')
  52. ->where('table.contents.status = ?', 'publish'))->num;
  53. }
  54. /**
  55. * 获取待审核的文章数目
  56. *
  57. * @return integer
  58. */
  59. protected function ___waitingPostsNum(): int
  60. {
  61. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  62. ->from('table.contents')
  63. ->where('table.contents.type = ? OR table.contents.type = ?', 'post', 'post_draft')
  64. ->where('table.contents.status = ?', 'waiting'))->num;
  65. }
  66. /**
  67. * 获取草稿文章数目
  68. *
  69. * @return integer
  70. */
  71. protected function ___draftPostsNum(): int
  72. {
  73. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  74. ->from('table.contents')
  75. ->where('table.contents.type = ?', 'post_draft'))->num;
  76. }
  77. /**
  78. * 获取当前用户已发布的文章数目
  79. *
  80. * @return integer
  81. */
  82. protected function ___myPublishedPostsNum(): int
  83. {
  84. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  85. ->from('table.contents')
  86. ->where('table.contents.type = ?', 'post')
  87. ->where('table.contents.status = ?', 'publish')
  88. ->where('table.contents.authorId = ?', $this->user->uid))->num;
  89. }
  90. /**
  91. * 获取当前用户待审核文章数目
  92. *
  93. * @return integer
  94. */
  95. protected function ___myWaitingPostsNum(): int
  96. {
  97. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  98. ->from('table.contents')
  99. ->where('table.contents.type = ? OR table.contents.type = ?', 'post', 'post_draft')
  100. ->where('table.contents.status = ?', 'waiting')
  101. ->where('table.contents.authorId = ?', $this->user->uid))->num;
  102. }
  103. /**
  104. * 获取当前用户草稿文章数目
  105. *
  106. * @return integer
  107. */
  108. protected function ___myDraftPostsNum(): int
  109. {
  110. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  111. ->from('table.contents')
  112. ->where('table.contents.type = ?', 'post_draft')
  113. ->where('table.contents.authorId = ?', $this->user->uid))->num;
  114. }
  115. /**
  116. * 获取当前用户已发布的文章数目
  117. *
  118. * @return integer
  119. */
  120. protected function ___currentPublishedPostsNum(): int
  121. {
  122. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  123. ->from('table.contents')
  124. ->where('table.contents.type = ?', 'post')
  125. ->where('table.contents.status = ?', 'publish')
  126. ->where('table.contents.authorId = ?', $this->request->filter('int')->uid))->num;
  127. }
  128. /**
  129. * 获取当前用户待审核文章数目
  130. *
  131. * @return integer
  132. */
  133. protected function ___currentWaitingPostsNum(): int
  134. {
  135. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  136. ->from('table.contents')
  137. ->where('table.contents.type = ? OR table.contents.type = ?', 'post', 'post_draft')
  138. ->where('table.contents.status = ?', 'waiting')
  139. ->where('table.contents.authorId = ?', $this->request->filter('int')->uid))->num;
  140. }
  141. /**
  142. * 获取当前用户草稿文章数目
  143. *
  144. * @return integer
  145. */
  146. protected function ___currentDraftPostsNum(): int
  147. {
  148. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  149. ->from('table.contents')
  150. ->where('table.contents.type = ?', 'post_draft')
  151. ->where('table.contents.authorId = ?', $this->request->filter('int')->uid))->num;
  152. }
  153. /**
  154. * 获取已发布页面数目
  155. *
  156. * @return integer
  157. */
  158. protected function ___publishedPagesNum(): int
  159. {
  160. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  161. ->from('table.contents')
  162. ->where('table.contents.type = ?', 'page')
  163. ->where('table.contents.status = ?', 'publish'))->num;
  164. }
  165. /**
  166. * 获取草稿页面数目
  167. *
  168. * @return integer
  169. */
  170. protected function ___draftPagesNum(): int
  171. {
  172. return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num'])
  173. ->from('table.contents')
  174. ->where('table.contents.type = ?', 'page_draft'))->num;
  175. }
  176. /**
  177. * 获取当前显示的评论数目
  178. *
  179. * @return integer
  180. */
  181. protected function ___publishedCommentsNum(): int
  182. {
  183. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  184. ->from('table.comments')
  185. ->where('table.comments.status = ?', 'approved'))->num;
  186. }
  187. /**
  188. * 获取当前待审核的评论数目
  189. *
  190. * @return integer
  191. */
  192. protected function ___waitingCommentsNum(): int
  193. {
  194. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  195. ->from('table.comments')
  196. ->where('table.comments.status = ?', 'waiting'))->num;
  197. }
  198. /**
  199. * 获取当前垃圾评论数目
  200. *
  201. * @return integer
  202. */
  203. protected function ___spamCommentsNum(): int
  204. {
  205. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  206. ->from('table.comments')
  207. ->where('table.comments.status = ?', 'spam'))->num;
  208. }
  209. /**
  210. * 获取当前用户显示的评论数目
  211. *
  212. * @return integer
  213. */
  214. protected function ___myPublishedCommentsNum(): int
  215. {
  216. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  217. ->from('table.comments')
  218. ->where('table.comments.status = ?', 'approved')
  219. ->where('table.comments.ownerId = ?', $this->user->uid))->num;
  220. }
  221. /**
  222. * 获取当前用户待审核的评论数目
  223. *
  224. * @return integer
  225. */
  226. protected function ___myWaitingCommentsNum(): int
  227. {
  228. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  229. ->from('table.comments')
  230. ->where('table.comments.status = ?', 'waiting')
  231. ->where('table.comments.ownerId = ?', $this->user->uid))->num;
  232. }
  233. /**
  234. * 获取当前用户垃圾评论数目
  235. *
  236. * @return integer
  237. */
  238. protected function ___mySpamCommentsNum(): int
  239. {
  240. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  241. ->from('table.comments')
  242. ->where('table.comments.status = ?', 'spam')
  243. ->where('table.comments.ownerId = ?', $this->user->uid))->num;
  244. }
  245. /**
  246. * 获取当前文章的评论数目
  247. *
  248. * @return integer
  249. */
  250. protected function ___currentCommentsNum(): int
  251. {
  252. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  253. ->from('table.comments')
  254. ->where('table.comments.cid = ?', $this->request->filter('int')->cid))->num;
  255. }
  256. /**
  257. * 获取当前文章显示的评论数目
  258. *
  259. * @return integer
  260. */
  261. protected function ___currentPublishedCommentsNum(): int
  262. {
  263. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  264. ->from('table.comments')
  265. ->where('table.comments.status = ?', 'approved')
  266. ->where('table.comments.cid = ?', $this->request->filter('int')->cid))->num;
  267. }
  268. /**
  269. * 获取当前文章待审核的评论数目
  270. *
  271. * @return integer
  272. */
  273. protected function ___currentWaitingCommentsNum(): int
  274. {
  275. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  276. ->from('table.comments')
  277. ->where('table.comments.status = ?', 'waiting')
  278. ->where('table.comments.cid = ?', $this->request->filter('int')->cid))->num;
  279. }
  280. /**
  281. * 获取当前文章垃圾评论数目
  282. *
  283. * @return integer
  284. */
  285. protected function ___currentSpamCommentsNum(): int
  286. {
  287. return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num'])
  288. ->from('table.comments')
  289. ->where('table.comments.status = ?', 'spam')
  290. ->where('table.comments.cid = ?', $this->request->filter('int')->cid))->num;
  291. }
  292. /**
  293. * 获取分类数目
  294. *
  295. * @return integer
  296. */
  297. protected function ___categoriesNum(): int
  298. {
  299. return $this->db->fetchObject($this->db->select(['COUNT(mid)' => 'num'])
  300. ->from('table.metas')
  301. ->where('table.metas.type = ?', 'category'))->num;
  302. }
  303. /**
  304. * 获取标签数目
  305. *
  306. * @return integer
  307. */
  308. protected function ___tagsNum(): int
  309. {
  310. return $this->db->fetchObject($this->db->select(['COUNT(mid)' => 'num'])
  311. ->from('table.metas')
  312. ->where('table.metas.type = ?', 'tag'))->num;
  313. }
  314. }