original_string: public static function get_books_by_courses($courseids = array()) {
          global $CFG;
  
          $returnedbooks = array();
          $warnings = array();
  
          $params = self::validate_parameters(self::get_books_by_courses_parameters(), array('courseids' => $courseids));
  
          $courses = array();
          if (empty($params['courseids'])) {
              $courses = enrol_get_my_courses();
              $params['courseids'] = array_keys($courses);
          }
  
          // Ensure there are courseids to loop through.
          if (!empty($params['courseids'])) {
  
              list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
  
              // Get the books in this course, this function checks users visibility permissions.
              // We can avoid then additional validate_context calls.
              $books = get_all_instances_in_courses("book", $courses);
              foreach ($books as $book) {
                  $context = context_module::instance($book->coursemodule);
                  // Entry to return.
                  $bookdetails = array();
                  // First, we return information that any user can see in the web interface.
                  $bookdetails['id'] = $book->id;
                  $bookdetails['coursemodule']      = $book->coursemodule;
                  $bookdetails['course']            = $book->course;
                  $bookdetails['name']              = external_format_string($book->name, $context->id);
                  // Format intro.
                  list($bookdetails['intro'], $bookdetails['introformat']) =
                      external_format_text($book->intro, $book->introformat, $context->id, 'mod_book', 'intro', null);
                  $bookdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_book', 'intro', false, false);
                  $bookdetails['numbering']         = $book->numbering;
                  $bookdetails['navstyle']          = $book->navstyle;
                  $bookdetails['customtitles']      = $book->customtitles;
  
                  if (has_capability('moodle/course:manageactivities', $context)) {
                      $bookdetails['revision']      = $book->revision;
                      $bookdetails['timecreated']   = $book->timecreated;
                      $bookdetails['timemodified']  = $book->timemodified;
                      $bookdetails['section']       = $book->section;
                      $bookdetails['visible']       = $book->visible;
                      $bookdetails['groupmode']     = $book->groupmode;
                      $bookdetails['groupingid']    = $book->groupingid;
                  }
                  $returnedbooks[] = $bookdetails;
              }
          }
          $result = array();
          $result['books'] = $returnedbooks;
          $result['warnings'] = $warnings;
          return $result;
      }
code: public static function get_books_by_courses($courseids = array()) {
          global $CFG;
  
          $returnedbooks = array();
          $warnings = array();
  
          $params = self::validate_parameters(self::get_books_by_courses_parameters(), array('courseids' => $courseids));
  
          $courses = array();
          if (empty($params['courseids'])) {
              $courses = enrol_get_my_courses();
              $params['courseids'] = array_keys($courses);
          }
  
          // Ensure there are courseids to loop through.
          if (!empty($params['courseids'])) {
  
              list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
  
              // Get the books in this course, this function checks users visibility permissions.
              // We can avoid then additional validate_context calls.
              $books = get_all_instances_in_courses("book", $courses);
              foreach ($books as $book) {
                  $context = context_module::instance($book->coursemodule);
                  // Entry to return.
                  $bookdetails = array();
                  // First, we return information that any user can see in the web interface.
                  $bookdetails['id'] = $book->id;
                  $bookdetails['coursemodule']      = $book->coursemodule;
                  $bookdetails['course']            = $book->course;
                  $bookdetails['name']              = external_format_string($book->name, $context->id);
                  // Format intro.
                  list($bookdetails['intro'], $bookdetails['introformat']) =
                      external_format_text($book->intro, $book->introformat, $context->id, 'mod_book', 'intro', null);
                  $bookdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_book', 'intro', false, false);
                  $bookdetails['numbering']         = $book->numbering;
                  $bookdetails['navstyle']          = $book->navstyle;
                  $bookdetails['customtitles']      = $book->customtitles;
  
                  if (has_capability('moodle/course:manageactivities', $context)) {
                      $bookdetails['revision']      = $book->revision;
                      $bookdetails['timecreated']   = $book->timecreated;
                      $bookdetails['timemodified']  = $book->timemodified;
                      $bookdetails['section']       = $book->section;
                      $bookdetails['visible']       = $book->visible;
                      $bookdetails['groupmode']     = $book->groupmode;
                      $bookdetails['groupingid']    = $book->groupingid;
                  }
                  $returnedbooks[] = $bookdetails;
              }
          }
          $result = array();
          $result['books'] = $returnedbooks;
          $result['warnings'] = $warnings;
          return $result;
      }
code_tokens: public static function get_books_by_courses ( $ courseids = array ( ) ) { global $ CFG ; $ returnedbooks = array ( ) ; $ warnings = array ( ) ; $ params = self :: validate_parameters ( self :: get_books_by_courses_parameters ( ) , array ( 'courseids' => $ courseids ) ) ; $ courses = array ( ) ; if ( empty ( $ params [ 'courseids' ] ) ) { $ courses = enrol_get_my_courses ( ) ; $ params [ 'courseids' ] = array_keys ( $ courses ) ; } // Ensure there are courseids to loop through. if ( ! empty ( $ params [ 'courseids' ] ) ) { list ( $ courses , $ warnings ) = external_util :: validate_courses ( $ params [ 'courseids' ] , $ courses ) ; // Get the books in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $ books = get_all_instances_in_courses ( "book" , $ courses ) ; foreach ( $ books as $ book ) { $ context = context_module :: instance ( $ book -> coursemodule ) ; // Entry to return. $ bookdetails = array ( ) ; // First, we return information that any user can see in the web interface. $ bookdetails [ 'id' ] = $ book -> id ; $ bookdetails [ 'coursemodule' ] = $ book -> coursemodule ; $ bookdetails [ 'course' ] = $ book -> course ; $ bookdetails [ 'name' ] = external_format_string ( $ book -> name , $ context -> id ) ; // Format intro. list ( $ bookdetails [ 'intro' ] , $ bookdetails [ 'introformat' ] ) = external_format_text ( $ book -> intro , $ book -> introformat , $ context -> id , 'mod_book' , 'intro' , null ) ; $ bookdetails [ 'introfiles' ] = external_util :: get_area_files ( $ context -> id , 'mod_book' , 'intro' , false , false ) ; $ bookdetails [ 'numbering' ] = $ book -> numbering ; $ bookdetails [ 'navstyle' ] = $ book -> navstyle ; $ bookdetails [ 'customtitles' ] = $ book -> customtitles ; if ( has_capability ( 'moodle/course:manageactivities' , $ context ) ) { $ bookdetails [ 'revision' ] = $ book -> revision ; $ bookdetails [ 'timecreated' ] = $ book -> timecreated ; $ bookdetails [ 'timemodified' ] = $ book -> timemodified ; $ bookdetails [ 'section' ] = $ book -> section ; $ bookdetails [ 'visible' ] = $ book -> visible ; $ bookdetails [ 'groupmode' ] = $ book -> groupmode ; $ bookdetails [ 'groupingid' ] = $ book -> groupingid ; } $ returnedbooks [ ] = $ bookdetails ; } } $ result = array ( ) ; $ result [ 'books' ] = $ returnedbooks ; $ result [ 'warnings' ] = $ warnings ; return $ result ; }
docstring: Returns a list of books in a provided list of courses,
  if no list is provided all books that the user can view will be returned.
  
  @param array $courseids the course ids
  @return array of books details
  @since Moodle 3.0
docstring_tokens: Returns a list of books in a provided list of courses if no list is provided all books that the user can view will be returned .