original_string: public static function get_discussion_posts(int $discussionid, ?string $sortby, ?string $sortdirection) {
          global $USER;
          // Validate the parameter.
          $params = self::validate_parameters(self::get_discussion_posts_parameters(), [
                  'discussionid' => $discussionid,
                  'sortby' => $sortby,
                  'sortdirection' => $sortdirection,
              ]);
          $warnings = [];
  
          $vaultfactory = mod_forum\local\container::get_vault_factory();
  
          $discussionvault = $vaultfactory->get_discussion_vault();
          $discussion = $discussionvault->get_from_id($params['discussionid']);
  
          $forumvault = $vaultfactory->get_forum_vault();
          $forum = $forumvault->get_from_id($discussion->get_forum_id());
  
          $sortby = $params['sortby'];
          $sortdirection = $params['sortdirection'];
          $sortallowedvalues = ['id', 'created', 'modified'];
          $directionallowedvalues = ['ASC', 'DESC'];
  
          if (!in_array(strtolower($sortby), $sortallowedvalues)) {
              throw new invalid_parameter_exception('Invalid value for sortby parameter (value: ' . $sortby . '),' .
                  'allowed values are: ' . implode(', ', $sortallowedvalues));
          }
  
          $sortdirection = strtoupper($sortdirection);
          if (!in_array($sortdirection, $directionallowedvalues)) {
              throw new invalid_parameter_exception('Invalid value for sortdirection parameter (value: ' . $sortdirection . '),' .
                  'allowed values are: ' . implode(',', $directionallowedvalues));
          }
  
          $managerfactory = mod_forum\local\container::get_manager_factory();
          $capabilitymanager = $managerfactory->get_capability_manager($forum);
  
          $postvault = $vaultfactory->get_post_vault();
          $posts = $postvault->get_from_discussion_id(
                  $USER,
                  $discussion->get_id(),
                  $capabilitymanager->can_view_any_private_reply($USER),
                  "{$sortby} {$sortdirection}"
              );
  
          $builderfactory = mod_forum\local\container::get_builder_factory();
          $postbuilder = $builderfactory->get_exported_posts_builder();
  
          $legacydatamapper = mod_forum\local\container::get_legacy_data_mapper_factory();
  
          return [
              'posts' => $postbuilder->build($USER, [$forum], [$discussion], $posts),
              'ratinginfo' => \core_rating\external\util::get_rating_info(
                  $legacydatamapper->get_forum_data_mapper()->to_legacy_object($forum),
                  $forum->get_context(),
                  'mod_forum',
                  'post',
                  $legacydatamapper->get_post_data_mapper()->to_legacy_objects($posts)
              ),
              'warnings' => $warnings,
          ];
      }
code: public static function get_discussion_posts(int $discussionid, ?string $sortby, ?string $sortdirection) {
          global $USER;
          // Validate the parameter.
          $params = self::validate_parameters(self::get_discussion_posts_parameters(), [
                  'discussionid' => $discussionid,
                  'sortby' => $sortby,
                  'sortdirection' => $sortdirection,
              ]);
          $warnings = [];
  
          $vaultfactory = mod_forum\local\container::get_vault_factory();
  
          $discussionvault = $vaultfactory->get_discussion_vault();
          $discussion = $discussionvault->get_from_id($params['discussionid']);
  
          $forumvault = $vaultfactory->get_forum_vault();
          $forum = $forumvault->get_from_id($discussion->get_forum_id());
  
          $sortby = $params['sortby'];
          $sortdirection = $params['sortdirection'];
          $sortallowedvalues = ['id', 'created', 'modified'];
          $directionallowedvalues = ['ASC', 'DESC'];
  
          if (!in_array(strtolower($sortby), $sortallowedvalues)) {
              throw new invalid_parameter_exception('Invalid value for sortby parameter (value: ' . $sortby . '),' .
                  'allowed values are: ' . implode(', ', $sortallowedvalues));
          }
  
          $sortdirection = strtoupper($sortdirection);
          if (!in_array($sortdirection, $directionallowedvalues)) {
              throw new invalid_parameter_exception('Invalid value for sortdirection parameter (value: ' . $sortdirection . '),' .
                  'allowed values are: ' . implode(',', $directionallowedvalues));
          }
  
          $managerfactory = mod_forum\local\container::get_manager_factory();
          $capabilitymanager = $managerfactory->get_capability_manager($forum);
  
          $postvault = $vaultfactory->get_post_vault();
          $posts = $postvault->get_from_discussion_id(
                  $USER,
                  $discussion->get_id(),
                  $capabilitymanager->can_view_any_private_reply($USER),
                  "{$sortby} {$sortdirection}"
              );
  
          $builderfactory = mod_forum\local\container::get_builder_factory();
          $postbuilder = $builderfactory->get_exported_posts_builder();
  
          $legacydatamapper = mod_forum\local\container::get_legacy_data_mapper_factory();
  
          return [
              'posts' => $postbuilder->build($USER, [$forum], [$discussion], $posts),
              'ratinginfo' => \core_rating\external\util::get_rating_info(
                  $legacydatamapper->get_forum_data_mapper()->to_legacy_object($forum),
                  $forum->get_context(),
                  'mod_forum',
                  'post',
                  $legacydatamapper->get_post_data_mapper()->to_legacy_objects($posts)
              ),
              'warnings' => $warnings,
          ];
      }
