36 lines
849 B
PHP
36 lines
849 B
PHP
<?php
|
|
namespace app\controllers;
|
|
|
|
use app\models\Question;
|
|
use kernel\Controller;
|
|
|
|
|
|
class QuestionController extends Controller{
|
|
public function actionCreate()
|
|
{
|
|
echo $this->twig->render('question_create.html.twig');
|
|
}
|
|
|
|
public function actionGetQuestionsWithAnswers(): array
|
|
{
|
|
return Question::with('AnswerController')->get()->toArray();
|
|
}
|
|
|
|
public function actionGetQuestionsWithUsers(): array
|
|
{
|
|
return Question::with('user')->get()->toArray();
|
|
}
|
|
|
|
public function actionGetQuestionAnswersUpvotes($question_id)
|
|
{
|
|
return Question::find($question_id)->answers()->with('upvotes')->get()->toArray();
|
|
}
|
|
|
|
public function actionViewAllQuestions()
|
|
{
|
|
foreach (Question::all() as $question)
|
|
{
|
|
echo $question->question. "<br>";
|
|
}
|
|
}
|
|
} |