PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/src/service/design/srv/model/thread/PwDesignThreadDataService.php

https://gitlab.com/wuhang2003/phpwind
PHP | 231 lines | 155 code | 19 blank | 57 comment | 23 complexity | 2e6d59efcacbad2cebb33b9764054ebe MD5 | raw file
  1. <?php
  2. Wind::import('SRV:design.srv.model.PwDesignModelBase');
  3. /**
  4. * the last known user to change this file in the repository <$LastChangedBy: gao.wanggao $>
  5. * <note>
  6. * decorateAddProperty 为插入表单值修饰
  7. * decorateEditProperty 为修改表单值修饰
  8. * _getData 获取数据
  9. * </note>
  10. * @author $Author: gao.wanggao $ Foxsee@aliyun.com
  11. * @copyright ?2003-2103 phpwind.com
  12. * @license http://www.phpwind.com
  13. * @version $Id: PwDesignThreadDataService.php 25436 2013-03-15 08:45:34Z gao.wanggao $
  14. * @package
  15. */
  16. class PwDesignThreadDataService extends PwDesignModelBase{
  17. /**
  18. * (non-PHPdoc)
  19. * @see src/service/design/srv/model/PwDesignModelBase::decorateAddProperty()
  20. */
  21. public function decorateAddProperty($model) {
  22. $data = array();
  23. $forumService = $this->_getFroumService();
  24. $data['forumOption'] = '<option value="">全部版块</option>' . $forumService->getForumOption();
  25. $data['specileType'] = array();
  26. $tType = Wekit::load('forum.srv.PwThreadType')->getTtype();
  27. foreach ($tType AS $k=>$v) $data['specileType'][$k] = $v[0];
  28. return $data;
  29. }
  30. /**
  31. * (non-PHPdoc)
  32. * @see src/service/design/srv/model/PwDesignModelBase::decorateEditProperty()
  33. */
  34. public function decorateEditProperty($moduleBo) {
  35. $model = $moduleBo->getModel();
  36. $property = $moduleBo->getProperty();
  37. $data = array();
  38. $forumService = $this->_getFroumService();
  39. $data['forumOption'] = '<option value="">全部版块</option>' . $forumService->getForumOption($property['fids']);
  40. $data['specileType'] = array();
  41. $tType = Wekit::load('forum.srv.PwThreadType')->getTtype();
  42. foreach ($tType AS $k=>$v) $data['specileType'][$k] = $v[0];
  43. return $data;
  44. }
  45. /**
  46. * (non-PHPdoc)
  47. * @see src/service/design/srv/model/PwDesignModelBase::decorateSaveProperty()
  48. */
  49. public function decorateSaveProperty($property, $moduleid) {
  50. //直接调用版本
  51. if (isset($property['fids'][0]) && !$property['fids'][0]) $property['fids'] = array();
  52. $property['mapFid'] = $property['fids'];
  53. /*
  54. //下级版块的调用实现
  55. $mapFid = $fids = array();
  56. $srv = Wekit::load('forum.srv.PwForumService');
  57. $map = $srv->getForumMap();
  58. if (!is_array($property['fids'])) $property['fids'] = array();
  59. foreach ($property['fids'] AS $parentid) {
  60. $fids[] = $srv->getForumsByLevel($parentid, $map);
  61. }
  62. foreach ($fids AS $_fids) {
  63. foreach ($_fids AS $_v) {
  64. if (!$_v['isshow']) continue;
  65. $mapFid[] = $_v['fid'];
  66. }
  67. }
  68. $property['mapFid'] = array_unique(array_merge($mapFid, $property['fids']));
  69. if (isset($property['mapFid'][0]) && !$property['mapFid'][0]) $property['mapFid'] = array();
  70. */
  71. return $property;
  72. }
  73. protected function getData($field, $order, $limit, $offset) {
  74. Wind::import('SRV:forum.vo.PwThreadSo');
  75. $so = new PwThreadSo();
  76. $time = Pw::getTime();
  77. $so->setDisabled(0);
  78. $field['tids'] && $so->setTid(explode(' ', $field['tids']));
  79. if ($field['usernames']) {
  80. $usernames = explode(' ', $field['usernames']);
  81. foreach ($usernames AS &$username) $username = trim($username);
  82. $users = Wekit::load('user.PwUser')->fetchUserByName($usernames);
  83. $uids = array_keys($users);
  84. if ($uids) {
  85. $so->setAuthorId($uids);
  86. } else {
  87. return array();
  88. }
  89. }
  90. $field['keywords'] && $so->setKeywordOfTitle(trim($field['keywords']));
  91. $field['mapFid'] && $so->setFid($field['mapFid']);//修正后的fids
  92. $field['special'] && $so->setSpecial($field['special']);
  93. $field['istop'] && $so->setTopped($field['istop']);
  94. $field['ispic'] && $so->setHasImage($field['ispic']);
  95. //$field['isattach'] && $so->setIsattach($field['isattach']);
  96. $field['isdigest'] && $so->setDigest($field['isdigest']);
  97. $field['createdtime'] && $so->setCreateTimeStart($time-intval($field['createdtime']));
  98. $field['createdtime'] && $so->setCreateTimeEnd($time);
  99. $field['posttime'] && $so->setLastpostTimeStart($time-intval($field['posttime']));
  100. $field['posttime'] && $so->setLastpostTimeEnd($time);
  101. switch ($order) {
  102. case '2':
  103. $so->orderbyLastPostTime(false);
  104. break;
  105. case '1':
  106. $so->orderbyCreatedTime(false);
  107. break;
  108. case '3':
  109. $so->orderbyReplies(false);
  110. break;
  111. case '4':
  112. $so->orderbyHits(false);
  113. break;
  114. case '5':
  115. $so->orderbyLike(false);
  116. break;
  117. }
  118. $list = Wekit::load('forum.PwThread')->searchThread($so, $limit, $offset);
  119. return $this->_buildSignKey($list, $field['ishighlight']);
  120. }
  121. /**
  122. * 用于推送时的指定数据获取
  123. * @see src/service/design/srv/model/PwDesignModelBase::_fetchData()
  124. */
  125. protected function fetchData($ids) {
  126. $list = Wekit::load('forum.PwThread')->fetchThread($ids);
  127. return $this->_buildSignKey($list);
  128. }
  129. private function _buildSignKey($list, $ishighlight = null) {
  130. $content = $_tType = $_fid = $_aTid = array();
  131. $_tid = array_keys($list);
  132. $content = $this->_getContent($_tid);
  133. foreach ($list AS $v) {
  134. $_fid[] = $v['fid'];
  135. $_tType[] = $v['topic_type'];
  136. if ($content[$v['tid']]['aids']) $_aTid[] = $v['tid'];
  137. }
  138. $forums = $this->_getForum($_fid);
  139. $tTypes = $this->_getTopicType($_tType);
  140. $attachs = $this->_getAttachs($_aTid);
  141. if ($ishighlight){
  142. Wind::import('LIB:utility.PwHighlight');
  143. $highlight = new PwHighlight();
  144. }
  145. foreach ($list AS $k=>$v ) {
  146. if (!$forums[$v['fid']]['isshow']) $v = array();
  147. $list[$k]['subject'] = $this->_formatTitle($v['subject']);
  148. if ($ishighlight) {
  149. $styleArr = $highlight->parseHighlight($v['highlight']);
  150. $list[$k]['__style'] = array($styleArr['bold'],$styleArr['underline'],$styleArr['italic'],$styleArr['color']);
  151. }
  152. $list[$k]['url'] = WindUrlHelper::createUrl('bbs/read/run', array('tid' => $v['tid'], 'fid' => $v['fid']), '', 'pw');
  153. $list[$k]['content'] = $this->_formatDes($content[$k]['content']);
  154. $list[$k]['created_time'] = $this->_formatTime($v['created_time']);
  155. $list[$k]['lastpost_time'] = $this->_formatTime($v['lastpost_time']);
  156. $list[$k]['created_space'] = WindUrlHelper::createUrl('space/index/run', array('uid' => $v['created_userid']), '', 'pw');
  157. $list[$k]['created_smallavatar'] = Pw::getAvatar($v['created_userid'],'small');
  158. $list[$k]['created_middleavatar'] = Pw::getAvatar($v['created_userid'],'middle');
  159. $list[$k]['created_bigavatar'] = Pw::getAvatar($v['created_userid'],'big');
  160. $list[$k]['lastpost_smallavatar'] = Pw::getAvatar($v['lastpost_userid'],'small');
  161. $list[$k]['lastpost_middleavatar'] = Pw::getAvatar($v['lastpost_userid'],'middle');
  162. $list[$k]['lastpost_space'] = WindUrlHelper::createUrl('space/index/run', array('uid' => $v['lastpost_userid']), '', 'pw');
  163. $list[$k]['forum_name'] = $this-> _filterForumHtml($forums[$v['fid']]['name']);
  164. $list[$k]['forum_url'] = WindUrlHelper::createUrl('bbs/thread/run', array('fid' => $v['fid']), '', 'pw');
  165. $list[$k]['tType'] = isset($tTypes[$v['topic_type']]['name']) ? $tTypes[$v['topic_type']]['name'] : '' ;
  166. $list[$k]['tType_url'] = isset($tTypes[$v['topic_type']]['id']) ? WindUrlHelper::createUrl('bbs/thread/run', array('fid' => $v['fid'], 'type'=>$tTypes[$v['topic_type']]['id']), '', 'pw'): '' ;
  167. $list[$k]['thumb_attach'] = $attachs[$v['tid']]['path'] ? $attachs[$v['tid']]['path']: '';
  168. }
  169. return $list;
  170. }
  171. private function _getContent($ids) {
  172. return Wekit::load('forum.PwThread')->fetchThread($ids, PwThread::FETCH_CONTENT);
  173. }
  174. private function _getForum($fids) {
  175. return Wekit::load('forum.PwForum')->fetchForum($fids);
  176. }
  177. private function _getTopicType($ids) {
  178. return Wekit::load('forum.PwTopicType')->fetchTopicType($ids);
  179. }
  180. /**
  181. * 过滤版块名称html
  182. * Enter description here ...
  183. * @param string $forumname
  184. */
  185. private function _filterForumHtml($forumname) {
  186. return strip_tags($forumname);
  187. //return preg_replace('/<SPAN(.*)>(.*)<\/SPAN>/isU', '\\2', $forumname);
  188. }
  189. //TODO
  190. private function _getAttachs($tids) {
  191. $attachs = array();
  192. $ds = Wekit::load('attach.PwThreadAttach');
  193. foreach ($tids AS $tid) {
  194. $_attachs = $ds->getAttachByTid($tid, array(0));
  195. foreach ($_attachs AS $v) {
  196. if ($v['type'] == 'img') {
  197. $attachs[$tid] = $v;
  198. break;
  199. }
  200. }
  201. }
  202. return $attachs;
  203. }
  204. private function _getFroumService() {
  205. return Wekit::load('forum.srv.PwForumService');
  206. }
  207. private function _getModelDs() {
  208. return Wekit::load('design.PwDesignModel');
  209. }
  210. }
  211. ?>