PageRenderTime 47ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/upload/src/applications/like/controller/MylikeController.php

https://gitlab.com/wuhang2003/phpwind
PHP | 269 lines | 209 code | 20 blank | 40 comment | 32 complexity | 33476025f90e63e7d36613d0dbccebc1 MD5 | raw file
  1. <?php
  2. Wind::import('LIB:base.PwBaseController');
  3. /**
  4. * the last known user to change this file in the repository <$LastChangedBy: gao.wanggao $>
  5. * @author $Author: gao.wanggao $ Foxsee@aliyun.com
  6. * @copyright ?2003-2103 phpwind.com
  7. * @license http://www.phpwind.com
  8. * @version $Id: MylikeController.php 6836 2012-03-27 04:05:46Z gao.wanggao $
  9. * @package
  10. */
  11. class MylikeController extends PwBaseController {
  12. public function beforeAction($handlerAdapter) {
  13. parent::beforeAction($handlerAdapter);
  14. if ($this->loginUser->uid < 1) $this->forwardRedirect(WindUrlHelper::createUrl('u/login/run/'));
  15. }
  16. public function run() {
  17. $page = (int) $this->getInput('page', 'get');
  18. $tagid = (int) $this->getInput('tag', 'get');
  19. $perpage = 10;
  20. $page = $page > 1 ? $page : 1;
  21. $service = $this->_getBuildLikeService();
  22. $tagLists = $service->getTagsByUid($this->loginUser->uid);
  23. if ($tagid > 0) {
  24. $resource = $this->_getLikeService()->allowEditTag($this->loginUser->uid, $tagid);
  25. if ($resource instanceof PwError) $this->showError($resource->getError());
  26. $count = $resource['number'];
  27. $logids = $service->getLogidsByTagid($tagid, $page, $perpage);
  28. $logLists = $service->getLogLists($logids);
  29. } else {
  30. list($start, $perpage) = Pw::page2limit($page, $perpage);
  31. $count = $this->_getLikeLogDs()->getLikeCount($this->loginUser->uid);
  32. $logLists = $service->getLogList($this->loginUser->uid, $start, $perpage);
  33. }
  34. // start
  35. $json = array();
  36. foreach ($logLists AS $_log) {
  37. $_log['tags'] = array_unique((array)$_log['tags']);
  38. if (!$_log['tags']) continue;
  39. $tagJson = array();
  40. foreach ((array)$_log['tags'] AS $_tagid) {
  41. if (!isset($tagLists[$_tagid]['tagname'])) continue;
  42. $tagJson[] = array(
  43. 'id'=>$_tagid,
  44. 'value'=>$tagLists[$_tagid]['tagname'],
  45. );
  46. }
  47. $json[] = array(
  48. 'id'=>$_log['logid'],
  49. 'items'=>$tagJson,
  50. );
  51. }
  52. //end
  53. $likeLists = $service->getLikeList();
  54. $likeInfos = $service->getLikeInfo();
  55. $hotBrand = $this->_getLikeService()->getLikeBrand('day1', 0, 10, true);
  56. $args = $tagid > 0 ? array("tag" => $tagid) : array();
  57. $this->setOutput($args, 'args');
  58. $this->setOutput($logLists, 'logLists');
  59. $this->setOutput($likeLists, 'likeLists');
  60. $this->setOutput($likeInfos, 'likeInfos');
  61. $this->setOutput($tagLists, 'tagLists');
  62. $this->setOutput($hotBrand, 'hotBrand');
  63. $this->setOutput($count, 'count');
  64. $this->setOutput($page, 'page');
  65. $this->setOutput($perpage, 'perpage');
  66. $this->setOutput($json, 'likeJson');
  67. // seo设置
  68. Wind::import('SRV:seo.bo.PwSeoBo');
  69. $seoBo = PwSeoBo::getInstance();
  70. $lang = Wind::getComponent('i18n');
  71. $seoBo->setCustomSeo($lang->getMessage('SEO:like.mylike.run.title'), '', '');
  72. Wekit::setV('seo', $seoBo);
  73. }
  74. public function taAction() {
  75. // seo设置
  76. Wind::import('SRV:seo.bo.PwSeoBo');
  77. $seoBo = PwSeoBo::getInstance();
  78. $lang = Wind::getComponent('i18n');
  79. $seoBo->setCustomSeo($lang->getMessage('SEO:like.mylike.ta.title'), '', '');
  80. Wekit::setV('seo', $seoBo);
  81. }
  82. public function dataAction() {
  83. $page = (int) $this->getInput('page', 'get');
  84. $start = (int) $this->getInput('start', 'get');
  85. $start >= 100 && $start = 100;
  86. $perpage = 20;
  87. $_data = array();
  88. $logLists = $this->_getBuildLikeService()->getFollowLogList($this->loginUser->uid, $start, $perpage);
  89. $likeLists = $this->_getBuildLikeService()->getLikeList();
  90. $likeInfos = $this->_getBuildLikeService()->getLikeInfo();
  91. $replyInfos = $this->_getBuildLikeService()->getLastReplyInfo();
  92. foreach ($logLists as $k => $logList) {
  93. if (!isset($likeInfos[$logList['likeid']])) continue;
  94. $_data[$k]['fromid'] = $likeLists[$logList['likeid']]['fromid'];
  95. $_data[$k]['fromtype'] = $likeLists[$logList['likeid']]['typeid'];
  96. $_data[$k]['url'] = $likeInfos[$logList['likeid']]['url'];
  97. $_data[$k]['image'] = $likeInfos[$logList['likeid']]['image'];
  98. $_data[$k]['subject'] = WindSecurity::escapeHTML($likeInfos[$logList['likeid']]['subject']);
  99. $_data[$k]['descrip'] = WindSecurity::escapeHTML(strip_tags($likeInfos[$logList['likeid']]['content']));
  100. $_data[$k]['uid'] = $likeInfos[$logList['likeid']]['uid'];
  101. $_data[$k]['username'] = $likeInfos[$logList['likeid']]['username'];
  102. $_data[$k]['avatar'] = Pw::getAvatar($likeInfos[$logList['likeid']]['uid'], 'small');
  103. $_data[$k]['space'] = WindUrlHelper::createUrl(
  104. 'space/index/run/?uid=' . $likeInfos[$logList['likeid']]['uid']);
  105. $_data[$k]['lasttime'] = Pw::time2str($likeInfos[$logList['likeid']]['lasttime'], 'auto');
  106. $_data[$k]['like_count'] = $likeInfos[$logList['likeid']]['like_count'];
  107. $_data[$k]['reply_pid'] = $replyInfos[$likeLists[$logList['likeid']]['reply_pid']];
  108. $_data[$k]['reply_uid'] = $replyInfos[$likeLists[$logList['likeid']]['reply_pid']]['uid'];
  109. $_data[$k]['reply_avatar'] = Pw::getAvatar($replyInfos[$likeLists[$logList['likeid']]['reply_pid']]['uid'],
  110. 'small');
  111. $_data[$k]['reply_space'] = WindUrlHelper::createUrl(
  112. 'space/index/run/?uid=' . $replyInfos[$likeLists[$logList['likeid']]['reply_pid']]['uid']);
  113. $_data[$k]['reply_username'] = $replyInfos[$likeLists[$logList['likeid']]['reply_pid']]['username'];
  114. $_data[$k]['reply_content'] = WindSecurity::escapeHTML($replyInfos[$likeLists[$logList['likeid']]['reply_pid']]['content']);
  115. $_data[$k]['like_url'] = WindUrlHelper::createUrl(
  116. 'like/mylike/doLike/?typeid=' . $_data[$k]['fromtype'] . '&fromid=' . $_data[$k]['fromid']);
  117. }
  118. $this->setOutput($_data, 'html');
  119. $this->showMessage('operate.success');
  120. }
  121. public function getTagListAction() {
  122. $array = array();
  123. $lists = $this->_getLikeTagService()->getInfoByUid($this->loginUser->uid);
  124. $this->setOutput($lists, 'data');
  125. $this->showMessage('BBS:like.success');
  126. }
  127. /**
  128. * 增加喜欢
  129. *
  130. */
  131. public function doLikeAction() {
  132. $typeid = (int) $this->getInput('typeid', 'post');
  133. $fromid = (int) $this->getInput('fromid', 'post');
  134. if ($typeid < 1 || $fromid < 1) $this->showError('BBS:like.fail');
  135. $resource = $this->_getLikeService()->addLike($this->loginUser, $typeid, $fromid);
  136. if ($resource instanceof PwError) $this->showError($resource->getError());
  137. $needcheck = false;
  138. if($resource['extend']['needcheck']) $needcheck = false;
  139. $data['likecount'] = $resource['likecount'];
  140. $data['needcheck'] = $needcheck;
  141. $this->setOutput($data, 'data');
  142. $this->showMessage('BBS:like.success');
  143. }
  144. /**
  145. * 删除我的喜欢
  146. *
  147. * 如果喜欢内容总喜欢数小于1,同时删除喜欢内容
  148. */
  149. public function doDelLikeAction() {
  150. $logid = (int) $this->getInput('logid', 'post');
  151. if (!$logid) $this->showError('BBS:like.fail');
  152. $resource = $this->_getLikeService()->delLike($this->loginUser->uid, $logid);
  153. if ($resource) $this->showMessage('BBS:like.success');
  154. $this->showError('BBS:like.fail');
  155. }
  156. /**
  157. * 编辑喜欢所属分类
  158. */
  159. public function doLogTagAction() {
  160. $tagid = (int)$this->getInput('tagid', 'post');
  161. $type = (int)$this->getInput('type', 'post');
  162. $logid = (int)$this->getInput('logid', 'post');
  163. if (!$logid || !$tagid) $this->showError('BBS:like.fail');
  164. $this->_getLikeService()->editLogTag($logid, $tagid, $type);
  165. $this->showMessage('BBS:like.success');
  166. }
  167. /**
  168. * 增加所属分类
  169. * Enter description here ...
  170. */
  171. public function doAddLogTagAction() {
  172. $tagname = $this->getInput('tagname', 'post');
  173. $logid = (int)$this->getInput('logid', 'post');
  174. if (!$logid || !$tagname) $this->showError('BBS:like.fail');
  175. $resource = $this->_getLikeService()->addTag($this->loginUser->uid,$tagname);
  176. if ($resource instanceof PwError) $this->showError($resource->getError());
  177. $tagid = (int)$resource;
  178. $this->_getLikeService()->editLogTag($logid, $tagid, 1);
  179. $this->setOutput(array('id'=>$tagid,'name'=>$tagname), 'data');
  180. $this->showMessage('BBS:like.success');
  181. }
  182. /**
  183. * 分类添加
  184. *
  185. */
  186. public function doAddTagAction() {
  187. $tagname = $this->getInput('tagname', 'post');
  188. if (!$tagname) $this->showError('BBS:like.fail');
  189. $resource = $this->_getLikeService()->addTag($this->loginUser->uid,$tagname);
  190. if ($resource instanceof PwError) $this->showError($resource->getError());
  191. $this->setOutput(array('id'=>(int)$resource,'name'=>$tagname), 'data');
  192. $this->showMessage('BBS:like.success');
  193. }
  194. /**
  195. * 分类删除
  196. *
  197. */
  198. public function doDelTagAction() {
  199. $tagid = (int) $this->getInput('tag', 'post');
  200. if (!$tagid) {
  201. $this->showError('operate.fail');
  202. }
  203. $info = $this->_getLikeService()->allowEditTag($this->loginUser->uid, $tagid);
  204. if ($info instanceof PwError) $this->showError($info->getError());
  205. if (!$this->_getLikeTagService()->deleteInfo($tagid)) $this->showError('BBS:like.fail');
  206. $this->_getLikeRelationsService()->deleteInfos($tagid);
  207. $this->showMessage('BBS:like.success', true, WindUrlHelper::createUrl('like/mylike/run/'));
  208. }
  209. /**
  210. * 编辑分类
  211. *
  212. */
  213. public function doEditTagAction() {
  214. $tagid = (int) $this->getInput('tag', 'post');
  215. $tagname = trim($this->getInput('tagname', 'post'));
  216. if (Pw::strlen($tagname) < 2) $this->showError('BBS:like.tagname.is.short');
  217. if (Pw::strlen($tagname) > 10) $this->showError('BBS:like.tagname.is.lenth');
  218. $tags = $this->_getLikeTagService()->getInfoByUid($this->loginUser->uid);
  219. $allow = false;
  220. foreach ($tags as $tag) {
  221. if ($tag['tagid'] == $tagid) $allow = true;
  222. if ($tag['tagname'] == $tagname) $this->showError('BBS:like.fail.already.tagname');
  223. }
  224. if (!$allow) $this->showError('BBS:like.fail');
  225. Wind::import('SRV:like.dm.PwLikeTagDm');
  226. $dm = new PwLikeTagDm($tagid);
  227. $dm->setTagname($tagname);
  228. $resource = $this->_getLikeTagService()->updateInfo($dm);
  229. if ($resource instanceof PwError) $this->showError($resource->getError());
  230. $this->setOutput(array('id'=>$tagid,'name'=>$tagname), 'data');
  231. $this->showMessage('BBS:like.success');
  232. }
  233. private function _getLikeRelationsService() {
  234. return Wekit::load('like.PwLikeRelations');
  235. }
  236. private function _getLikeTagService() {
  237. return Wekit::load('like.PwLikeTag');
  238. }
  239. private function _getBuildLikeService() {
  240. return Wekit::load('like.srv.PwBuildLikeService');
  241. }
  242. private function _getLikeService() {
  243. return Wekit::load('like.srv.PwLikeService');
  244. }
  245. private function _getLikeLogDs() {
  246. return Wekit::load('like.PwLikeLog');
  247. }
  248. }
  249. ?>