PageRenderTime 60ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/class/favor/ShowFavor.class.php

https://github.com/hylinux/ltebbs
PHP | 268 lines | 144 code | 73 blank | 51 comment | 25 complexity | b6230fdb69a03e809909620591944ff6 MD5 | raw file
  1. <?php
  2. //vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldcolumn=1 foldmethod=marker:
  3. /**
  4. * 项目: 5anet(BBS)
  5. * 文件: class/user/ShowFavor.class.php
  6. *
  7. * 分页列出用户的收藏
  8. *
  9. * PHP Version 5
  10. *
  11. * @package: class.user
  12. * @author: Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
  13. * @license: http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  14. * @copyright: http://www.5anet.com
  15. * @version: $Id: $
  16. * @date: $Date:$
  17. */
  18. include_once CLASS_PATH.'main/BaseAction.class.php';
  19. include_once CLASS_PATH.'user/UserUtil.class.php';
  20. include_once CLASS_PATH.'bbs/LayoutUtil.class.php';
  21. //include the language file
  22. if ( file_exists(LANG_PATH.SYSTEM_LANG.'/ShowFavor.lang.php') ) {
  23. include_once LANG_PATH.SYSTEM_LANG.'/ShowFavor.lang.php';
  24. }
  25. class ShowFavor extends BaseAction {
  26. /**
  27. * 数据库的连接
  28. */
  29. public $db;
  30. /**
  31. * 构造函数
  32. * @param: NULL
  33. * @return: NULL
  34. * @access: public
  35. */
  36. public function __construct() {
  37. $this->db = $this->getDB();
  38. }
  39. /**
  40. * 显示用户的控制面板
  41. */
  42. public function run() {
  43. //求得用户的id
  44. $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']);
  45. $smarty = $this->getSmarty();
  46. $user_name = $_SESSION['user']['name'];
  47. $smarty->assign('view_user_name', $user_name);
  48. //用户的所在组
  49. $sql = 'select b.group_name from base_user_info as a join sys_group as b on '.
  50. ' a.group_dep = b.id where a.id=?';
  51. $sth = $this->db->Prepare($sql);
  52. $res = $this->db->Execute($sth, array($user_id));
  53. $rows = $res->FetchRow();
  54. $smarty->assign('user_roles', $rows['group_name']);
  55. $user_header = UserUtil::getUserHeader($this->db, $user_id);
  56. $smarty->assign('head_url', $user_header);
  57. //查询新的短消息的数量
  58. $sql = 'select count(*) as num from message_inbox where user_id=? and is_read = 0 ';
  59. $sth = $this->db->Prepare($sql);
  60. $res = $this->db->Execute($sth, array($user_id));
  61. $rows = $res->FetchRow();
  62. $smarty->assign('new_message_label', $rows['num']);
  63. //共有短消息数
  64. $sql = 'select count(*) as num from message_inbox where user_id=? ';
  65. $sth = $this->db->Prepare($sql);
  66. $res = $this->db->Execute($sth, array($user_id));
  67. $rows = $res->FetchRow();
  68. $smarty->assign('total_message_number', $rows['num']);
  69. //取得用户注册时间
  70. $sql = 'select register_date from base_user_info where id=?';
  71. $stmt = $this->db->prepare($sql);
  72. $res = $this->db->CacheExecute(60*60, $stmt, array($user_id));
  73. $rows = $res->FetchRow();
  74. $smarty->assign('user_register_date', $rows['register_date']);
  75. //取得用户最后的登录时间
  76. $sql = 'SELECT from_unixtime(last_time) as lastlogout FROM `user_last_time_logout` where user_id=?';
  77. $stmt = $this->db->prepare($sql);
  78. $res = $this->db->CacheExecute(60*60, $stmt, array($user_id));
  79. $rows = $res->FetchRow();
  80. $smarty->assign('user_last_logout', $rows['lastlogout']);
  81. //发表的主题数
  82. $sql = 'select count(*) as num from bbs_subject where author = ?';
  83. $stmt = $this->db->Prepare($sql);
  84. $res = $this->db->CacheExecute(10, $stmt, array($user_name));
  85. $rows = $res->FetchRow();
  86. $smarty->assign('all_topic_number', $rows['num']);
  87. //参与的帖子数
  88. $sql = 'select count(*) as num from bbs_reply where author=?';
  89. $stmt = $this->db->Prepare($sql);
  90. $res = $this->db->CacheExecute(10, $stmt, array($user_name));
  91. $rows = $res->FetchRow();
  92. $smarty->assign('all_reply_number', $rows['num']);
  93. ///拥有的短消息的数量
  94. $sql = 'select count(*) as num from message_inbox where user_id=?';
  95. $stmt = $this->db->prepare($sql);
  96. $res = $this->db->CacheExecute(20, $stmt, array($user_id));
  97. $rows = $res->FetchRow();
  98. $number_inbox = $rows['num'];
  99. $sql = 'select count(*) as num from message_outbox where user_id=?';
  100. $stmt = $this->db->prepare($sql);
  101. $res = $this->db->CacheExecute(20, $stmt, array($user_id));
  102. $rows = $res->FetchRow();
  103. $smarty->assign('message_all_number', $number_inbox + $rows['num']);
  104. //拥有的收藏数
  105. $sql = 'select count(*) as num from favor where user_id=?';
  106. $stmt = $this->db->prepare($sql);
  107. $res = $this->db->CacheExecute(10, $stmt, array($user_id));
  108. $rows = $res->FetchRow();
  109. $smarty->assign('favor_amount', $rows['num']);
  110. //取得导航栏菜单
  111. //开始检查帖子。
  112. $dir = $this->getParameter('dir');
  113. if ( !$dir ) {
  114. $dir = 0;
  115. }
  116. if ( $dir ) {
  117. $sql = 'select count(*) as num from favor where user_id=? and dir_id=?';
  118. } else {
  119. $sql = 'select count(*) as num from favor where user_id=?';
  120. }
  121. $stmt = $this->db->prepare($sql);
  122. if ( $dir ) {
  123. $res = $this->db->Execute($stmt, array($user_id, $dir));
  124. } else {
  125. $res = $this->db->Execute($stmt, array($user_id));
  126. }
  127. $rows = $res->FetchRow();
  128. $total_number = $rows['num'];
  129. //求总公的页面
  130. $total_page = ceil($total_number / $this->page_number );
  131. //取得当前的页面
  132. $page = $this->getParameter('page');
  133. if ( !$page || $page < 0 ) {
  134. $page = 1;
  135. }
  136. if ( $page > $total_page && $total_page > 0 ) {
  137. $page = $total_page;
  138. }
  139. $begin_page = 1;
  140. $end_page = $total_page;
  141. if ( $page <= 10 && $total_page >=10 ) {
  142. $end_page = 10;
  143. } else if ( $page > 10 ) {
  144. if ( $page % 10 == 0 ) {
  145. //向前翻
  146. $end_page = $page;
  147. $begin_page = $end_page - 9;
  148. } else if ( $page % 10 == 1 ) {
  149. //向后翻
  150. //确定开始的页数
  151. $begin_page = $page;
  152. if ( $begin_page > $total_page ) {
  153. $begin_page = $page - 9;
  154. }
  155. if ( ( $begin_page + 9 ) > $total_page ) {
  156. $end_page = $total_page;
  157. } else {
  158. $end_page = $begin_page + 9;
  159. }
  160. } else {
  161. $num = $page % 10;
  162. $pre_num = floor($page / 10 );
  163. $begin_page = $pre_num * 10 + 1;
  164. $end_page = $begin_page + 9;
  165. }
  166. }
  167. if ( $end_page > $total_page ) {
  168. $end_page = $total_page;
  169. }
  170. $nav_page_array = array();
  171. for( $i = $begin_page; $i<=$end_page; $i++ ) {
  172. array_push($nav_page_array, $i);
  173. }
  174. //帖子导航栏
  175. $smarty->assign('nav_page', $nav_page_array);
  176. //当前的页面
  177. $smarty->assign('now_page', $page);
  178. //共有的页面
  179. $smarty->assign('total_page', $total_page);
  180. //取出所有的dir
  181. $sql = 'select id, dir_name from favor_dir where user_id=?';
  182. $stmt = $this->db->prepare($sql);
  183. $res = $this->db->Execute($stmt, array($user_id));
  184. $rows = $res->GetAll();
  185. $smarty->assign('dir', $dir);
  186. $smarty->assign('dir_array', $rows);
  187. $subject_array = LayoutUtil::getSubjectInfoByFavor($this->db, $user_id, $dir,
  188. $this->page_number, ($page -1 ) * $this->page_number);
  189. $smarty->assign('subject', $subject_array);
  190. $smarty->display('showfavor.tmpl');
  191. }
  192. //缺省每页显示多少条记录
  193. private $page_number = 15;
  194. }
  195. ?>