Пример #1
0
 public function pdf(Mypdf $fpdf, $count, $answered = false)
 {
     $parse = $this->variants;
     $variants = explode(";", $parse);
     $fpdf->SetFont('TimesNewRomanPSMT', 'U', 12);
     $fpdf->Cell(20, 10, iconv('utf-8', 'windows-1251', 'Вопрос ' . $count . '.'), 0, 0);
     $fpdf->Cell(7, 10, iconv('utf-8', 'windows-1251', 'Выберите один вариант ответа'), 0, 1);
     $fpdf->SetFont('TimesNewRomanPSMT', '', 12);
     $fpdf->MultiCell(0, 5, iconv('utf-8', 'windows-1251', $this->text), 0, 1);
     $fpdf->Ln(2);
     $fpdf->SetWidths(array('10', '170'));
     if ($answered) {
         // пдф с ответами
         $answer = $this->answer;
         $new_variants = Session::get('saved_variants_order');
         foreach ($new_variants as $var) {
             if ($answer == $var) {
                 $fpdf->Row(array('   +', iconv('utf-8', 'windows-1251', $var)));
             } else {
                 $fpdf->Row(array(iconv('utf-8', 'windows-1251', ''), iconv('utf-8', 'windows-1251', $var)));
             }
             $fpdf->Ln(0);
         }
         Session::forget('saved_variants_order');
     } else {
         // без ответов
         $new_variants = QuestionController::mixVariants($variants);
         Session::put('saved_variants_order', $new_variants);
         foreach ($new_variants as $var) {
             $fpdf->Row(array(iconv('utf-8', 'windows-1251', ''), iconv('utf-8', 'windows-1251', $var)));
             $fpdf->Ln(0);
         }
     }
 }
