original_string: public static function get_policies_with_acceptances($userid) {
          // Get the list of policies and versions that current user is able to see
          // and the respective acceptance records for the selected user.
          $policies = static::list_policies();
          $acceptances = static::get_user_acceptances($userid);
          $ret = [];
          foreach ($policies as $policy) {
              $versions = [];
              if ($policy->currentversion && $policy->currentversion->audience != policy_version::AUDIENCE_GUESTS) {
                  if (isset($acceptances[$policy->currentversion->id])) {
                      $policy->currentversion->acceptance = $acceptances[$policy->currentversion->id];
                  } else {
                      $policy->currentversion->acceptance = null;
                  }
                  $versions[] = $policy->currentversion;
              }
              foreach ($policy->archivedversions as $version) {
                  if ($version->audience != policy_version::AUDIENCE_GUESTS
                          && static::can_user_view_policy_version($version, $userid)) {
                      $version->acceptance = isset($acceptances[$version->id]) ? $acceptances[$version->id] : null;
                      $versions[] = $version;
                  }
              }
              if ($versions) {
                  $ret[] = (object)['id' => $policy->id, 'versions' => $versions];
              }
          }
  
          return $ret;
      }
code: public static function get_policies_with_acceptances($userid) {
          // Get the list of policies and versions that current user is able to see
          // and the respective acceptance records for the selected user.
          $policies = static::list_policies();
          $acceptances = static::get_user_acceptances($userid);
          $ret = [];
          foreach ($policies as $policy) {
              $versions = [];
              if ($policy->currentversion && $policy->currentversion->audience != policy_version::AUDIENCE_GUESTS) {
                  if (isset($acceptances[$policy->currentversion->id])) {
                      $policy->currentversion->acceptance = $acceptances[$policy->currentversion->id];
                  } else {
                      $policy->currentversion->acceptance = null;
                  }
                  $versions[] = $policy->currentversion;
              }
              foreach ($policy->archivedversions as $version) {
                  if ($version->audience != policy_version::AUDIENCE_GUESTS
                          && static::can_user_view_policy_version($version, $userid)) {
                      $version->acceptance = isset($acceptances[$version->id]) ? $acceptances[$version->id] : null;
                      $versions[] = $version;
                  }
              }
              if ($versions) {
                  $ret[] = (object)['id' => $policy->id, 'versions' => $versions];
              }
          }
  
          return $ret;
      }
code_tokens: public static function get_policies_with_acceptances ( $ userid ) { // Get the list of policies and versions that current user is able to see // and the respective acceptance records for the selected user. $ policies = static :: list_policies ( ) ; $ acceptances = static :: get_user_acceptances ( $ userid ) ; $ ret = [ ] ; foreach ( $ policies as $ policy ) { $ versions = [ ] ; if ( $ policy -> currentversion && $ policy -> currentversion -> audience != policy_version :: AUDIENCE_GUESTS ) { if ( isset ( $ acceptances [ $ policy -> currentversion -> id ] ) ) { $ policy -> currentversion -> acceptance = $ acceptances [ $ policy -> currentversion -> id ] ; } else { $ policy -> currentversion -> acceptance = null ; } $ versions [ ] = $ policy -> currentversion ; } foreach ( $ policy -> archivedversions as $ version ) { if ( $ version -> audience != policy_version :: AUDIENCE_GUESTS && static :: can_user_view_policy_version ( $ version , $ userid ) ) { $ version -> acceptance = isset ( $ acceptances [ $ version -> id ] ) ? $ acceptances [ $ version -> id ] : null ; $ versions [ ] = $ version ; } } if ( $ versions ) { $ ret [ ] = ( object ) [ 'id' => $ policy -> id , 'versions' => $ versions ] ; } } return $ ret ; }
docstring: Get the list of policies and versions that current user is able to see and the respective acceptance records for
  the selected user.
  
  @param int $userid
  @return array array with the same structure that list_policies() returns with additional attribute acceptance for versions
docstring_tokens: Get the list of policies and versions that current user is able to see and the respective acceptance records for the selected user .