PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/class/user/ListMyReply.class.php

https://github.com/hylinux/ltebbs
PHP | 239 lines | 122 code | 67 blank | 50 comment | 20 complexity | f7243fde750d6c77146fbae728d545dd 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/ListMyReply.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.'/ListMyReply.lang.php') ) {
  23. include_once LANG_PATH.SYSTEM_LANG.'/ListMyReply.lang.php';
  24. }
  25. class ListMyReply 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. $total_number = LayoutUtil::getTotalNumberReplyByUser($this->db, $user_name);
  113. //求总公的页面
  114. $total_page = ceil($total_number / $this->page_number );
  115. //取得当前的页面
  116. $page = $this->getParameter('page');
  117. if ( !$page || $page < 0 ) {
  118. $page = 1;
  119. }
  120. if ( $page > $total_page && $total_page > 0 ) {
  121. $page = $total_page;
  122. }
  123. $begin_page = 1;
  124. $end_page = $total_page;
  125. if ( $page <= 10 && $total_page >=10 ) {
  126. $end_page = 10;
  127. } else if ( $page > 10 ) {
  128. if ( $page % 10 == 0 ) {
  129. //向前翻
  130. $end_page = $page;
  131. $begin_page = $end_page - 9;
  132. } else if ( $page % 10 == 1 ) {
  133. //向后翻
  134. //确定开始的页数
  135. $begin_page = $page;
  136. if ( $begin_page > $total_page ) {
  137. $begin_page = $page - 9;
  138. }
  139. if ( ( $begin_page + 9 ) > $total_page ) {
  140. $end_page = $total_page;
  141. } else {
  142. $end_page = $begin_page + 9;
  143. }
  144. } else {
  145. $num = $page % 10;
  146. $pre_num = floor($page / 10 );
  147. $begin_page = $pre_num * 10 + 1;
  148. $end_page = $begin_page + 9;
  149. }
  150. }
  151. if ( $end_page > $total_page ) {
  152. $end_page = $total_page;
  153. }
  154. $nav_page_array = array();
  155. for( $i = $begin_page; $i<=$end_page; $i++ ) {
  156. array_push($nav_page_array, $i);
  157. }
  158. //帖子导航栏
  159. $smarty->assign('nav_page', $nav_page_array);
  160. //当前的页面
  161. $smarty->assign('now_page', $page);
  162. //共有的页面
  163. $smarty->assign('total_page', $total_page);
  164. $subject_array = LayoutUtil::getReplyInfoByUser($this->db, $user_name,
  165. $this->page_number, ($page -1 ) * $this->page_number, $show_best);
  166. $smarty->assign('subject', $subject_array);
  167. $smarty->display('listmyreply.tmpl');
  168. }
  169. //缺省每页显示多少条记录
  170. private $page_number = 15;
  171. }
  172. ?>