Пример #2
0
 /** проверяет права доступа к рыбинским вопросам */
 public function rybaTest($id_question)
 {
     $question = new Question();
     $question_controller = new QuestionController($question);
     if ($question_controller->getCode($id_question)['section_code'] == 10) {
         if (Auth::user()['role'] == 'Рыбинец' || Auth::user()['role'] == 'Админ') {
             return true;
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
Пример #3
0
 /** перемешивает элементы массива */
 public static function mixVariants($variants)
 {
     $num_var = count($variants);
     $new_variants = [];
     for ($i = 0; $i < $num_var; $i++) {
         //варианты в случайном порядке
         $variants = QuestionController::randomArray($variants);
         $chosen = array_pop($variants);
         $new_variants[$i] = $chosen;
     }
     return $new_variants;
 }
Пример #4
0
 public function pdf(Mypdf $fpdf, $count, $answered = false)
 {
     $text_parts = explode("<>", $this->text);
     //части текста между селектами
     $parse = explode("%", $this->variants);
     $variants = explode("<>", $parse[0]);
     $num_slot = count($variants);
     $text = '';
     $fpdf->SetFont('TimesNewRomanPSMT', 'U', 12);
     $fpdf->Cell(20, 10, iconv('utf-8', 'windows-1251', 'Вопрос ' . $count . '.'), 0, 0);
     $fpdf->Cell(7, 10, iconv('utf-8', 'windows-1251', 'Заполните пропуски в тексте'), 0, 1);
     $fpdf->SetFont('TimesNewRomanPSMT', '', 12);
     if ($answered) {
         // пдф с ответами
         $answers = explode(";", $this->answer);
         for ($i = 1; $i <= $num_slot; $i++) {
             $text .= $text_parts[$i - 1] . '(' . $i . ' ' . $answers[$i - 1] . ') ';
             //формируем текст вопроса без пропущенных слов
         }
         $fpdf->Write(5, iconv('utf-8', 'windows-1251', $text));
         // вывод текста
         $fpdf->Ln(5);
         for ($i = 1; $i <= $num_slot; $i++) {
             // вывод верных ответов
             $fpdf->Write(5, iconv('utf-8', 'windows-1251', $i . ': ' . $answers[$i - 1]));
             $fpdf->Ln(5);
         }
     } else {
         // без ответов
         for ($i = 1; $i <= $num_slot; $i++) {
             $text .= $text_parts[$i - 1] . $i . '_______________';
             //формируем текст вопроса
         }
         $parse_group_variants = [];
         $group_variants = [];
         $num_var = [];
         for ($i = 0; $i < count($variants); $i++) {
             $parse_group_variants[$i] = explode(";", $variants[$i]);
             //варинаты каждого селекта
             $group_variants[$i] = QuestionController::mixVariants($parse_group_variants[$i]);
             //перемешиваем варианты
             $num_var[$i] = count($group_variants[$i]);
         }
         $fpdf->Write(5, iconv('utf-8', 'windows-1251', $text));
         // вывод текста
         $fpdf->Ln(5);
         for ($i = 1; $i <= $num_slot; $i++) {
             // вывод вариантов
             $fpdf->Write(5, iconv('utf-8', 'windows-1251', $i . ': '));
             for ($j = 0; $j < $num_var[$i - 1] - 1; $j++) {
                 $fpdf->Write(5, iconv('utf-8', 'windows-1251', $group_variants[$i - 1][$j] . ', '));
             }
             $fpdf->Write(5, iconv('utf-8', 'windows-1251', $group_variants[$i - 1][$j] . '.'));
             // вывод последнего варианта
             $fpdf->Ln(5);
         }
     }
 }
Пример #5
0
 /** Генерирует pdf файлы с тестом с заданным количеством вариантов */
 public function pdfTest(Request $request)
 {
     $question = new Question();
     $test = new Test();
     $test_controller = new TestController($test);
     $question_controller = new QuestionController($question);
     $test_name = $request->input('test');
     $num_var = $request->input('num-variants');
     $query = Test::whereTest_name($test_name)->select('amount', 'id_test')->first();
     $id_test = $query->id_test;
     $amount = $query->amount;
     // кол-во вопрососв в тесте
     $today = date("Y-m-d H-i-s");
     $dir = 'download/pdf_tests/' . $today;
     mkdir($dir);
     define('FPDF_FONTPATH', 'C:\\wamp\\www\\uir\\public\\fonts');
     for ($k = 1; $k <= $num_var; $k++) {
         // генерируем необходимое число вариантов
         $fpdf = new Mypdf();
         $answered_fpdf = new Mypdf();
         $this->headOfPdf($fpdf, $test_name, $k, $amount);
         $this->headOfPdf($answered_fpdf, $test_name, $k, $amount);
         $ser_array = $question_controller->prepareTest($id_test);
         // подготавливаем тест
         for ($i = 0; $i < $amount; $i++) {
             // показываем каждый вопрос из теста
             $id = $question_controller->chooseQuestion($ser_array);
             if (!$test_controller->rybaTest($id)) {
                 //проверка на вопрос по рыбе
                 return view('no_access');
             }
             $this->pdfQuestion($fpdf, $id, $i + 1);
             $this->pdfQuestion($answered_fpdf, $id, $i + 1, true);
             $fpdf->Ln(10);
             $answered_fpdf->Ln(10);
         }
         $fpdf->Output(iconv('utf-8', 'windows-1251', $dir . '/variant' . $k . '.pdf'), 'F');
         $answered_fpdf->Output(iconv('utf-8', 'windows-1251', $dir . '/answered_variant' . $k . '.pdf'), 'F');
     }
     $zip = $this->pdfToZip($dir);
     // создаем архив
     $this->delPdf($dir);
     // удаляем созданную папку с тестами
     $this->download($zip);
     // скачать архив
 }
Пример #6
0
 public function pdf(Mypdf $fpdf, $count, $answered = false)
 {
     $parse = $this->variants;
     $variants = explode(";", $parse);
     $fpdf->SetFont('TimesNewRomanPSMT', 'U', 12);
     $fpdf->Cell(20, 10, iconv('utf-8', 'windows-1251', 'Вопрос ' . $count . '.'), 0, 0);
     $fpdf->Cell(7, 10, iconv('utf-8', 'windows-1251', 'Выберите один или несколько вариантов ответа'), 0, 1);
     $fpdf->SetFont('TimesNewRomanPSMT', '', 12);
     $fpdf->MultiCell(0, 5, iconv('utf-8', 'windows-1251', $this->text), 0, 1);
     $fpdf->Ln(2);
     $fpdf->SetWidths(array('10', '170'));
     if ($answered) {
         // пдф с ответами
         $answers = explode(";", $this->answer);
         $new_variants = Session::get('saved_variants_order');
         for ($i = 0; $i < count($new_variants); $i++) {
             // идем по всем вариантам
             for ($j = 0; $j < count($answers); $j++) {
                 // идем по всем ответам
                 if ($answers[$j] == $new_variants[$i]) {
                     // если вариант совпал с ответом
                     $fpdf->Row(array('   +', iconv('utf-8', 'windows-1251', $new_variants[$i])));
                     $fpdf->Ln(0);
                     break;
                 } else {
                     if ($j == count($answers) - 1) {
                         // проверяем, не все ли ответы просмотрены
                         $fpdf->Row(array(iconv('utf-8', 'windows-1251', ''), iconv('utf-8', 'windows-1251', $new_variants[$i])));
                         // если так, то выводим строку без "+"
                         $fpdf->Ln(0);
                     } else {
                         continue;
                     }
                     // иначе смотрим следующий ответ
                 }
             }
         }
         Session::forget('saved_variants_order');
     } else {
         // без ответов
         $new_variants = QuestionController::mixVariants($variants);
         Session::put('saved_variants_order', $new_variants);
         foreach ($new_variants as $var) {
             $fpdf->Row(array(iconv('utf-8', 'windows-1251', ''), iconv('utf-8', 'windows-1251', $var)));
             $fpdf->Ln(0);
         }
     }
 }