Index: moodle/mod/lamslesson/callback.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/callback.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/callback.php 14 Feb 2011 03:08:14 -0000 1.1 @@ -0,0 +1,47 @@ +libdir.'/datalib.php'); +include_once('lib.php'); +global $DB; + +if(!isset($CFG->lamslesson_serverid)||!isset($CFG->lamslesson_serverkey)) { + header('HTTP/1.1 401 Unauthenticated'); + exit(1); +} +$plaintext = trim($_GET['ts']).trim($_GET['un']).trim($CFG->lamslesson_serverid).trim($CFG->lamslesson_serverkey); +$hash = sha1(strtolower($plaintext)); + +if($hash!=$_GET['hs']){ + header('HTTP/1.1 401 Unauthenticated'); + exit(1); +} + +//OK, the caller is authenticated. Now let's fulfill its request. +// and make Moodle get the latest marks for this user in this lesson + +$lsid = $_GET['lsId']; +$user = $DB->get_record('user', array('username'=>$_GET['un'])); +if(!$user){ + header('HTTP/1.1 401 Unauthenticated'); + exit(1); +} + +$lamslesson = $DB->get_record('lamslesson', array('lesson_id' => $lsid), '*', MUST_EXIST); + +$gradebookmark = lamslesson_get_lams_outputs($user->username,$lamslesson,$user->username); + +?> \ No newline at end of file Index: moodle/mod/lamslesson/lib.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/lib.php,v diff -u -r1.5 -r1.6 --- moodle/mod/lamslesson/lib.php 31 Jan 2011 01:07:48 -0000 1.5 +++ moodle/mod/lamslesson/lib.php 14 Feb 2011 03:08:14 -0000 1.6 @@ -548,8 +548,8 @@ return file_get_contents($request); } -function lamslesson_get_outputs($username, $lang, $country, $lessonid, $courseid, $method,$foruser) { - global $CFG; +function lamslesson_get_lams_outputs($username,$lamslesson,$foruser) { + global $CFG, $DB; $datetime = date('F d,Y g:i a'); $plaintext = trim($datetime) @@ -559,28 +559,69 @@ $hash = sha1(strtolower($plaintext)); $request = $CFG->lamslesson_serverurl. LAMSLESSON_LESSON_MANAGER .'?serverId='.$CFG->lamslesson_serverid - .'&courseId='.$courseid + .'&courseId='.$lamslesson->course .'&username='.$username .'&datetime='.urlencode(strtolower($datetime)) .'&hashValue='.$hash - .'&lang='.$lang - .'&country='.$country - .'&method='.$method - .'&lsId='.$lessonid + .'&lang=en' + .'&country=AU' + .'&method='.LAMSLESSON_OUTPUT_METHOD + .'&lsId='.$lamslesson->lesson_id .'&outputsUser='.$foruser; // GET call to LAMS $xml = file_get_contents($request); - $xml_array = xmlize($xml); + $results = xmlize($xml); - return $xml_array; + // 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) { + + // Now calculate the percentage and then multiply it by the lamslesson grade. + $gradebookmark = ($userresult / $maxresult) * $lamslesson->grade; + + // Put this into gradebook + $user = $DB->get_record('user', array('username'=>$foruser)); + lamslesson_update_grades($lamslesson, $user->id, $gradebookmark); + return $gradebookmark; + + } + } - /** * Return URL to join a LAMS lesson as a learner or staff depending on method. * URL redirects LAMS to learner or monitor interface depending on method. Index: moodle/mod/lamslesson/view.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/view.php,v diff -u -r1.5 -r1.6 --- moodle/mod/lamslesson/view.php 9 Feb 2011 20:26:44 -0000 1.5 +++ moodle/mod/lamslesson/view.php 14 Feb 2011 03:08:14 -0000 1.6 @@ -111,6 +111,7 @@ echo $OUTPUT->box_end(); // Once we have progress info ready + $progress = lamslesson_get_student_progress($USER->username,$lamslesson->lesson_id, $course->id); // Progress details @@ -150,53 +151,12 @@ // 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); + $gradebookmark = lamslesson_get_lams_outputs($USER->username,$lamslesson,$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; + if (!empty($gradebookmark)) { echo ''; - - // Put this into gradebook - - lamslesson_update_grades($lamslesson, $USER->id, $gradebookmark); - } + } echo $OUTPUT->box_end();