function blended_update_assignment_and_gradebook($id_assignment, $id_assignment_0 = null, $all_teams, $blended, $id, $currentuserid, $id_team = null)
{
    global $CFG, $DB;
    //require_once("$CFG->dirroot/mod/assign/lib.php");
    //require_once("$CFG->dirroot/mod/forum/lib.php");
    //require_once("$CFG->dirroot/mod/assignment/lib.php");
    global $DB;
    $activity_cm = get_coursemodule_from_id(null, $id_assignment);
    $assignment = blended_get_assignment($activity_cm->id, $id);
    foreach ($all_teams as $index => $id_member) {
        $blendedgrade = new object();
        $blendedgrade->rewrite = null;
        $g = new object();
        $grades = array();
        // Dos modos de funcionamiento
        $user = blended_get_user($id_member, $blended, null);
        $blendedgrade = blended_get_user_grade($user, $activity_cm->id, $id_assignment_0, $id_member, $blended, null);
        if ($blendedgrade != null) {
            // ASSIGNMENT SUBMISSION -----------------------------------------
            blended_delete_submission($activity_cm->id, $user->id);
            $newsubmission = blended_prepare_new_submission($activity_cm->id, $user->id, $currentuserid, $blendedgrade->grade);
            if (!$DB->insert_record("assignment_submissions", $newsubmission)) {
                error("Could not insert a new empty submission");
            }
            $g->grades[$user->id] = new object();
            $g->grades[$user->id]->userid = $user->id;
            $g->grades[$user->id]->finalgrade = $blendedgrade->grade;
            $actividad = $DB->get_record('grade_items', array('iteminstance' => $assignment->instance));
            $assignments = $DB->get_records($actividad->itemmodule);
            foreach ($assignments as $ass) {
                if ($ass->id == $assignment->instance) {
                    activity_grade_item_update($assignment, $g);
                }
            }
        }
        if ($blendedgrade != null && $blendedgrade->rewrite == 0) {
            continue;
        }
    }
    // Fin foreach
}
示例#2
0
    if (isset($_REQUEST["selectedActivity{$i}"])) {
        $acodes[] = $_REQUEST["selectedActivity{$i}"];
    }
}
if ($acode) {
    $acodes[] = $acode;
}
global $CFG;
print_spacer(20);
print_heading(format_string(get_string('correction', 'blended')));
// iterate over the activity codes
foreach ($acodes as $acode) {
    $link = new stdClass();
    $quizid = find_quizid($acode);
    $id_member = find_userid($acode, $jobid);
    $user_reg = blended_get_user($id_member, $blended);
    $link->hrefText = "Resultados";
    $link->href = "{$CFG->wwwroot}/mod/quiz/report.php?&q={$quizid}";
    try {
        evaluate_quiz($acode, $jobid, $newattempt, $blended);
    } catch (EvaluationError $e) {
        print "EvaluationError: " . $e->getMessage();
        register_exception($e, $jobid);
    } catch (ResultsError $e) {
        print "ResultsError: " . $e->getMessage();
        register_exception($e, $jobid);
    }
    /**
     * Mark images as passed
     */
    set_field('blended_images', 'status', IMAGE_STATUS_PASSED, 'activitycode', $acode);
function evaluate_quiz($acode, $jobid, $newattempt, $blended)
{
    global $USER;
    global $CFG;
    mtrace("Evaluation QUIZ Processing..." . "<BR><BR>");
    try {
        print "New Attempt is: " . $newattempt . "<BR/>";
        $detected_userid = find_userid($acode, $jobid);
        if ($detected_userid == null or $detected_userid == '') {
            throw new EvaluationError(get_string('ErrorUserIDEmpty', 'blended'), EvaluationError::USERID_IS_EMPTY);
        }
        $user_reg = blended_get_user($detected_userid, $blended);
        if ($user_reg == null) {
            throw new EvaluationError(get_string('ErrorUserNotInCourse', 'blended'), EvaluationError::USER_NOT_IN_THIS_COURSE);
        }
        $userid = $user_reg->id;
        mtrace('Obtained USERID value: ' . $userid . " OK. <BR/>");
        $quiz = get_quiz($acode);
        $attempts = quiz_get_user_attempts($quiz->id, $userid, 'all', true);
        mtrace("Searching quiz... Success." . "<BR/>");
        $uniqueid = get_uniqueid($acode);
        mtrace('Obtained uniqueid: OK. <BR/>');
        $timestamp = get_timestamp($acode);
        mtrace('Obtained timestamp: OK. <BR/>');
        if (!get_record('quiz_attempts', 'uniqueid', $uniqueid)) {
            $newattempt = true;
        } else {
            $newattempt = false;
            mtrace("User {$userid} had opened this attempt already.");
        }
        $attemptnumber = 1;
        if ($newattempt == false) {
            mtrace('Obtaining user attempt...<BR/>');
            set_attempt_unfinished($uniqueid);
            $attempt = quiz_get_user_attempt_unfinished($quiz->id, $userid);
        } elseif ($newattempt == true) {
            mtrace('Creating new attempt...<BR/>');
            $attempt = create_new_attempt($quiz, $attemptnumber, $userid, $acode, $uniqueid, $timestamp);
            // Save the attempt
            if (!insert_record('quiz_attempts', $attempt)) {
                throw new EvaluationError(get_string('ErrorCouldNotCreateAttempt', 'blended'), EvaluationError::CREATE_QUIZ_ATTEMPT_ERROR);
            }
            // Actualizamos el estado de las imágenes para indicar que ya está creado un nuevo attempt
            update_images_status($acode, $jobid);
        }
        update_question_attempts($uniqueid);
        // /*
        mtrace('<BR>Getting questions and question options... ');
        $questions = get_questions($attempt, $quiz);
        if (!get_question_options($questions)) {
            error('Could not load question options');
        }
        mtrace('Success! <BR>');
        //	print ("<BR>He obtenido questions: ");
        //print_object($questions);
        $lastattemptid = false;
        //	 if ($attempt->attempt > 1 and $quiz->attemptonlast and !$attempt->preview) {
        // Find the previous attempt
        //      if (!$lastattemptid = get_field('quiz_attempts', 'uniqueid', 'quiz', $attempt->quiz, 'userid', $attempt->userid, 'attempt', $attempt->attempt-1)) {
        //        error('Could not find previous attempt to build on');
        //  }
        //}
        //print ('He obtenido lastattemptid');
        mtrace('Getting question states... ');
        if (!($states = get_question_states($questions, $quiz, $attempt, $lastattemptid))) {
            error('Could not restore question sessions');
        }
        mtrace('Success! <BR>');
        mtrace('Getting responses... <BR>');
        $responses = get_responses($acode, $jobid, $attempt);
        //print('Estas son las responses:');
        //print_object($responses);
        //$timestamp=time();
        $event = 8;
        $actions = question_extract_responses($questions, $responses, $event);
        $questionids = get_questionids($acode);
        //	print $questionids;
        $questionidarray = explode(',', $questionids);
        $success = true;
        mtrace('<BR> Processing responses and saving session... ');
        foreach ($questionidarray as $i) {
            if (!isset($actions[$i])) {
                $actions[$i]->responses = array('' => '');
                $actions[$i]->event = QUESTION_EVENTOPEN;
            }
            $actions[$i]->timestamp = $timestamp;
            if (question_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt)) {
                save_question_session($questions[$i], $states[$i]);
            } else {
                $success = false;
            }
        }
        mtrace('Success! <BR>');
        // Set the attempt to be finished
        $timestamp = time();
        //$attempt->timefinish = $timestamp;
        // Update the quiz attempt and the overall grade for the quiz
        mtrace('<BR> Finishing the attempt... ');
        // print_object ($attempt);
        if (set_field('quiz_attempts', 'timefinish', $timestamp, 'uniqueid', $uniqueid) == false) {
            throw new EvaluationError('Unable to finish the quiz attempt!', EvaluationError::FINISH_QUIZ_ATTEMPT_ERROR);
        }
        mtrace('Success! <BR>');
        if ($attempt->attempt > 1 || $attempt->timefinish > 0 and !$attempt->preview) {
            mtrace('<BR> Saving quiz grade... ');
            quiz_save_best_grade($quiz, $userid);
        }
        mtrace('Success! <BR>');
        // */
        mtrace("Process Done. <BR><BR>");
        mtrace("<center> Your quiz has been succesfully evaluated!! </center>");
    } catch (EvaluationError $e) {
        throw $e;
    }
    return;
}
/**
 * Construct a table view of all results related to a quiz
 * 
 */
