Index: moodle/mod/lamslesson/lang/en/lamslesson.php =================================================================== diff -u -r82b05bec226a5e8a2e57f35727aefe8b8a3d2fad -rf33b561f38d98d71de239a1721f48dfc83bc738c --- moodle/mod/lamslesson/lang/en/lamslesson.php (.../lamslesson.php) (revision 82b05bec226a5e8a2e57f35727aefe8b8a3d2fad) +++ moodle/mod/lamslesson/lang/en/lamslesson.php (.../lamslesson.php) (revision f33b561f38d98d71de239a1721f48dfc83bc738c) @@ -86,5 +86,13 @@ $string['introduction'] = 'Introduction'; $string['openmonitor'] = 'Monitor this lesson'; $string['lastmodified'] = 'Last modified'; -$string['openlesson'] = 'Click here to open the lesson now'; +$string['openlesson'] = 'Open Lesson'; $string['empty'] = 'empty'; +$string['completionfinish'] = 'Show as complete when user finished the lesson'; +$string['yourprogress'] = 'Your Lesson Progress'; +$string['youhavecompleted'] = 'You have completed: '; +$string['outof'] = 'out of approximately'; +$string['lessonincompleted'] = 'Lesson is not yet completed'; +$string['lessoncompleted'] = 'You have completed this lesson'; +$string['activities'] = 'activities'; +$string['ymmv'] = 'Total activities depend on your learning path.'; \ No newline at end of file Index: moodle/mod/lamslesson/lib.php =================================================================== diff -u -r82b05bec226a5e8a2e57f35727aefe8b8a3d2fad -rf33b561f38d98d71de239a1721f48dfc83bc738c --- moodle/mod/lamslesson/lib.php (.../lib.php) (revision 82b05bec226a5e8a2e57f35727aefe8b8a3d2fad) +++ moodle/mod/lamslesson/lib.php (.../lib.php) (revision f33b561f38d98d71de239a1721f48dfc83bc738c) @@ -53,6 +53,8 @@ define('LAMSLESSON_PARAM_AUTHOR_METHOD', 'author'); define('LAMSLESSON_PARAM_MONITOR_METHOD', 'monitor'); define('LAMSLESSON_PARAM_LEARNER_METHOD', 'learner'); +define('LAMSLESSON_PARAM_SINGLE_PROGRESS_METHOD', 'singleStudentProgress'); +define('LAMSLESSON_PARAM_PROGRESS_METHOD', 'studentProgress'); define('LAMSLESSON_PARAM_CUSTOM_CSV', 'customCSV'); define('LAMSLESSON_LD_SERVICE', '/services/xml/LearningDesignRepository'); define('LAMSLESSON_LESSON_MANAGER', '/services/xml/LessonManager'); @@ -317,22 +319,19 @@ if (empty($array['@']['resourceId'])) { // it's a folder $folder_name = preg_replace("/'/", "$1\'", $array['@']['name']); - $output .= "{type:'Text', label:'" . $folder_name . "',id:'0'"; + $output .= "{type:'Text', label:'" . $folder_name . "',id:0"; if (empty($array['#']['LearningDesign']) && empty($array['#']['Folder'])) { - $output .= ", children: [{type:'HTML', html:'-" . get_string('empty', 'lamslesson') . "-', id:'0'}]}"; + $output .= ",expanded:0,children:[{type:'HTML',html:'-" . get_string('empty', 'lamslesson') . "-', id:0}]}"; return $output; } else { - $output .= ", children: ["; + $output .= ",children:["; } if (!empty($array['#']['LearningDesign'])) { $lds = $array['#']['LearningDesign']; for($i=0; $ilamslesson_serverid, $CFG->lamslesson_serverkey) || $CFG->lamslesson_serverid == "") { + print_error(get_string('notsetup', 'lamslesson')); + return NULL; + } + + $datetime = date("F d,Y g:i a"); + $datetime_encoded = urlencode($datetime); + + $plaintext = $datetime.$username.$CFG->lamslesson_serverid.$CFG->lamslesson_serverkey; + $hashvalue = sha1(strtolower($plaintext)); + + $request = "$CFG->lamslesson_serverurl" . LAMSLESSON_LESSON_MANAGER . "?method=" . LAMSLESSON_PARAM_SINGLE_PROGRESS_METHOD . "&serverId=" . $CFG->lamslesson_serverid . "&datetime=" . $datetime_encoded . "&hashValue=" . $hashvalue ."&lsId=" . $ldid . "&courseId=" . $courseid . "&progressUser=" . $username . "&username=" . $username; + + // GET call to LAMS + + $xml = file_get_contents($request); + + $xml_array = xmlize($xml); + + $response = $xml_array['LessonProgress']['#']; + $learnerProgress = $response['LearnerProgress']['0']; + + // print_r($learnerProgress['@']['activitiesCompleted']); + // die(); + + + return $learnerProgress['@']; +} + + +//returns the moodle completion state for a user) +function lamslesson_get_moodle_completion($course,$cm) { + + $completion = new completion_info($course); + return $completion->get_data($cm); + +} + +function lamslesson_set_as_completed($cm,$course,$lamslesson) { + // Update completion state + $completion = new completion_info($course); + if ($completion->is_enabled($cm) && $lamslesson->completionfinish) { + lamslesson_set_completion_state($cm,$completion,COMPLETION_COMPLETE); + } +} + +function lamslesson_set_as_incomplete($cm,$course,$lamslesson) { + // Update completion state + $completion = new completion_info($course); + if ($completion->is_enabled($cm) && $lamslesson->completionfinish) { + lamslesson_set_completion_state($cm,$completion,COMPLETION_INCOMPLETE); + } +} + +function lamslesson_set_completion_state($cm,$completion,$state) { + //Update completion state + + switch ($state) { + case COMPLETION_COMPLETE: + + $completion->update_state($cm, COMPLETION_COMPLETE); + break; + + default: + $completion->update_state($cm, COMPLETION_INCOMPLETE); + break; + } + + +} + + + Index: moodle/mod/lamslesson/mod_form.php =================================================================== diff -u -r82b05bec226a5e8a2e57f35727aefe8b8a3d2fad -rf33b561f38d98d71de239a1721f48dfc83bc738c --- moodle/mod/lamslesson/mod_form.php (.../mod_form.php) (revision 82b05bec226a5e8a2e57f35727aefe8b8a3d2fad) +++ moodle/mod/lamslesson/mod_form.php (.../mod_form.php) (revision f33b561f38d98d71de239a1721f48dfc83bc738c) @@ -146,13 +146,16 @@ tree = new YAHOO.widget.TreeView("treeDiv",[ $lds ]); +// expand only the first two nodes +tree.getNodeByIndex(1).expand(true); +tree.getNodeByIndex(2).expand(true); tree.render(); -tree.expandAll(); tree.subscribe('clickEvent',function(oArgs) { selectSequence(oArgs.node.data.id, oArgs.node.label); }); + XXX; @@ -181,4 +184,16 @@ } return $errors; } + + function add_completion_rules() { + $mform =& $this->_form; + + $mform->addElement('checkbox', 'completionfinish', '', get_string('completionfinish', 'lamslesson')); + return array('completionfinish'); + } + + function completion_rule_enabled($data) { + return !empty($data['completionfinish']); + } + } Index: moodle/mod/lamslesson/styles.css =================================================================== diff -u -r82b05bec226a5e8a2e57f35727aefe8b8a3d2fad -rf33b561f38d98d71de239a1721f48dfc83bc738c --- moodle/mod/lamslesson/styles.css (.../styles.css) (revision 82b05bec226a5e8a2e57f35727aefe8b8a3d2fad) +++ moodle/mod/lamslesson/styles.css (.../styles.css) (revision f33b561f38d98d71de239a1721f48dfc83bc738c) @@ -1 +1,6 @@ -.path-mod-lamslesson .smalltext {font-size: 0.75em;} +/** General Styles **/ +.path-mod-lamslesson .smalltext {text-align:right;font-size: 0.75em;} +.path-mod-lamslesson .centerlink {text-align:center;padding-top: 15px; padding-bottom:5px;} +.path-mod-lamslesson .progress-header {text-align:center;font-weight: bold;padding-top: 5px; padding-bottom:5px;} +.path-mod-lamslesson .super {position:relative;bottom:0.5em;color:red;font-size:0.8em;} + Index: moodle/mod/lamslesson/view.php =================================================================== diff -u -r82b05bec226a5e8a2e57f35727aefe8b8a3d2fad -rf33b561f38d98d71de239a1721f48dfc83bc738c --- moodle/mod/lamslesson/view.php (.../view.php) (revision 82b05bec226a5e8a2e57f35727aefe8b8a3d2fad) +++ moodle/mod/lamslesson/view.php (.../view.php) (revision f33b561f38d98d71de239a1721f48dfc83bc738c) @@ -27,8 +27,6 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 */ -/// (Replace lamslesson with the name of your module and remove this line) - require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); require_once(dirname(__FILE__).'/lib.php'); @@ -70,22 +68,14 @@ add_to_log($course->id, "lamslesson", "view lamslesson", "view.php?id=$cm->id", "$lamslesson->id", $cm->id); // Get raw data -//print("ID:" . $cm->instance); + //$lessons = $DB->get_records('lamslesson', 'id', $cm->instance); // Check capabilities $canparticipate = has_capability('mod/lamslesson:participate', $context); -if ($canparticipate) { - - if ($canmanage) { - - } - -} - // Output starts here echo $OUTPUT->header(); @@ -96,24 +86,71 @@ echo format_module_intro('lamslesson', $lamslesson, $cm->id); echo '

'; echo '
'; -echo '' . get_string('lastmodified', 'lamslesson') . ": " . userdate($lamslesson->timemodified) .''; +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 '

'; } 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->box_end(); -// echo html_writer::table($table); -//print_table($table); -// Finish the page + +// 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 '
' . get_string('yourprogress','lamslesson') . '
'; + 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 '
' . get_string('lessoncompleted','lamslesson') . ' ' . $OUTPUT->pix_icon('i/tick_green_big', get_string('lessoncompleted','lamslesson')) . '
'; + echo $OUTPUT->box_end(); +} + +/* +print($progress['activitiesCompleted']); +print($progress['activityCount']); +print($progress['attemptedActivities']); +print($progress['lessonComplete']); +*/ + echo $OUTPUT->footer(); + +/// Mark as viewed +// lamslesson_set_as_completed($cm, $course, $lamslesson); +