Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Services;
- use App\Transformers\QuestionTransformer;
- use App\Repositories\QuestionRepository;
- class QuestionService extends Service
- {
- protected $questionRepository, $questionTransformer, $userService, $calculatorService;
- public function __construct()
- {
- $this->questionRepository = new QuestionRepository();
- $this->questionTransformer = new QuestionTransformer();
- }
- //Todas as questões
- public function getAllQuestions()
- {
- $questions = $this->questionRepository->all();
- if(!$questions)
- return new \Exception('Questions not found');
- $questions = $this->questionTransformer->transformCollection($questions->all());
- return $questions;
- }
- public function countAllQuestions()
- {
- $count = $this->questionRepository->all()->count();
- return $count;
- }
- public function getQuestionCollection($id)
- {
- return $this->questionRepository->find($id);
- }
- public function getQuestion($id)
- {
- $question = $this->questionRepository->find($id);
- if(!$question)
- return new \Exception('Question not found');
- $question = $this->questionTransformer->transform($question);
- return $question;
- }
- public function getQuestionsBySubject($request)
- {
- switch ($request->status){
- case 1: // all
- $questions = $this->questionRepository->findBySubject($request->id, $request->startYear,
- $request->endYear, $request->keyWord, $request->pagination);
- break;
- case 2: // user not resolved
- $questions = $this->questionRepository->findBySubjectUserNr($request->id, $request->startYear,
- $request->endYear, $request->keyWord, $request->pagination, $request->userId);
- break;
- case 3: // user resolved
- //TODO
- break;
- case 4: // not reviewed
- $questions = $this->questionRepository->findBySubjectNotReviewed($request->id, $request->startYear,
- $request->endYear, $request->keyWord, $request->pagination);
- break;
- default: // error
- break;
- }
- return $this->questionTransformer->transformCollectionOrderKey($questions->all());
- }
- public function getQuestionsByTopic($status,$idtopic, $startYear, $endYear,
- $keyWord, $pagination, $iduser)
- {
- switch ($status){
- case 1: // all
- $questions = $this->questionRepository->findByTopic($idtopic, $startYear,
- $endYear, $keyWord, $pagination);
- break;
- case 2: // user not resolved
- $questions = $this->questionRepository->findByTopicUserNr($idtopic, $startYear,
- $endYear, $keyWord, $pagination, $iduser);
- break;
- case 4: // not reviewed
- $questions = $this->questionRepository->findByTopicNotReviewed($idtopic, $startYear,
- $endYear, $keyWord, $pagination);
- break;
- default: // error
- break;
- }
- return $this->questionTransformer->transformCollectionOrderKey($questions->all());
- }
- public function countQuestionsBySubject($request)
- {
- switch ($request->status){
- case 1: // all
- $count = $this->questionRepository->countBySubject($request->id, $request->startYear,
- $request->endYear, $request->keyWord);
- break;
- case 2: // user not resolved
- //TODO: Redo user questions comparation
- $questions = $this->questionRepository->countBySubject($request->id, $request->startYear,
- $request->endYear, $request->keyWord);
- $questionsUser = $this->questionRepository->findBySubjectUser($request->id, $request->userId);
- $count1 = $questions;
- $count2 = $questionsUser->count();
- $count = $count1 - $count2;
- break;
- case 4: // not reviewed
- $count = $this->questionRepository->countBySubjectNotReviewed($request->id, $request->startYear,
- $request->endYear, $request->keyWord);
- break;
- default: // error
- break;
- }
- return $count;
- }
- public function countQuestionsByTopic($status,$idtopic, $startYear, $endYear, $keyWord, $iduser)
- {
- $count = 0;
- switch ($status){
- case 1: // all
- $count = $this->questionRepository->countByTopic($idtopic, $startYear,
- $endYear, $keyWord);
- break;
- case 2: // user not resolved
- //TODO: Redo user questions comparation
- $questions = $this->questionRepository->countByTopic($idtopic, $startYear,
- $endYear, $keyWord);
- $questionsUser = $this->questionRepository->findByTopicUser($idtopic, $iduser);
- $count1 = $questions;
- $count2 = $questionsUser->count();
- $count = $count1 - $count2;
- break;
- case 4: // not reviewed
- $count = $this->questionRepository->countByTopicNotReviewed($idtopic, $startYear,
- $endYear, $keyWord);
- break;
- default: // error
- break;
- }
- return $count;
- }
- public function countBySubjectBest($idsubject)
- {
- return $this->questionRepository->countBySubjectBest($idsubject);
- }
- public function countBySubject($idsubject)
- {
- return $this->questionRepository->countBySubjectId($idsubject);
- }
- public function countByTopic($idtopic)
- {
- return $this->questionRepository->countByTopicId($idtopic);
- }
- public function updateSubjetOfQuestion($idquest, $idsubject)
- {
- $question = $this->questionRepository->find($idquest);
- $question->subject_idsubject = $idsubject;
- $question->reviewed = 1;
- $question->save();
- return $question;
- }
- public function updateTopicOfQuestion($idquest, $idtopic)
- {
- $question = $this->questionRepository->find($idquest);
- $question->topic_idtopic = $idtopic;
- $question->reviewed = 1;
- $question->save();
- return $question;
- }
- public function getBestQuestion($idsubject, $iduser, $idquiz)
- {
- $userService = new UserService();
- $calculatorService = new CalculatorService();
- $theta = $userService->getSubjectUserRelationTheta($idsubject, $iduser);
- $question = $calculatorService->getBestQuestion($idsubject, $idquiz, $theta);
- $question = $this->questionTransformer->transform($question);
- return $question;
- }
- public function getFutureBestQuestion($idquiz, $idquest, $idsubject, $iduser, $idquests)
- {
- $userService = new UserService();
- $calculatorService = new CalculatorService();
- $question = $this->questionRepository->find($idquest);
- $futureRightTheta = $userService->updateUserTheta($question, $idsubject, $iduser, 1, false);
- $futureWrongTheta = $userService->updateUserTheta($question, $idsubject, $iduser, 0, false);
- $idquests[] = $idquest;
- $questionRight = $calculatorService->getBestQuestion($idsubject, $idquiz, $futureRightTheta, $idquests);
- $idquests[] = $questionRight->idquest;
- $questionWrong = $calculatorService->getBestQuestion($idsubject, $idquiz, $futureWrongTheta, $idquests);
- $data = [
- 'futureRightAnswerQuestion' => $this->questionTransformer->transform($questionRight),
- 'futureWrongAnswerQuestion' => $this->questionTransformer->transform($questionWrong),
- 'futureRightTheta' => $futureRightTheta,
- 'futureWrongTheta' => $futureWrongTheta,
- ];
- return $data;
- }
- public function getQuestionParametersBySubject($idsubject)
- {
- return $this->questionRepository->findQuestionParametersBySubject($idsubject);
- }
- public function updateQuestionParameters($question, $usersAnswers)
- {
- $var = $this->calculatorService->updateQuestionParameters($usersAnswers, $question);
- return $var;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement