Invalid Response Value detected

Invalid Response Value detected

by john felix -
Number of replies: 2

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.

Average of ratings: -
In reply to john felix

Re: Invalid Response Value detected

by Jérôme Mouneyrac -

Hi John,

In Moodle 2.2+ turn on debug >= NORMAL in Moodle. The error will display a debug info telling you exactly which returned value is wrong.

cheers,
Jerome 

In reply to john felix

Re: Invalid Response Value detected

by Ayesha Nasim -

Hey John, Did you have any luck fixing the issue, if yes then can you please tell me howd you do it, 
I am having the same issue.

your help would be very much appreciated

Kind Reagrds