Exemplo n.º 1
0
 public static function new_topic(array $topic)
 {
     $topic_id = topic_model::add($topic);
     board_model::inc_by_id(array('topic_count' => 1), $topic['board_id']);
     user_model::inc_by_id(array('topic_count' => 1), $topic['user_id']);
     return $topic_id;
 }
Exemplo n.º 2
0
 public static function new_reply(array $reply)
 {
     reply_model::add($reply);
     $user = user_model::get_by_id($reply['user_id']);
     topic_model::set_and_inc_by_id(array('last_post_user' => $user->name, 'last_post_time' => $reply['pub_time']), array('reply_count' => 1), $reply['topic_id']);
     board_model::set_and_inc_by_id(array('last_post_user' => $user->name, 'last_post_time' => $reply['pub_time']), array('reply_count' => 1), $reply['board_id']);
     user_model::inc_by_id(array('reply_count' => 1), $reply['user_id']);
 }
Exemplo n.º 3
0
 public static function show_action()
 {
     $board_id = g_int('id', 0);
     $board = board_model::get_by_id($board_id);
     self::forward_404_if($board === null, '板块不存在。');
     self::set('board', $board);
     $order_limit = array(array('id' => 'DESC'), g_int('page', 1), 10);
     list($pager, $topics) = topic_model::pager_with_count($board->topic_count, array('board_id' => $board_id), $order_limit);
     binder::bind($topics, 'belongs_to', 'user');
     $pager['target'] = 'board/show?id=' . $board_id;
     self::set('pager', $pager);
     self::set('topics', $topics);
     self::show_page();
 }
Exemplo n.º 4
0
 public static function do_new_action()
 {
     self::method('post');
     self::role('user');
     self::csrf('user');
     $board_id = g_int('board_id', 1);
     $board = board_model::get_by_id($board_id);
     try {
         $checker = new lazy_checker(p());
         $checker->check('title', array('change_to' => 'string', 'char_size' => array(3, topic_model::title_len, '标题长度为%d到%d个字符')));
         $checker->check('content', array('change_to' => 'string', 'char_size' => array(6, topic_model::content_len, '内容长度为%d到%d个字符')));
         $user_id = visitor::get_role_id('user');
         $topic = array('board_id' => $board_id, 'user_id' => $user_id, 'pub_time' => clock::get_stamp(), 'title' => $checker->title, 'content' => $checker->content);
         $topic_id = topic_service::new_topic($topic);
         self::json_result(true, '', 0, url('topic/show?id=' . $topic_id));
     } catch (check_failed $e) {
         self::json_result(false, $e->get_reasons());
     }
 }