/** * Get the number of items posted by this user for each catagory * * @return array with the activity for each content type. */ public function getActivity() { // Get the number of questions posted $question = new \Bjurnemark\Question\Question(); $question->setDI($this->di); $numQuestions = $question->getUserStats($this->id); // Get the number of answers posted $answer = new \Bjurnemark\Answer\Answer(); $answer->setDI($this->di); $numAnswers = $answer->getUserStats($this->id); // Get the number of comments posted $comment = new \Bjurnemark\Comment\Comment(); $comment->setDI($this->di); $numComments = $comment->getUserStats($this->id); $activity = ['numQuestions' => $numQuestions['count'], 'numAnswers' => $numAnswers['count'], 'numComments' => $numComments['count'], 'points' => $numQuestions['count'] * VAL_QUESTION + $numAnswers['count'] * VAL_ANSWER + $numComments['count'] * VAL_COMMENT + ($numQuestions['score'] + $numAnswers['score'] + $numComments['score']) * VAL_SCORE]; return $activity; }
/** * View questions by user id. * * @param $userId the user to display questions for. * @return void */ public function byUserAction($userId) { // // List questions posted by the user // $title = "Ställda frågor"; // Select the questions $data = $this->question->query()->where("user_id = {$userId}")->orderBy("id DESC")->execute(); $this->views->add('question/plainlist', ['data' => $data, 'title' => $title]); // // List questions answered by the user // $title = "Besvarade frågor"; // Get a handle to a answer object $answer = new \Bjurnemark\Answer\Answer(); $answer->setDI($this->di); // Get the tagged questions $qIds = $answer->getQuestionsAnsweredBy($userId); $data = null; if (0 != count($qIds)) { // Implode to string suitable for SELECT ... IN $qIds = '(' . implode(",", $qIds) . ')'; // Select the questions $data = $this->question->query()->where("id in {$qIds}")->orderBy("id DESC")->execute(); } $this->views->add('question/plainlist', ['data' => $data, 'title' => $title]); }