Example #1
0
 public function enrichRatingsWithAuthorName($ratings)
 {
     $userModel = ModelCollection::userModel();
     $moderationModel = ModelCollection::moderationModel();
     $questionModel = ModelCollection::questionModel();
     $reportModel = ModelCollection::reportModel();
     $entries = array();
     foreach ($ratings as $key => $rating) {
         $question = $questionModel->getQuestion($rating['question_id']);
         break;
     }
     foreach ($ratings as $key => $rating) {
         $entries[$key]['id'] = $rating['id'];
         $entries[$key]['user_id'] = $rating['user_id'];
         $entries[$key]['question_id'] = $rating['question_id'];
         $entries[$key]['stars'] = $rating['stars'];
         $entries[$key]['comment'] = $rating['comment'];
         $entries[$key]['author'] = $userModel->getUsernameByID($rating['user_id']);
         $entries[$key]['ismod'] = $moderationModel->isModerator($rating['user_id'], $question['category_id']);
         $entries[$key]['issuperuser'] = $userModel->isSuperuser($rating['user_id']);
         $entries[$key]['alreadyreported'] = $reportModel->checkIfUserAlreadyDoneReport("rating", $rating['id'], $_SESSION['user_id']);
         $entries[$key]['created'] = $rating['created'];
         $entries[$key]['parent'] = $rating['parent'];
     }
     return $entries;
 }
Example #2
0
 public function opQuestionWithAnswers($operation, $chosenCategory)
 {
     $answerModel = ModelCollection::answerModel();
     $categoryModel = ModelCollection::categoryModel();
     $tagModel = ModelCollection::tagModel();
     PermissionUtility::checkLogin();
     $this->checkForMissingParametersOpQwA($chosenCategory, $operation, $categoryModel);
     if (FORCE_RECAPTCHA_FOR_NEW_QUESTIONS) {
         $this->checkRecaptcha();
     }
     if ($_POST['opquestion_form_questionType'] == SINGLECHOICE_TYPE) {
         $type = $_POST['opquestion_form_questionType'];
         if ($operation == "new") {
             $questionID = $this->newQuestion($type, $_POST['opquestion_form_questionText'], $_SESSION['user_id'], $chosenCategory, $_POST['opquestion_form_attachment'], $_POST['opquestion_form_attachmentLocal']);
             //moveTempFile
             if ($_POST['opquestion_form_attachmentLocal'] == '1') {
                 $success = $this->moveTempFile($_POST['opquestion_form_attachmentTempFileName'], $questionID . '.' . $_POST['opquestion_form_attachment']);
                 if ($success == false) {
                     $this->logger->log("Attachment could not be moved", Logger::WARNING);
                 }
             }
             //remove all files in temp dir
             $this->removeAllFilesInTempDir();
             //insert all Answers to Db
             for ($i = 1; $i <= SINGLECHOICE_ANSWER_COUNT; $i++) {
                 if ($_POST['opquestion_form_correctness'] == $i) {
                     $correctnessOfAnswer = 100;
                 } else {
                     $correctnessOfAnswer = 0;
                 }
                 $answerModel->newAnswer($correctnessOfAnswer, $_POST['opquestion_form_answer' . $i], $_POST['opquestion_form_answerexplanation' . $i], $questionID);
             }
         } elseif ($operation == "edit") {
             $questionID = $_POST['opquestion_form_question_id'];
             $result = $this->editQuestion($type, $_POST['opquestion_form_questionText'], $_SESSION['user_id'], $_POST['opquestion_form_question_id'], $_POST['opquestion_form_attachment'], $_POST['opquestion_form_attachmentLocal']);
             //moveTempFile
             if ($_POST['opquestion_form_attachmentLocal'] == '1' && $_POST['opquestion_form_attachmentTempFileName'] != $_POST['opquestion_form_attachmentOld']) {
                 $this->removeAttachment($questionID . '.' . $_POST['opquestion_form_attachmentOld']);
                 $success = $this->moveTempFile($_POST['opquestion_form_attachmentTempFileName'], $questionID . '.' . $_POST['opquestion_form_attachment']);
                 if ($success == false) {
                     $this->logger->log("Attachment could not be moved", Logger::WARNING);
                 }
             }
             //remove all files in temp dir
             $this->removeAllFilesInTempDir();
             //edit answers
             $answers = $answerModel->getAnswersByQuestionID($_POST['opquestion_form_question_id']);
             $i = 0;
             foreach ($answers as $answer) {
                 $i = $i + 1;
                 if ($_POST['opquestion_form_correctness'] == $i) {
                     $correctnessOfAnswer = 100;
                 } else {
                     $correctnessOfAnswer = 0;
                 }
                 if ($operation == "edit") {
                     $answerModel->editAnswer($correctnessOfAnswer, $_POST['opquestion_form_answer' . $i], $_POST['opquestion_form_answerexplanation' . $i], $answer['id']);
                 } else {
                     $answerModel->newAnswer($correctnessOfAnswer, $_POST['opquestion_form_answer' . $i], $_POST['opquestion_form_answerexplanation' . $i], $questionID);
                 }
             }
         }
         if ($operation == "edit") {
             $tagModel->removeAllTagsOfQuestionById($_POST['opquestion_form_question_id']);
             // delete all and readd below. otherwise its way too complicated and not really faster
         }
         $this->handleNewTagCreation($questionID, $operation, $tagModel);
         if ($operation == "new") {
             return $questionID;
         }
         return;
     }
     $this->logger->log("Invalid questionType used in questionmodel", Logger::WARNING);
     MessageQueue::pushPersistent($_SESSION['user_id'], 'err_db_query_failed');
     NavigationUtility::redirectToErrorPage();
 }