2024-07-03 14:41:15 +03:00
|
|
|
<?php
|
2024-07-05 13:49:04 +03:00
|
|
|
namespace app\controllers;
|
|
|
|
|
|
|
|
|
|
|
|
use app\models\Answer;
|
|
|
|
use app\models\Upvote;
|
2024-07-03 14:41:15 +03:00
|
|
|
|
2024-07-09 16:08:50 +03:00
|
|
|
class AnswerController {
|
2024-07-05 13:49:04 +03:00
|
|
|
public function actionAddAnswer($answer,$question_id,$user_id)
|
2024-07-03 14:41:15 +03:00
|
|
|
{
|
|
|
|
return Answer::create(['answer'=>$answer,'question_id'=>$question_id,'user_id'=>$user_id]);
|
|
|
|
}
|
2024-07-05 13:49:04 +03:00
|
|
|
public static function actionUpvoteAnswer($answer_id,$user_id)
|
2024-07-03 14:41:15 +03:00
|
|
|
{
|
|
|
|
return Upvote::create(['answer_id'=>$answer_id,'user_id'=>$user_id]);
|
|
|
|
}
|
|
|
|
|
2024-07-05 13:49:04 +03:00
|
|
|
public function actionUpdateAnswer($answer_id,$new_answer)
|
2024-07-03 14:41:15 +03:00
|
|
|
{
|
|
|
|
$answer = Answer::find($answer_id);
|
|
|
|
$answer->answer = $new_answer;
|
|
|
|
return $answer->save();
|
|
|
|
}
|
2024-07-05 13:49:04 +03:00
|
|
|
|
|
|
|
public function actionViewAllAnswers(): void
|
|
|
|
{
|
|
|
|
foreach (Answer::all() as $answer)
|
|
|
|
{
|
|
|
|
echo $answer->answer . "<br>";
|
|
|
|
}
|
|
|
|
}
|
2024-07-03 14:41:15 +03:00
|
|
|
}
|