/** * Возвращает тесты и id соискателей * * @return array Массив в которого ключи - id соискателей, а значение - массив с тестами. */ public function getTestsA() { $select = $this->getAdapter()->select()->from(array('a' => Applicants::NAME), array('applicantId' => 'id'))->join(array('v' => Vacancies::NAME), 'a.vacancy_id = v.id', array())->join(array('vt' => $this->_name), 'vt.vacancy_id = v.id', array())->join(array('t' => Tests::NAME), 'vt.test_id = t.t_id', array('testId' => 't_id', 'testName' => 't_name')); $tests = $this->getAdapter()->query($select)->fetchAll(); $objAT = new ApplicantTests(); $arrTest = array(); foreach ($tests as $test) { $link = $objAT->getLink($test['applicantId'], $test['testId']); $percentMax = $objAT->getMaxPercent($test['applicantId'], $test['testId']); $scoreMax = $objAT->getMaxScore($test['applicantId'], $test['testId']); $linkMaxPercent = $objAT->getLinkForPercent($test['applicantId'], $test['testId'], $percentMax); $linkMaxScore = $objAT->getLinkForScore($test['applicantId'], $test['testId'], $scoreMax); $arrTest[$test['applicantId']][] = array('id' => $test['testId'], 'name' => $test['testName'], 'link' => $link, 'linkMaxScore' => $linkMaxScore, 'linkMaxPercent' => $linkMaxPercent, 'percentMax' => $percentMax, 'scoreMax' => $scoreMax); } return $arrTest; }
/** * Пересчитывает результат теста (вместо процентов - баллы) * @return void */ public function recalcAction() { if ($this->_authorize('test', 'edit')) { $link = $this->getRequest()->getParam('link'); $objApplicantTests = new ApplicantTests(); $applicantTest = $objApplicantTests->getTest($link); if (empty($applicantTest)) { exit; } $applicantId = $applicantTest->applicant_id; $testId = $applicantTest->test_id; $applicantTestId = $applicantTest->id; $objQuestion = new Questions(); $questions = $objQuestion->getQuestions($testId); $questions = $this->convertArr($questions, 'tq_id'); $objTestAnswers = new Answers(); $answers = $objTestAnswers->getAnswers(array_keys($questions)); // ключем $answers будет id вопроса $answers = $this->convertArr($answers, 'tq_id', true); $objApplicantAnswers = new ApplicantAnswers(); $applicantAnswers = $objApplicantAnswers->getAnswers($applicantTestId); $applicantAnswers = $this->convertArr($applicantAnswers, 'answer_id'); $result = $this->calcTestScore($questions, $answers, $applicantAnswers); $applicantTest->score = $result['score']; $applicantTest->percent = $result['percent']; $applicantTest->save(); } $this->_helper->redirector('testing', 'test', null, array('link' => $link)); }