PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/src/service/space/bo/PwSpaceModel.php

https://gitlab.com/wuhang2003/phpwind
PHP | 134 lines | 107 code | 12 blank | 15 comment | 9 complexity | e0c82ee4005a224ad15015d1d969f460 MD5 | raw file
  1. <?php
  2. Wind::import('SRV:space.bo.PwSpaceBo');
  3. /**
  4. * the last known user to change this file in the repository <$LastChangedBy: jieyin $>
  5. * @author $Author: jieyin $ Foxsee@aliyun.com
  6. * @copyright ©2003-2103 phpwind.com
  7. * @license http://www.phpwind.com
  8. * @version $Id: PwSpaceModel.php 20893 2012-11-16 07:00:39Z jieyin $
  9. * @package
  10. */
  11. class PwSpaceModel extends PwSpaceBo {
  12. /**
  13. * 模块调用接口
  14. * Enter description here ...
  15. * @param string $mod visit|tovisit|tag|keys|fllow|fans
  16. * @param int $limit
  17. * @param int $page
  18. */
  19. public function model($mod, $limit = 10, $page = 0) {
  20. $limit = (int)$limit;
  21. $page = (int)$page;
  22. if ($page > 0 ) {
  23. $method = sprintf('model%sList', ucwords($mod));
  24. if (!method_exists($this, $method)) return array();
  25. return $this->$method($limit, $page);
  26. } else {
  27. $method = sprintf('model%s', ucwords($mod));
  28. if (!method_exists($this, $method)) return array();
  29. return $this->$method($limit);
  30. }
  31. }
  32. protected function modelVisit($limit) {
  33. $_users = array();
  34. $visitors = unserialize($this->space['visitors']);
  35. if (!$visitors) return array(0,array());
  36. $count = count($visitors);
  37. $visitors = is_array($visitors) ? array_slice($visitors, 0, $limit, true) : array();
  38. $uids = array_keys($visitors);
  39. $users = Wekit::load('user.PwUser')->fetchUserByUid($uids);
  40. foreach ($visitors AS $k=>$v) {
  41. $users[$k]['visitor_time'] = $v;
  42. $_users[$k] = $users[$k];
  43. }
  44. return array($count, $_users);
  45. }
  46. protected function modelTovisit($limit) {
  47. $_users = array();
  48. $tovisitors = unserialize($this->space['tovisitors']);
  49. if (!$tovisitors) return array(0,array());
  50. $count = count($tovisitors);
  51. $tovisitors = is_array($tovisitors) ? array_slice($tovisitors, 0, $limit, true) : array();
  52. $uids = array_keys($tovisitors);
  53. $users = Wekit::load('user.PwUser')->fetchUserByUid($uids);
  54. foreach ($tovisitors AS $k=>$v) {
  55. $users[$k]['visitor_time'] = $v;
  56. $_users[$k] = $users[$k];
  57. }
  58. return array($count, $_users);
  59. }
  60. protected function modelTag($limit) {
  61. $count = Wekit::load('tag.PwTagAttention')->countAttentionByUid($this->spaceUid);
  62. return array($count, Wekit::load('tag.PwTag')->getAttentionByUid($this->spaceUid, 0, $limit));
  63. }
  64. protected function modelUserTag($limit) {
  65. $tags = Wekit::load('usertag.srv.PwUserTagService')->getUserTagList($this->spaceUid);
  66. $count = count($tags);
  67. $tags = is_array($tags) ? array_slice($tags, 0, $limit, true) : array();
  68. return array($count, $tags);
  69. }
  70. protected function modelFollow($limit) {
  71. $count = $this->spaceUser['follows'];
  72. $follows = Wekit::load('attention.PwAttention')->getFollows($this->spaceUid, $limit, 0);
  73. $uids = array_keys($follows);
  74. return array($count, Wekit::load('user.PwUser')->fetchUserByUid($uids));
  75. }
  76. protected function modelFans($limit) {
  77. $count = $this->spaceUser['fans'];
  78. $fans = Wekit::load('attention.PwAttention')->getFans($this->spaceUid, $limit, 0);
  79. $uids = array_keys($fans);
  80. return array($count, Wekit::load('user.PwUser')->fetchUserByUid($uids));
  81. }
  82. protected function modelThreadList($limit, $page) {
  83. $ds = Wekit::load('forum.PwThread');
  84. $count =$ds->countThreadByUid($this->spaceUid);
  85. if ($count) {
  86. list($offset,$limit) = Pw::page2limit($page, $limit);
  87. $threads = $ds->getThreadByUid($this->spaceUid,$limit,$offset, 2);
  88. }
  89. return array($count, $threads);
  90. }
  91. protected function modelPostList($limit, $page) {
  92. $ds = Wekit::load('forum.PwThread');
  93. list($offset,$limit) = Pw::page2limit($page, $limit);
  94. $count = $ds->countPostByUid($this->spaceUid);
  95. if ($count) {
  96. $tmpPosts = $ds->getPostByUid($this->spaceUid, $limit, $offset);
  97. $posts = $tids = array();
  98. foreach ($tmpPosts as $v) {
  99. $tids[] = $v['tid'];
  100. }
  101. $threads = $this->_getThreadDs()->fetchThread($tids);
  102. foreach ($tmpPosts as $v) {
  103. $v['threadSubject'] = Pw::substrs($threads[$v['tid']]['subject'], 30);
  104. $v['content'] = Pw::substrs($v['content'], 30);
  105. $v['created_time'] = PW::time2str($v['created_time'],'auto');
  106. $posts[] = $v;
  107. }
  108. }
  109. return array($count, $posts);
  110. }
  111. protected function modelFreshList($limit, $page) {
  112. Wind::import('SRV:attention.srv.PwFreshDisplay');
  113. Wind::import('SRV:attention.srv.dataSource.PwFetchMyFresh');
  114. $count = Wekit::load('attention.PwFresh')->countFreshByUid($this->spaceUid);
  115. $totalpage = ceil($count / $limit);
  116. $page > $totalpage && $page = $totalpage;
  117. list($offset,$limit) = Pw::page2limit($page, $limit);
  118. $freshDisplay = new PwFreshDisplay(new PwFetchMyFresh($this->spaceUid, $limit, $offset));
  119. return array($count, $freshDisplay->gather());
  120. }
  121. }
  122. ?>