function show_quiz_results_table($blended, $quiz, $course, $context)
{
    global $CFG;
    $currentpage = 'quizJob.php';
    if (!($images_view = get_records($table = "blended_images", $field = 'jobid', $value = $jobid, $sort = 'activitycode,pageindex'))) {
        print_box(get_string('ErrorScannedImageNotFound', 'blended'));
    } else {
        $i = 0;
        $images = array();
        $displayed_codes = array();
        $iconWarning = '<img src="images/warning.png" width="32" alt="' . get_string('MarkWarning', 'blended') . '"/>';
        echo "<form action=\"evaluate.php\" method=\"POST\" >";
        echo '<input type="hidden" name="a" value="' . $blended->id . '"/>';
        echo '<input type="hidden" name="jobid" value="' . $jobid . '"/>';
        foreach ($images_view as $result) {
            $acode = $result->activitycode;
            $imgout = $result->imgout;
            $pageindex = $result->pageindex;
            if ($acode) {
                $quiz_already_displayed = in_array($acode, $displayed_codes);
                if ($quiz_already_displayed == false) {
                    $imagerow = array();
                    $id_member = find_userid($acode, $jobid);
                    $user_reg = blended_get_user($id_member, $blended);
                    $verresultados = get_string('modulename', 'quiz') . $acode;
                    $quiz_in_course = check_quiz_course($acode, $course);
                    $showdetailslink = "<a href=\"showdetails.php?&a={$blended->id}&acode={$acode}&jobid={$result->jobid}\">{$verresultados}</a>";
                    $attempts = get_record('blended_attempts', 'id', $acode);
                    $index = $i + 1;
                    if ($user_reg != null && $attempts != false) {
                        $checkbox = "<input type=\"checkbox\" name=\"selectedActivity{$index}\" value=\"{$acode}\" />";
                    } else {
                        $checkbox = "<input type=\"checkbox\" name=\"selectedActivity{$index}\" disabled=\"true\" value=\"{$acode}\" />";
                    }
                    $imagerow["index"] = $checkbox . $index;
                    $imagerow["correctionlink"] = $showdetailslink;
                    $imagerow["activitycode"] = $result->activitycode . get_string('page', 'blended') . $pageindex;
                    $imagerow["alumno"] = '';
                    if ($user_reg !== null) {
                        $imagerow["alumno"] = print_user_picture($user_reg, $course->id, null, null, true) . fullname($user_reg);
                    } else {
                        $imagerow["alumno"] = get_string('ErrorUserIDEmpty', 'blended');
                    }
                    $imagerow["pasar"] = '';
                    $imagerow["status"] = '';
                    $status = '';
                    $warnings = count_doubtfull_marks($acode, $jobid);
                    if ($warnings > 0) {
                        $warn = $iconWarning . "Hay {$warnings} marcas dudosas!!";
                    } else {
                        $warn = '';
                    }
                    $imagerow["activitycode"] = $warn . '<br/>' . $imagerow["activitycode"];
                    if ($quiz_in_course) {
                        if (has_capability('mod/blended:evaluatequiz', $context)) {
                            if ($result->status == IMAGE_STATUS_PENDING) {
                                $evaluate = get_string('blendedPassToQuiz', 'blended');
                                $link = "<a href=\"evaluate.php?&a={$blended->id}&acode={$acode}&jobid={$jobid}\">{$evaluate}</a>";
                                $imagerow["pasar"] = $link;
                                $status = get_string('NotYet', 'blended');
                            } else {
                                $imagerow["pasar"] = get_string('blendedPassedToQuiz', 'blended');
                                $link = "<a href=\"evaluate.php?a={$blended->id}&acode={$acode}&jobid={$jobid}\">" . get_string('blendedPassAgainToQuiz', 'blended') . "</a>";
                                $status = $link;
                            }
                        } else {
                            $imagerow["pasar"] = "Permission Denied" . ($status = "");
                        }
                    }
                    $imagerow["status"] = $status;
                    if (has_capability('mod/blended:deletequiz', $context)) {
                        $imgdelete = "<img src=\"delete.gif\"/>";
                        $link = "<a href=\"delete_quiz.php?page={$currentpage}&acode={$acode}&jobid={$jobid}&a={$blended->id}\">{$imgdelete}</a>";
                        $delete = $link;
                        $imagerow["delete"] = $delete;
                    }
                    if ($attempts == false) {
                        // attempt not found in blended.
                        /*	echo"<center>";
                        			mtrace("El cuestionario que ha procesado pertenece a otro curso o no existe en la base de datos de este servidor.");
                        			echo"<center><br><br>";*/
                        $scan = blended_getOMRScanJob($result->jobid);
                        $resultname = $scan->scan_name . "-" . $result->id;
                        $correctionlink = "<a href=\"activitycode.php?&a={$blended->id}&jobid={$result->jobid}&resultid={$result->id}\">{$resultname}</a>";
                        $imagerow["correctionlink"] = $correctionlink;
                        //$imagerow["correctionlink"]='';
                        $imagerow["activitycode"] = "Erróneo." . $result->activitycode . ' ' . get_string('pages', 'blended') . $pageindex;
                        $imagerow["alumno"] = '';
                        $imagerow["pasar"] = '<img align="left" src="images/warning.png" width="32"/>' . get_string('ErrorActivityCodeNotFound', 'blended', $acode);
                        $status = "";
                        $key = "{$acode}{$pageindex}";
                        $images[$key] = $imagerow;
                    } else {
                        $displayed_codes[$acode] = $acode;
                        // avoid using another rows for different pages of the same activity
                        $images[$acode] = $imagerow;
                    }
                    $i++;
                } else {
                    $images[$acode]["activitycode"] .= ", " . $pageindex;
                }
            }
            // $acode!=null
        }
        echo '<input type="hidden" name="numActivities" value="' . $index . '" />';
        /**
         *  Add results with no $acode detected
         ***/
        foreach ($images_view as $result) {
            $scan = blended_getOMRScanJob($result->jobid);
            $acode = $result->activitycode;
            $resultname = $scan->scan_name . "-" . $result->id;
            $page = $result->page;
            if ($acode == null) {
                $imagerow = array();
                $imagerow["index"] = "";
                $correctionlink = "<a href=\"activitycode.php?&a={$blended->id}&jobid={$result->jobid}&resultid={$result->id}\">{$resultname}</a>";
                $imagerow["correctionlink"] = $correctionlink;
                $imagerow["activitycode"] = get_string('UnclassifiedPage', 'blended');
                $imagerow["alumno"] = '';
                $imagerow["pasar"] = '';
                $imagerow["status"] = get_string('NotYet', 'blended');
                if (has_capability('mod/blended:deletescanjob', $context)) {
                    $link = "<a href=\"delete_quiz.php?page={$currentpage}&acode={$acode}&jobid={$jobid}&a={$blended->id}\">{$imgdelete}</a>";
                    $delete = $link;
                    $imagerow["delete"] = $delete;
                }
                $images[] = $imagerow;
                $i++;
            }
        }
        //tabla de resultados
        $table = new stdClass();
        $table->class = 'mytable';
        $table->head = array('Seleccionar', 'Ver Resultados', 'ActivityCode', 'Alumno', 'Pasar a QUIZ', 'Evaluado en Moodle', 'Borrar');
        $align = "left";
        $table->align = array($align, $align, $align, $align, $align, $align, $align);
        $tablealign = "center";
        $table->tablealign = $tablealign;
        $table->rowclasses = array();
        $table->data = $images;
        print_table($table);
        echo '<center><input type="submit" name="manyActivities" value="' . get_string('blendedPassSelectedToQuiz', 'blended') . '"/></center>';
        echo "</form>";
    }
    return;
}