public function actionViewSoalQuiz($id) { $hasil = Quizsoal::model()->findAllByAttributes(array('id_quiz' => $id)); $soalkuis = new Quizsoal('search'); $soalkuis->id_quiz = $id; $kosong = 0; if ($_POST['Submit_jawaban']) { if (count($_POST['jawaban']) < 1) { echo "Anda belum menjawab soal satupun "; } else { $Jawaban = ""; $nomor = 1; //var_dump($_POST['NomorSoal']); // echo "*"; for ($i = 1; $i <= $_POST['NomorSoal']; $i++) { if ($_POST['jawaban']["{$i}"] == NULL) { $Jawaban .= "#"; $kosong += 1; } else { $Jawaban .= $_POST['jawaban']["{$i}"]; } } //echo $Jawaban; $encode = Soal::model()->getJawaban($id); //echo "<br>"; $count = 0; $wrong = 0; for ($i = 0; $i < $_POST['NomorSoal']; $i++) { // echo $_POST['jawaban'][$i]; //echo $encode[$i]["jawaban"]; // echo "*"; if ($_POST['jawaban'][$i + 1] == $encode[$i]["jawaban"]) { //secho "<br>", $_POST['jawaban']["$i"]," dan ",$encode[$i]["jawaban"]; $count += 1; } else { $wrong += 1; } } //var_dump($encode); } } //echo "<br>Anda benar : ",$count," dari ",$_POST['NomorSoal'], " soal"; $nilai = 100 / $_POST['NomorSoal'] * $count; // echo "<br>",$nilai; $name = Yii::app()->user->name; $koneksi_server = mysqli_connect('localhost', 'root', '', 'toefl'); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($koneksi_server, "INSERT INTO t_grade(username,jawaban,grade)\n VALUES ('{$name}', '{$Jawaban}','{$nilai}')"); mysqli_close($koneksi_server); //} if (!isset($_POST['Submit_jawaban'])) { $this->render('ViewSoalQuiz', array('model' => $soalkuis, 'hasil' => $hasil)); } else { $this->render('HasilQuiz', array('wew' => $nilai, 'wow' => $kosong, 'waw' => $wrong, 'wuw' => $count)); } }
public function actionSoal($id) { $rnd = rand(0, 9999); $inputSoal = new InputSoal(); if (isset($_POST['InputSoal'])) { $inputSoal->attributes = $_POST['InputSoal']; if ($inputSoal->validate()) { //create a file model $file = new File(); $uploadedFile = CUploadedFile::getInstance($inputSoal, 'file'); $fileName = "{$rnd}-{$uploadedFile}"; $file->file = $fileName; $file->jenis = $inputSoal->jenis; if ($file->save()) { //if(!empty($uploadedFile)) //$uploadedFile=CUploadedFile::getInstance($file,'file'); if (isset($uploadedFile)) { if ($inputSoal->jenis == 'L') { $uploadedFile->saveAs(Yii::app()->basePath . '/../music/test/' . $fileName); } else { if ($inputSoal->jenis == 'R') { $uploadedFile->saveAs(Yii::app()->basePath . '/../document/test/' . $fileName); } } } $soal = new Soal(); $soal->attributes = $inputSoal->attributes; $soal->id_file = $file->id_file; if ($soal->save()) { $kuissoal = new Quizsoal(); $kuissoal->id_quiz = $id; $kuissoal->id_soal = $soal->id_soal; if ($kuissoal->save()) { //redirect to index page $this->redirect(array('quiz/viewSoalQuiz', 'id' => $id)); } else { //get the error message $inputSoal->addErrors($soal->getErrors()); } } else { //get the error message $inputSoal->addErrors($soal->getErrors()); } } else { //get the error message $inputSoal->addErrors($soal->getErrors()); } } else { //get the error message $inputSoal->addErrors($file->getErrors()); } } //display input soal-form $this->render('Soal', array('model' => $inputSoal)); }