.
/**
* Prints a particular instance of lamslesson
*
* You can have a rather longer description of the file as well,
* if you like, and it can span multiple lines.
*
* @package mod_lamslesson
* @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org)
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
*/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
$n = optional_param('n', 0, PARAM_INT); // lamslesson instance ID - it should be named as the first character of the module
if ($id) {
$cm = get_coursemodule_from_id('lamslesson', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$lamslesson = $DB->get_record('lamslesson', array('id' => $cm->instance), '*', MUST_EXIST);
} elseif ($n) {
$lamslesson = $DB->get_record('lamslesson', array('id' => $n), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $lamslesson->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('lamslesson', $lamslesson->id, $course->id, false, MUST_EXIST);
} else {
print_error('You must specify a course_module ID or an instance ID');
}
require_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$locale = lamslesson_get_locale($course->id);
add_to_log($course->id, 'lamslesson', 'view', "view.php?id=$cm->id", $lamslesson->name, $cm->id);
/// Print the page header
$PAGE->set_url('/mod/lamslesson/view.php', array('id' => $cm->id));
$PAGE->set_title($lamslesson->name);
$PAGE->set_heading($course->shortname);
$PAGE->set_button(update_module_button($cm->id, $course->id, get_string('modulename', 'lamslesson')));
// Main page
$options_html = '';
$canmanage = has_capability('mod/lamslesson:manage', $context);
// Log the lamslesson view.
add_to_log($course->id, "lamslesson", "view lamslesson", "view.php?id=$cm->id", "$lamslesson->id", $cm->id);
// Get raw data
//$lessons = $DB->get_records('lamslesson', 'id', $cm->instance);
// Check capabilities
$canparticipate = has_capability('mod/lamslesson:participate', $context);
// Output starts here
echo $OUTPUT->header();
// Main LAMS region
echo $OUTPUT->heading($lamslesson->name);
echo $OUTPUT->box_start('generalbox', 'instructions');
echo '
';
echo format_module_intro('lamslesson', $lamslesson, $cm->id);
echo '
';
echo '
';
echo '' . get_string('lastmodified', 'lamslesson') . ": " . userdate($lamslesson->timemodified) .'
';
echo $OUTPUT->box_end();
echo $OUTPUT->box_start('generalbox', 'intro');
if ($canparticipate) {
$learnerurl = lamslesson_get_url($USER->username, $locale['lang'], $locale['country'], $lamslesson->lesson_id, $course->id, $course->fullname, $course->timecreated, LAMSLESSON_PARAM_LEARNER_METHOD);
echo '';
echo ' ';
echo $OUTPUT->action_link($learnerurl, get_string('openlesson', 'lamslesson'), new popup_action('click', $learnerurl, '', array('height' => 600, 'width' => 996)));
echo '';
echo '
';
}
if ($canmanage) {
$monitorurl = lamslesson_get_url($USER->username, $locale['lang'], $locale['country'], $lamslesson->lesson_id, $course->id, $course->fullname, $course->timecreated, LAMSLESSON_PARAM_MONITOR_METHOD);
echo '';
echo ' ';
echo $OUTPUT->action_link($monitorurl, get_string('openmonitor', 'lamslesson'), new popup_action('click', $monitorurl, '', array('height' => 600, 'width' => 996)));
echo '';
echo '
';
}
echo $OUTPUT->box_end();
// Once we have progress info ready
$progress = lamslesson_get_student_progress($USER->username,$lamslesson->lesson_id, $course->id);
// Progress details
// If the user has attempted at least 1 activity, then we present the
// progress information
if ($progress['attemptedActivities'] > 0 && $canparticipate && $progress['lessonComplete'] == 0) {
echo $OUTPUT->box_start('generalbox', 'intro');
echo '';
echo '';
echo get_string('lessonincompleted','lamslesson') . ' ';
echo '
';
echo '';
echo get_string('youhavecompleted','lamslesson') . ' ' . $progress['activitiesCompleted'] . ' ' .get_string('outof','lamslesson'). ' ' .$progress['activityCount'] . ' ' . get_string('activities','lamslesson') . '[*]';
echo '
';
echo '* ' . get_string('ymmv','lamslesson') . '
';
echo $OUTPUT->box_end();
}
// If lesson is completed
if ($progress['lessonComplete'] == 'true') {
echo $OUTPUT->box_start('generalbox', 'intro');
$moodle_completion = lamslesson_get_moodle_completion($course,$cm);
// First let's update the moodle completion accordingly
// if in Moodle it shows that it hasn't been completed.
if ($moodle_completion->completionstate == 0){
lamslesson_set_as_completed($cm,$course,$lamslesson);
}
echo '';
// Does this lesson has to record a score in Moodle?
if ($lamslesson->grade != 0) {
// Now let's get the score from LAMS and add it into gradebook
// Getting result from LAMS
$results = lamslesson_get_outputs($USER->username,'en','AU',$lamslesson->lesson_id,$cm->course,LAMSLESSON_OUTPUT_METHOD,$USER->username);
// Get the outputs from the activities
$learneroutputs = $results['ToolOutputs']['#']['LearnerOutput'];
$activityoutputs = $learneroutputs['0']['#']['Activity'];
$maxresult = 0;
$userresult = 0;
// Calculate max and user results (if they exist)
foreach ($activityoutputs as $k => $v){
// If activities don't have or produce any output then we just ignore them
if (!empty($v['#'])) {
foreach ($v['#']['ToolOutput'] as $k2 => $v2) {
$activityoutputname = $v2['@']['name'];
// The only numeric outputs we get from LAMS are for the MCQ and Assessment activities
// learner.total.score = Assessment
// learner.mark = MCQ
if ($activityoutputname == 'learner.mark' || $activityoutputname == 'learner.total.score') {
$actname = $v2['@']['name'];
$actmaxresult = $v2['@']['marksPossible'];
$actuserresult = $v2['@']['output'];
$userresult += $actuserresult;
$maxresult += $actmaxresult;
}
}
}
}
// If there's outputs from LAMS, then we process them and add them to the gradebook
if (!$maxresult == 0) {
//print("Max total result: " . $maxresult . "
User total result: " . $userresult . " " . $lamslesson->grade);
// Now calculate the percentage and then multiply it by the lamslesson grade.
$gradebookmark = ($userresult / $maxresult) * $lamslesson->grade;
echo '' . get_string('yourmarkis', 'lamslesson') . ' ' . round($gradebookmark, 2) . ' ' . get_string('outofmark', 'lamslesson') . ' ' . $lamslesson->grade . '.
';
// Put this into gradebook
lamslesson_update_grades($lamslesson, $USER->id, $gradebookmark);
}
}
echo $OUTPUT->box_end();
}
echo $OUTPUT->footer();