Hi,
I am trying to retrieve the list of sections that are under a course.
I am using the following code to retrieve it but it gives an error message "Invalid Response Value Detected".
I am trying to return a list of sections with each section having
- id
- course
- section
- summary
- name
- summaryformat
- visible
- sequence
Code
returns method
public static function get_course_sections_returns(){
return new external_multiple_structure(
new external_single_structure(
array(
'id'=> new external_value(PARAM_INT,'course section id'),
'course_id'=> new external_value(PARAM_INT,'course id'),
'section'=> new external_value(PARAM_INT,'section order'),
'summary'=> new external_value(PARAM_TEXT,'section summary'),
'name' => new external_value(PARAM_TEXT,'section name'),
'summaryformat' => new external_value(PARAM_INT, 'section summary format'),
'visible'=> new external_value(PARAM_INT, 'section visible'),
'sequence'=> new external_value(PARAM_TEXT, 'section sequence')
)));
}
parameter method
public static function get_course_sections_parameters(){
return new external_function_parameters(
array('course_id'=> new external_value(PARAM_INT, 'course id', VALUE_REQUIRED))
);
}
// retrieves a list of sections of a course
actual method that has the logic
public static function get_course_sections($course_id){
global $CFG, $DB;
$params = self::validate_parameters( self::get_course_sections_parameters(), array('course_id'=>$course_id) );
$list_of_course_sections_record = $DB->get_records('course_sections', array('course'=> intval($course_id)) );
$current_section = array();
$list_of_course_sections = array();
foreach( $list_of_course_sections_record as $course_section){
$current_section["id"] = intval($course_section->id);
$current_section["course_id"] = intval($course_section->course);
$current_section["section"] = intval($course_section->section);
$current_section["summary"] = $course_section->summary;
$current_section["name"] = $course_section->name;
$current_section["summaryformat"] = intval($course_section->summaryformat);
$current_section["visible"] = intval($course_section->visible);
$current_section["sequence"] = $course_section->sequence;
if( $current_section["id"] > 0 ){
array_push( $list_of_course_sections, $current_section );
}
$current_section = array();
}
return $list_of_course_sections;
}
I really appreciate your help with this.
Thanks.