code_tokens: public static function get_discussion_posts ( int $ discussionid , ? string $ sortby , ? string $ sortdirection ) { global $ USER ; // Validate the parameter. $ params = self :: validate_parameters ( self :: get_discussion_posts_parameters ( ) , [ 'discussionid' => $ discussionid , 'sortby' => $ sortby , 'sortdirection' => $ sortdirection , ] ) ; $ warnings = [ ] ; $ vaultfactory = mod_forum \ local \ container :: get_vault_factory ( ) ; $ discussionvault = $ vaultfactory -> get_discussion_vault ( ) ; $ discussion = $ discussionvault -> get_from_id ( $ params [ 'discussionid' ] ) ; $ forumvault = $ vaultfactory -> get_forum_vault ( ) ; $ forum = $ forumvault -> get_from_id ( $ discussion -> get_forum_id ( ) ) ; $ sortby = $ params [ 'sortby' ] ; $ sortdirection = $ params [ 'sortdirection' ] ; $ sortallowedvalues = [ 'id' , 'created' , 'modified' ] ; $ directionallowedvalues = [ 'ASC' , 'DESC' ] ; if ( ! in_array ( strtolower ( $ sortby ) , $ sortallowedvalues ) ) { throw new invalid_parameter_exception ( 'Invalid value for sortby parameter (value: ' . $ sortby . '),' . 'allowed values are: ' . implode ( ', ' , $ sortallowedvalues ) ) ; } $ sortdirection = strtoupper ( $ sortdirection ) ; if ( ! in_array ( $ sortdirection , $ directionallowedvalues ) ) { throw new invalid_parameter_exception ( 'Invalid value for sortdirection parameter (value: ' . $ sortdirection . '),' . 'allowed values are: ' . implode ( ',' , $ directionallowedvalues ) ) ; } $ managerfactory = mod_forum \ local \ container :: get_manager_factory ( ) ; $ capabilitymanager = $ managerfactory -> get_capability_manager ( $ forum ) ; $ postvault = $ vaultfactory -> get_post_vault ( ) ; $ posts = $ postvault -> get_from_discussion_id ( $ USER , $ discussion -> get_id ( ) , $ capabilitymanager -> can_view_any_private_reply ( $ USER ) , "{$sortby} {$sortdirection}" ) ; $ builderfactory = mod_forum \ local \ container :: get_builder_factory ( ) ; $ postbuilder = $ builderfactory -> get_exported_posts_builder ( ) ; $ legacydatamapper = mod_forum \ local \ container :: get_legacy_data_mapper_factory ( ) ; return [ 'posts' => $ postbuilder -> build ( $ USER , [ $ forum ] , [ $ discussion ] , $ posts ) , 'ratinginfo' => \ core_rating \ external \ util :: get_rating_info ( $ legacydatamapper -> get_forum_data_mapper ( ) -> to_legacy_object ( $ forum ) , $ forum -> get_context ( ) , 'mod_forum' , 'post' , $ legacydatamapper -> get_post_data_mapper ( ) -> to_legacy_objects ( $ posts ) ) , 'warnings' => $ warnings , ] ; }
docstring: Get the forum posts in the specified discussion.
  
  @param   int $discussionid
  @param   string $sortby
  @param   string $sortdirection
  @return  array
docstring_tokens: Get the forum posts in the specified discussion .