original_string: public static function get_lessons_by_courses($courseids = array()) {
          global $PAGE;
  
          $warnings = array();
          $returnedlessons = array();
  
          $params = array(
              'courseids' => $courseids,
          );
          $params = self::validate_parameters(self::get_lessons_by_courses_parameters(), $params);
  
          $mycourses = array();
          if (empty($params['courseids'])) {
              $mycourses = enrol_get_my_courses();
              $params['courseids'] = array_keys($mycourses);
          }
  
          // Ensure there are courseids to loop through.
          if (!empty($params['courseids'])) {
  
              list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
  
              // Get the lessons in this course, this function checks users visibility permissions.
              // We can avoid then additional validate_context calls.
              $lessons = get_all_instances_in_courses("lesson", $courses);
              foreach ($lessons as $lessonrecord) {
                  $context = context_module::instance($lessonrecord->coursemodule);
  
                  // Remove fields added by get_all_instances_in_courses.
                  unset($lessonrecord->coursemodule, $lessonrecord->section, $lessonrecord->visible, $lessonrecord->groupmode,
                      $lessonrecord->groupingid);
  
                  $lessonrecord = self::get_lesson_summary_for_exporter($lessonrecord);
  
                  $exporter = new lesson_summary_exporter($lessonrecord, array('context' => $context));
                  $returnedlessons[] = $exporter->export($PAGE->get_renderer('core'));
              }
          }
          $result = array();
          $result['lessons'] = $returnedlessons;
          $result['warnings'] = $warnings;
          return $result;
      }
code: public static function get_lessons_by_courses($courseids = array()) {
          global $PAGE;
  
          $warnings = array();
          $returnedlessons = array();
  
          $params = array(
              'courseids' => $courseids,
          );
          $params = self::validate_parameters(self::get_lessons_by_courses_parameters(), $params);
  
          $mycourses = array();
          if (empty($params['courseids'])) {
              $mycourses = enrol_get_my_courses();
              $params['courseids'] = array_keys($mycourses);
          }
  
          // Ensure there are courseids to loop through.
          if (!empty($params['courseids'])) {
  
              list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
  
              // Get the lessons in this course, this function checks users visibility permissions.
              // We can avoid then additional validate_context calls.
              $lessons = get_all_instances_in_courses("lesson", $courses);
              foreach ($lessons as $lessonrecord) {
                  $context = context_module::instance($lessonrecord->coursemodule);
  
                  // Remove fields added by get_all_instances_in_courses.
                  unset($lessonrecord->coursemodule, $lessonrecord->section, $lessonrecord->visible, $lessonrecord->groupmode,
                      $lessonrecord->groupingid);
  
                  $lessonrecord = self::get_lesson_summary_for_exporter($lessonrecord);
  
                  $exporter = new lesson_summary_exporter($lessonrecord, array('context' => $context));
                  $returnedlessons[] = $exporter->export($PAGE->get_renderer('core'));
              }
          }
          $result = array();
          $result['lessons'] = $returnedlessons;
          $result['warnings'] = $warnings;
          return $result;
      }
code_tokens: public static function get_lessons_by_courses ( $ courseids = array ( ) ) { global $ PAGE ; $ warnings = array ( ) ; $ returnedlessons = array ( ) ; $ params = array ( 'courseids' => $ courseids , ) ; $ params = self :: validate_parameters ( self :: get_lessons_by_courses_parameters ( ) , $ params ) ; $ mycourses = array ( ) ; if ( empty ( $ params [ 'courseids' ] ) ) { $ mycourses = enrol_get_my_courses ( ) ; $ params [ 'courseids' ] = array_keys ( $ mycourses ) ; } // Ensure there are courseids to loop through. if ( ! empty ( $ params [ 'courseids' ] ) ) { list ( $ courses , $ warnings ) = external_util :: validate_courses ( $ params [ 'courseids' ] , $ mycourses ) ; // Get the lessons in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $ lessons = get_all_instances_in_courses ( "lesson" , $ courses ) ; foreach ( $ lessons as $ lessonrecord ) { $ context = context_module :: instance ( $ lessonrecord -> coursemodule ) ; // Remove fields added by get_all_instances_in_courses. unset ( $ lessonrecord -> coursemodule , $ lessonrecord -> section , $ lessonrecord -> visible , $ lessonrecord -> groupmode , $ lessonrecord -> groupingid ) ; $ lessonrecord = self :: get_lesson_summary_for_exporter ( $ lessonrecord ) ; $ exporter = new lesson_summary_exporter ( $ lessonrecord , array ( 'context' => $ context ) ) ; $ returnedlessons [ ] = $ exporter -> export ( $ PAGE -> get_renderer ( 'core' ) ) ; } } $ result = array ( ) ; $ result [ 'lessons' ] = $ returnedlessons ; $ result [ 'warnings' ] = $ warnings ; return $ result ; }
docstring: Returns a list of lessons in a provided list of courses,
  if no list is provided all lessons that the user can view will be returned.
  
  @param array $courseids Array of course ids
  @return array of lessons details
  @since Moodle 3.3
docstring_tokens: Returns a list of lessons in a provided list of courses if no list is provided all lessons that the user can view will be returned .