public function newComment($document_id, $content) { $this->requireLogin(); //调用评论插件写入数据库 $addon = new LocalCommentAddon(); $model = $addon->getCommentModel(); $comment_id = $model->addComment($this->getUid(), $document_id, $content); if (!$comment_id) { $this->apiError(2301, "评论失败"); } //返回成功消息 $this->apiSuccess("评论成功", null, array('comment_id' => $comment_id)); }
protected function getCommentList($document_id, $offset = 0, $count = 2) { //调用评论插件读取评论该列表 $addon = new LocalCommentAddon(); $result = $addon->getCommentList($document_id, $offset, $count); if (!$result) { $result = array(); } //添加评论编号 foreach ($result as &$e) { $e['comment_id'] = $e['id']; unset($e['id']); } //添加用户信息 foreach ($result as &$e) { $e['user'] = $this->getAuthorStructure($e['uid']); } //筛选需要的字段 foreach ($result as &$e) { $e = array('comment_id' => $e['comment_id'], 'user' => $e['user'], 'content' => $e['content'], 'create_time' => $e['create_time']); } //返回结果 return $result; }
public function listTakePartIn($uid = 0, $offset = 0, $count = 10, $comment_count = 2) { //默认UID if (!$uid) { $this->requireLogin(); $uid = $this->getUid(); } //确认参数正确 if ($uid <= 0 || $offset < 0 || $count < 0 || $comment_count < 0) { $this->apiError(400, '参数错误'); } //读取指定任务的评论列表 $addon = new LocalCommentAddon(); $map = array('uid' => $uid, 'status' => 1); $model = $addon->getCommentModel(); $result = $model->where($map)->order('create_time desc')->field('DISTINCT document_id')->limit("{$offset},{$count}")->select(); $totalCount = $model->where($map)->order('create_time desc')->count('DISTINCT document_id'); if (!$result) { $result = array(); } //获取主题的详细信息 foreach ($result as &$e) { $e = $this->getTopicStructure($e['document_id'], $comment_count); } //返回成功结果 $this->apiSuccess("获取成功", null, array('total_count' => $totalCount, 'list' => $result)); }