original_string: public static function get_courses_branch(\context $catcontext) {
  
          if ($catcontext->contextlevel !== CONTEXT_COURSECAT) {
              throw new \coding_exception('A course category context should be provided');
          }
  
          $coursecat = \core_course_category::get($catcontext->instanceid);
          $courses = $coursecat->get_courses();
  
          $branches = [];
  
          foreach ($courses as $course) {
  
              $coursecontext = \context_course::instance($course->id);
  
              $coursenode = [
                  'text' => shorten_text(format_string($course->shortname, true, ['context' => $coursecontext])),
                  'contextid' => $coursecontext->id,
                  'branches' => [
                      [
                          'text' => get_string('activitiesandresources', 'tool_dataprivacy'),
                          'expandcontextid' => $coursecontext->id,
                          'expandelement' => 'module',
                          'expanded' => 0,
                      ], [
                          'text' => get_string('blocks'),
                          'expandcontextid' => $coursecontext->id,
                          'expandelement' => 'block',
                          'expanded' => 0,
                      ],
                  ]
              ];
              $branches[] = self::complete($coursenode);
          }
  
          return $branches;
      }
code: public static function get_courses_branch(\context $catcontext) {
  
          if ($catcontext->contextlevel !== CONTEXT_COURSECAT) {
              throw new \coding_exception('A course category context should be provided');
          }
  
          $coursecat = \core_course_category::get($catcontext->instanceid);
          $courses = $coursecat->get_courses();
  
          $branches = [];
  
          foreach ($courses as $course) {
  
              $coursecontext = \context_course::instance($course->id);
  
              $coursenode = [
                  'text' => shorten_text(format_string($course->shortname, true, ['context' => $coursecontext])),
                  'contextid' => $coursecontext->id,
                  'branches' => [
                      [
                          'text' => get_string('activitiesandresources', 'tool_dataprivacy'),
                          'expandcontextid' => $coursecontext->id,
                          'expandelement' => 'module',
                          'expanded' => 0,
                      ], [
                          'text' => get_string('blocks'),
                          'expandcontextid' => $coursecontext->id,
                          'expandelement' => 'block',
                          'expanded' => 0,
                      ],
                  ]
              ];
              $branches[] = self::complete($coursenode);
          }
  
          return $branches;
      }
code_tokens: public static function get_courses_branch ( \ context $ catcontext ) { if ( $ catcontext -> contextlevel !== CONTEXT_COURSECAT ) { throw new \ coding_exception ( 'A course category context should be provided' ) ; } $ coursecat = \ core_course_category :: get ( $ catcontext -> instanceid ) ; $ courses = $ coursecat -> get_courses ( ) ; $ branches = [ ] ; foreach ( $ courses as $ course ) { $ coursecontext = \ context_course :: instance ( $ course -> id ) ; $ coursenode = [ 'text' => shorten_text ( format_string ( $ course -> shortname , true , [ 'context' => $ coursecontext ] ) ) , 'contextid' => $ coursecontext -> id , 'branches' => [ [ 'text' => get_string ( 'activitiesandresources' , 'tool_dataprivacy' ) , 'expandcontextid' => $ coursecontext -> id , 'expandelement' => 'module' , 'expanded' => 0 , ] , [ 'text' => get_string ( 'blocks' ) , 'expandcontextid' => $ coursecontext -> id , 'expandelement' => 'block' , 'expanded' => 0 , ] , ] ] ; $ branches [ ] = self :: complete ( $ coursenode ) ; } return $ branches ; }
docstring: Gets the courses branch for the provided category.
  
  @param \context $catcontext
  @return array
docstring_tokens: Gets the courses branch for the provided category .