Index: temp_moodle_dev/moodle/blocks/lamstwo_status/block_lamstwo_status.php
===================================================================
RCS file: /usr/local/cvsroot/temp_moodle_dev/moodle/blocks/lamstwo_status/block_lamstwo_status.php,v
diff -u -r1.2 -r1.3
--- temp_moodle_dev/moodle/blocks/lamstwo_status/block_lamstwo_status.php 13 Jul 2009 00:21:33 -0000 1.2
+++ temp_moodle_dev/moodle/blocks/lamstwo_status/block_lamstwo_status.php 14 Jul 2009 01:49:43 -0000 1.3
@@ -14,9 +14,12 @@
const STATUS_COMPLETED = 'status_completed';
const STATUS_UNKNOWN = 'status_unknown';
+ // when there is a problem contacting lams server, set true
+ public static $error = false;
+
function init() {
$this->title = get_string('block_title', 'lamstwo');
- $this->version = 2009070800;
+ $this->version = 2009071400;
}
function get_content() {
@@ -26,19 +29,23 @@
$this->content = new stdClass;
$this->content->text = $this->print_all_lesson_status();
- $this->content->footer = '';
+ $this->content->footer = ' ';
return $this->content;
}
function print_all_lesson_status() {
- $return_str = '
';
+ $return_str = '';
$array = $this->get_all_lesson_status();
- foreach ($array as $lamstwo_id => $status_obj_array) {
- $return_str .= ''.$status_obj_array[0]->lamstwo_name.' |
';
- foreach ($status_obj_array as $status_obj) {
- $status_str = get_string($status_obj->status_i18n_key, 'lamstwo');
- $return_str .= ''.$status_obj->lesson_name.' | '.$status_str.' |
';
+ if (self::$error) {
+ $return_str .= ''.get_string($array, 'lamstwo').' |
';
+ } else {
+ foreach ($array as $lamstwo_id => $status_obj_array) {
+ $return_str .= ''.$status_obj_array[0]->lamstwo_name.' |
';
+ foreach ($status_obj_array as $status_obj) {
+ $status_str = get_string($status_obj->status_i18n_key, 'lamstwo');
+ $return_str .= ''.$status_obj->lesson_name.' | '.$status_str.' |
';
+ }
}
}
$return_str .= '
';
@@ -51,7 +58,7 @@
// get course module ids
$cms = get_records_sql("SELECT cm.* FROM {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
- WHERE cm.module=m.id AND m.name='lamstwo' AND cm.course={$COURSE->id}");
+ WHERE cm.module=m.id AND m.name='lamstwo' AND cm.course={$COURSE->id} AND cm.visible=1 ORDER BY cm.section");
foreach ($cms as $cmid => $cm) {
$context = get_context_instance(CONTEXT_MODULE, $cmid);
@@ -63,12 +70,18 @@
// get status for all lessons
foreach ($lessons as $obj) {
$xml_array = $this->get_single_lesson_status($USER->username, $COURSE->id, $obj->lesson_id);
- $status_obj = new stdClass();
- $status_obj->lamstwo_name = $obj->lamstwo_name;
- $status_obj->lesson_id = $obj->lesson_id;
- $status_obj->lesson_name = $obj->lesson_name;
- $status_obj->status_i18n_key = $this->process_xml($xml_array);
- $status_array[$obj->lamstwo_id][] = $status_obj;
+ if (is_array($xml_array)) {
+ $status_obj = new stdClass();
+ $status_obj->lamstwo_name = $obj->lamstwo_name;
+ $status_obj->lesson_id = $obj->lesson_id;
+ $status_obj->lesson_name = $obj->lesson_name;
+ $status_obj->status_i18n_key = $this->process_xml($xml_array);
+ $status_array[$obj->lamstwo_id][] = $status_obj;
+ } else {
+ // error contacting lams server, $xml_array is an error string
+ self::$error = true;
+ return $xml_array;
+ }
}
}
}
@@ -96,7 +109,7 @@
$request = "$CFG->lamstwo_serverurl$service?serverId=$CFG->lamstwo_serverid&datetime=$datetime_encoded&hashValue=$hashvalue&method=singleStudentProgress&username=$username&courseId=$courseid&lsId=$lsId&progressUser=$username";
// GET call to LAMS
- $xml = file_get_contents($request);
+ $xml = @file_get_contents($request);
if(!empty($http_response_header[0])) {
// Retrieve HTTP status code
@@ -107,16 +120,22 @@
case 200:
break;
case 503:
+ return 'restcall503';
break;
case 403:
+ return 'restcall403';
break;
case 400:
+ return 'restcall400';
break;
+ case 500:
+ return 'restcall500';
+ break;
default:
+ return 'restcalldefault';
}
} else {
- //return get_string('restcallfail', 'lamstwo');
- //print_error('restcallfail', 'lamstwo', $CFG->wwwroot.'/course/view.php?id='.$courseid);
+ return 'restcallfail';
}
$xml_array = xmlize($xml);
Index: temp_moodle_dev/moodle/lang/en_utf8/lamstwo.php
===================================================================
RCS file: /usr/local/cvsroot/temp_moodle_dev/moodle/lang/en_utf8/Attic/lamstwo.php,v
diff -u -r1.5 -r1.6
--- temp_moodle_dev/moodle/lang/en_utf8/lamstwo.php 9 Jul 2009 08:11:17 -0000 1.5
+++ temp_moodle_dev/moodle/lang/en_utf8/lamstwo.php 14 Jul 2009 01:49:43 -0000 1.6
@@ -76,13 +76,14 @@
$string['restcall503'] = 'Call to LAMS failed: received an HTTP status of 503. This might mean that LAMS is unavailable. Please wait a minute and try again, or contact your system administrator.';
$string['restcall403'] = 'Call to LAMS failed: received an HTTP status of 403 Forbidden. Please check the configurations settings and/or contact your system administrator.';
$string['restcall400'] = 'Call to LAMS failed: received an HTTP status of 400 Bad Request. Please check the configurations settings and/or contact your system administrator.';
+$string['restcall500'] = 'Call to LAMS failed: received an HTTP status of 500 Internal Error. Please check the configurations settings and/or contact your system administrator.';
$string['restcalldefault'] = 'Call to LAMS failed: received an HTTP status of: $a';
$string['restcallfail'] = 'Call to LAMS failed: received no response or connection was refused. Please check that you have the correct LAMS server URL and that it is online.';
$string['parsingerror'] = 'There has been an error parsing the rest response. Please contact your system administrator.';
$string['deletelesson'] = 'Delete this lesson';
$string['deletelessonconfirm'] = 'Are you sure you want to delete this lesson?';
$string['deletesuccess'] = 'Lesson successfully deleted.';
-$string['block_title'] = 'LAMSv2 Lesson Status';
+$string['block_title'] = 'Lesson Status (LAMS)';
$string['status_started'] = 'Started';
$string['status_not_started'] = 'Not started';
$string['status_completed'] = 'Completed';