original_string: public static function get_policy_version($versionid, $behalfid = null) {
          global $PAGE;
  
          $result = [];
          $warnings = [];
          $params = external_api::validate_parameters(self::get_policy_version_parameters(), [
              'versionid' => $versionid,
              'behalfid' => $behalfid
          ]);
          $versionid = $params['versionid'];
          $behalfid = $params['behalfid'];
  
          $context = context_system::instance();
          $PAGE->set_context($context);
  
          try {
              // Validate if the user has access to the policy version.
              $version = api::get_policy_version($versionid);
              if (!api::can_user_view_policy_version($version, $behalfid)) {
                  $warnings[] = [
                      'item' => $versionid,
                      'warningcode' => 'errorusercantviewpolicyversion',
                      'message' => get_string('errorusercantviewpolicyversion', 'tool_policy')
                  ];
              } else if (!empty($version)) {
                  $version = api::get_policy_version($versionid);
                  $policy['name'] = $version->name;
                  $policy['versionid'] = $versionid;
                  list($policy['content'], $notusedformat) = external_format_text(
                      $version->content,
                      $version->contentformat,
                      SYSCONTEXTID,
                      'tool_policy',
                      'policydocumentcontent',
                      $version->id
                  );
                  $result['policy'] = $policy;
              }
          } catch (moodle_exception $e) {
              $warnings[] = [
                  'item' => $versionid,
                  'warningcode' => 'errorpolicyversionnotfound',
                  'message' => get_string('errorpolicyversionnotfound', 'tool_policy')
              ];
          }
  
          return [
              'result' => $result,
              'warnings' => $warnings
          ];
      }
code: public static function get_policy_version($versionid, $behalfid = null) {
          global $PAGE;
  
          $result = [];
          $warnings = [];
          $params = external_api::validate_parameters(self::get_policy_version_parameters(), [
              'versionid' => $versionid,
              'behalfid' => $behalfid
          ]);
          $versionid = $params['versionid'];
          $behalfid = $params['behalfid'];
  
          $context = context_system::instance();
          $PAGE->set_context($context);
  
          try {
              // Validate if the user has access to the policy version.
              $version = api::get_policy_version($versionid);
              if (!api::can_user_view_policy_version($version, $behalfid)) {
                  $warnings[] = [
                      'item' => $versionid,
                      'warningcode' => 'errorusercantviewpolicyversion',
                      'message' => get_string('errorusercantviewpolicyversion', 'tool_policy')
                  ];
              } else if (!empty($version)) {
                  $version = api::get_policy_version($versionid);
                  $policy['name'] = $version->name;
                  $policy['versionid'] = $versionid;
                  list($policy['content'], $notusedformat) = external_format_text(
                      $version->content,
                      $version->contentformat,
                      SYSCONTEXTID,
                      'tool_policy',
                      'policydocumentcontent',
                      $version->id
                  );
                  $result['policy'] = $policy;
              }
          } catch (moodle_exception $e) {
              $warnings[] = [
                  'item' => $versionid,
                  'warningcode' => 'errorpolicyversionnotfound',
                  'message' => get_string('errorpolicyversionnotfound', 'tool_policy')
              ];
          }
  
          return [
              'result' => $result,
              'warnings' => $warnings
          ];
      }
code_tokens: public static function get_policy_version ( $ versionid , $ behalfid = null ) { global $ PAGE ; $ result = [ ] ; $ warnings = [ ] ; $ params = external_api :: validate_parameters ( self :: get_policy_version_parameters ( ) , [ 'versionid' => $ versionid , 'behalfid' => $ behalfid ] ) ; $ versionid = $ params [ 'versionid' ] ; $ behalfid = $ params [ 'behalfid' ] ; $ context = context_system :: instance ( ) ; $ PAGE -> set_context ( $ context ) ; try { // Validate if the user has access to the policy version. $ version = api :: get_policy_version ( $ versionid ) ; if ( ! api :: can_user_view_policy_version ( $ version , $ behalfid ) ) { $ warnings [ ] = [ 'item' => $ versionid , 'warningcode' => 'errorusercantviewpolicyversion' , 'message' => get_string ( 'errorusercantviewpolicyversion' , 'tool_policy' ) ] ; } else if ( ! empty ( $ version ) ) { $ version = api :: get_policy_version ( $ versionid ) ; $ policy [ 'name' ] = $ version -> name ; $ policy [ 'versionid' ] = $ versionid ; list ( $ policy [ 'content' ] , $ notusedformat ) = external_format_text ( $ version -> content , $ version -> contentformat , SYSCONTEXTID , 'tool_policy' , 'policydocumentcontent' , $ version -> id ) ; $ result [ 'policy' ] = $ policy ; } } catch ( moodle_exception $ e ) { $ warnings [ ] = [ 'item' => $ versionid , 'warningcode' => 'errorpolicyversionnotfound' , 'message' => get_string ( 'errorpolicyversionnotfound' , 'tool_policy' ) ] ; } return [ 'result' => $ result , 'warnings' => $ warnings ] ; }
docstring: Fetch the details of a policy version.
  
  @param int $versionid The policy version ID.
  @param int $behalfid The id of user on whose behalf the user is viewing the policy.
  @return array
  @throws coding_exception
  @throws dml_exception
  @throws invalid_parameter_exception
  @throws restricted_context_exception
  @throws moodle_exception
docstring_tokens: Fetch the details of a policy version .