/upload/src/aCloud/version/phpwind/customized/ACloudVerCustomizedForum.php

https://gitlab.com/wuhang2003/phpwind · PHP · 170 lines · 127 code · 15 blank · 28 comment · 21 complexity · da7c4d92ace5476bfdb3cf597667a603 MD5 · raw file

  1. <?php
  2. ! defined ( 'ACLOUD_PATH' ) && exit ( 'Forbidden' );
  3. define ( 'FORUM_INVALID_PARAMS', 401 );
  4. define ( 'FORUM_FAVOR_MAX', 402 );
  5. define ( 'FORUM_FAVOR_ALREADY', 403 );
  6. define ( 'FORUM_NOT_EXISTS', 404 );
  7. class ACloudVerCustomizedForum extends ACloudVerCustomizedBase {
  8. /**
  9. * 获取版块列表
  10. *
  11. * @return array
  12. */
  13. public function getAllForum() {
  14. $forumDs = $this->_getPwForum ();
  15. $forumResult = $forumDs->getForumList ( PwForum::FETCH_MAIN | PwForum::FETCH_STATISTICS );
  16. if ($forumResult instanceof PwError) return $this->buildResponse ( - 1, $forumResult->getError () );
  17. $forumDomain = $this->_getDomainDs()->getByType('forum');
  18. $key = Pw::collectByKey($forumDomain, 'id');
  19. $forumDomain = array_combine($key, $forumDomain);
  20. $cates = $forums = $subForums = $secondSubForums = array ();
  21. $count = 0;
  22. foreach ( $forumResult as $k => $v ) {
  23. $v['domain'] = '';
  24. if(isset($forumDomain[$k])) $v['domain'] = $forumDomain[$k]['domain'];
  25. if ($v ['type'] == 'category') {
  26. $cates [$v ['fid']] = array ('fid' => $v ['fid'], 'forumname' => strip_tags ( $v ['name'] ), 'type' => $v ['type'], 'todaypost' => '','domain' => $v['domain']);
  27. } elseif ($v ['type'] == 'forum') {
  28. Wind::import('SRV:forum.bo.PwForumBo');
  29. $pwforum = new PwForumBo($v['fid'], true);
  30. if ($pwforum->allowVisit(Wekit::getLoginUser()) !== true) continue;
  31. $forums [$v ['parentid']] [$v ['fid']] = array ('fid' => $v ['fid'], 'forumname' => strip_tags ( $v ['name'] ), 'type' => $v ['type'], 'todaypost' => $v ['todayposts'],'domain' => $v['domain']);
  32. } elseif ($v ['type'] == 'sub') {
  33. $subForums [$v ['parentid']] [$v ['fid']] = array ('fid' => $v ['fid'], 'forumname' => strip_tags ( $v ['name'] ), 'type' => $v ['type'], 'todaypost' => $v ['todayposts'],'domain' => $v['domain'] );
  34. } elseif ($v ['type'] == 'sub2') {
  35. $secondSubForums [$v ['parentid']] [$v ['fid']] = array ('fid' => $v ['fid'], 'forumname' => strip_tags ( $v ['name'] ), 'type' => $v ['type'], 'todaypost' => $v ['todayposts'],'domain' => $v['domain'] );
  36. }
  37. $count ++;
  38. }
  39. $result = array ();
  40. foreach ( $cates as $k => $v ) {
  41. $v ['child'] = isset ( $forums [$k] ) ? $this->_buildForums ( $forums [$k], $subForums, $secondSubForums ) : array ();
  42. $result [] = $v;
  43. }
  44. return $this->buildResponse ( 0, array ('count' => $count, 'forums' => $result ) );
  45. }
  46. /**
  47. * 根据版块id获取版块列表
  48. *
  49. * @param int $fid
  50. * @return array
  51. */
  52. public function getForumByFid($fid) {
  53. $fid = intval ( $fid );
  54. if ($fid < 1)
  55. return $this->buildResponse ( FORUM_INVALID_PARAMS,"参数错误" );
  56. $result = $this->_getPwForum ()->getForum ( $fid, PwForum::FETCH_MAIN | PwForum::FETCH_STATISTICS );
  57. if (result instanceof PwError) return $this->buildResponse ( - 1, $result->getError () );
  58. $domain = $this->_getDomainDs()->getByTypeAndId('forum', $fid);
  59. return $this->buildResponse ( 0, array ('forum' => array ('fid' => $result ['fid'], 'forumname' => $result ['name'], 'todaypost' => $result ['todayposts'] ),'todaythreads' => $result['todaythreads'],'domain' => $domain['domain']) );
  60. }
  61. /**
  62. * 根据版块id获取子版块
  63. *
  64. * @param int $fid
  65. * @return array
  66. */
  67. public function getChildForumByFid($fid) {
  68. $fid = intval ( $fid );
  69. if ($fid < 1)
  70. return $this->buildResponse ( FORUM_INVALID_PARAMS,"参数错误" );
  71. $forumService = $this->_getFroumService ();
  72. $map = $forumService->getForumMap ();
  73. $forumList = $forumService->getForumsByLevel ( $fid, $map );
  74. if ($forumList instanceof PwError) return $this->buildResponse ( - 1, $forumList->getError () );
  75. $forums = $subForums = $secondSubForums = array ();
  76. $count = 0;
  77. $fids = Pw::collectByKey($forumList, 'fid');
  78. $domains = $this->_getDomainDs()->fetchByTypeAndId('forum', $fids);
  79. foreach ( $forumList as $v ) {
  80. $v['domain'] = '';
  81. if(isset($domains[$v['fid']])) $v['domain'] = $domains[$v['fid']]['domain'];
  82. $statistics = $this->_getPwForum ()->getForum ( $v ['fid'], PwForum::FETCH_STATISTICS );
  83. if ($v ['type'] == 'forum') {
  84. //TODO 用户版块访问权限
  85. $forums [$v ['fid']] = array ('fid' => $v ['fid'], 'forumname' => strip_tags ( $v ['name'] ), 'type' => $v ['type'], 'todaypost' => $statistics ['todayposts'],'domain' => $v['domain']);
  86. } elseif ($v ['type'] == 'sub') {
  87. $subForums [$v ['parentid']] [$v ['fid']] = array ('fid' => $v ['fid'], 'forumname' => strip_tags ( $v ['name'] ), 'type' => $v ['type'], 'todaypost' => $statistics ['todayposts'],'domain' => $v['domain'] );
  88. } elseif ($v ['type'] == 'sub2') {
  89. $secondSubForums [$v ['parentid']] [$v ['fid']] = array ('fid' => $v ['fid'], 'forumname' => strip_tags ( $v ['name'] ), 'type' => $v ['type'], 'todaypost' => $statistics ['todayposts'],'domain' => $v['domain'] );
  90. }
  91. $count ++;
  92. }
  93. $result = array ();
  94. foreach ( $forums as $k => $v ) {
  95. $v ['child'] = isset ( $subForums [$k] ) ? $this->_fetchSubForum ( $subForums [$k], $secondSubForums ) : array ();
  96. $result [] = $v;
  97. }
  98. return $this->buildResponse ( 0, array ('count' => $count, 'forums' => $result ) );
  99. }
  100. /**
  101. *
  102. * 获取指定版块中的主题分类信息
  103. *
  104. * @param int $fid
  105. * @return array
  106. */
  107. public function getTopicType($fid){
  108. $topicTypes = $this->_getTopictypeDs()->getTopicTypesByFid($fid);
  109. $result = array();
  110. foreach ($topicTypes['all_types'] as $k => $v){
  111. $result[$k] = $v;
  112. $result[$k]['upid'] = $v['parentid'];
  113. }
  114. return $this->buildResponse ( 0, array('info' => $result));
  115. }
  116. private function _buildForums($forums, $subForums, $secondSubForums) {
  117. $result = array ();
  118. foreach ( $forums as $fid => $forum ) {
  119. $forum ['child'] = (isset ( $subForums [$fid] ) && $subForums [$fid]) ? $this->_buildSubForums ( $subForums [$fid], $secondSubForums ) : array ();
  120. $result [] = $forum;
  121. }
  122. return $result;
  123. }
  124. private function _buildSubForums($subForums, $secondSubForums) {
  125. $result = array ();
  126. foreach ( $subForums as $fid => $subForum ) {
  127. $subForum ['child'] = (isset ( $secondSubForums [$fid] ) && $secondSubForums [$fid]) ? $secondSubForums [$fid] : array ();
  128. $result [] = $subForum;
  129. }
  130. return $result;
  131. }
  132. private function _fetchSubForum($subForums, $secondSubForums) {
  133. $result = array ();
  134. foreach ( $subForums as $fid => $subForum ) {
  135. $subForum ['child'] = (isset ( $secondSubForums [$fid] ) && $secondSubForums [$fid]) ? $secondSubForums [$fid] : array ();
  136. $result [$fid] = $subForum;
  137. }
  138. return $result;
  139. }
  140. private function _getPwForum() {
  141. return Wekit::load ( 'SRV:forum.PwForum' );
  142. }
  143. private function _getFroumService() {
  144. return Wekit::load ( 'SRV:forum.srv.PwForumService' );
  145. }
  146. private function _getTopictypeDs() {
  147. return Wekit::load('forum.PwTopicType');
  148. }
  149. /**
  150. * @return PwDomain
  151. */
  152. private function _getDomainDs(){
  153. return Wekit::load('domain.PwDomain');
  154. }
  155. }