/** * 问题详情页 * @param $id 问题id */ public function details($id) { $uid = getUserId(); if (!$uid) { $uid = 0; } // 调用存储过程查询问题详情 // 包含问题基本信息 用户信息 投票信息 收藏 相关tag $query = " call proc_question_details({$id},{$uid}) "; $question = M('question')->query($query); // dump($question); //查询问题的答案 $mapanswer['question_id'] = array('eq', $id); $answers = M('answer a')->where($mapanswer)->order('votes desc')->join('left join auth_user u on a.user_id = u.id')->join('left join profile p on p.user_id = a.user_id')->field('a.id,a.votes,a.content,a.user_id,u.username,a.ct,a.accepted,p.pic,p.reputation')->select(); //如果用户已经登陆并且有答案,需要处理答案的投票信息 if (hadLogin() && $answers) { foreach ($answers as &$a) { $mapav['answer_id'] = array('eq', $a['id']); $mapav['user_id'] = array('eq', getUserId()); $av = M('avote')->where($mapav)->find(); if ($av) { $a['vote_type'] = $av['vote_type']; } unset($mapav); } } //dump($answers); $question[0]['q_answers'] = $answers; $this->assign('q', $question[0]); $this->display(); }
public function details($id) { $map['q.id'] = array('eq', $id); $q = M('question q')->where($map)->join('auth_user u on q.user_id= u.id')->field('q.id,q.title,q.votes,q.content,q.answers,q.views,q.ct,u.username,q.user_id,q.favorite')->select(); if (hadLogin()) { unset($map); $map['user_id'] = array('eq', getUserId()); $map['question_id'] = array('eq', $id); $qv = M('qvote')->where($map)->find(); if ($qv) { $this->assign('vote_type', $qv['vote_type']); } $fq = M('fquestion')->where($map)->find(); if ($fq) { $this->assign('favorite', 1); } } if ($q) { $q = $q[0]; $tags = $this->getQuestionTags($id); $q['tags'] = $tags; $mapanswer['question_id'] = array('eq', $q['id']); $answers = M('answer a')->where($mapanswer)->order('votes desc')->join(' auth_user u on a.user_id = u.id')->field('a.id,a.votes,a.answer,a.user_id,u.username,a.ct')->select(); if (hadLogin() && $answers) { foreach ($answers as &$a) { $mapav['answer_id'] = array('eq', $a['id']); $mapav['user_id'] = array('eq', getUserId()); $av = M('avote')->where($mapav)->find(); if ($av) { $a['vote_type'] = $av['vote_type']; } unset($mapav); } } $q['q_answers'] = $answers; $this->assign('q', $q); $this->display(); } }