original_string: public function paged_search(\stdClass $formdata, $pagenum) {
          $out = new \stdClass();
  
          if (self::is_search_area_categories_enabled() && !empty($formdata->cat)) {
              $cat = self::get_search_area_category_by_name($formdata->cat);
              if (empty($formdata->areaids)) {
                  $formdata->areaids = array_keys($cat->get_areas());
              } else {
                  foreach ($formdata->areaids as $key => $areaid) {
                      if (!key_exists($areaid, $cat->get_areas())) {
                          unset($formdata->areaids[$key]);
                      }
                  }
              }
          }
  
          $perpage = static::DISPLAY_RESULTS_PER_PAGE;
  
          // Make sure we only allow request up to max page.
          $pagenum = min($pagenum, (static::MAX_RESULTS / $perpage) - 1);
  
          // Calculate the first and last document number for the current page, 1 based.
          $mindoc = ($pagenum * $perpage) + 1;
          $maxdoc = ($pagenum + 1) * $perpage;
  
          // Get engine documents, up to max.
          $docs = $this->search($formdata, $maxdoc);
  
          $resultcount = count($docs);
          if ($resultcount < $maxdoc) {
              // This means it couldn't give us results to max, so the count must be the max.
              $out->totalcount = $resultcount;
          } else {
              // Get the possible count reported by engine, and limit to our max.
              $out->totalcount = $this->engine->get_query_total_count();
              $out->totalcount = min($out->totalcount, static::MAX_RESULTS);
          }
  
          // Determine the actual page.
          if ($resultcount < $mindoc) {
              // We couldn't get the min docs for this page, so determine what page we can get.
              $out->actualpage = floor(($resultcount - 1) / $perpage);
          } else {
              $out->actualpage = $pagenum;
          }
  
          // Split the results to only return the page.
          $out->results = array_slice($docs, $out->actualpage * $perpage, $perpage, true);
  
          return $out;
      }
code: public function paged_search(\stdClass $formdata, $pagenum) {
          $out = new \stdClass();
  
          if (self::is_search_area_categories_enabled() && !empty($formdata->cat)) {
              $cat = self::get_search_area_category_by_name($formdata->cat);
              if (empty($formdata->areaids)) {
                  $formdata->areaids = array_keys($cat->get_areas());
              } else {
                  foreach ($formdata->areaids as $key => $areaid) {
                      if (!key_exists($areaid, $cat->get_areas())) {
                          unset($formdata->areaids[$key]);
                      }
                  }
              }
          }
  
          $perpage = static::DISPLAY_RESULTS_PER_PAGE;
  
          // Make sure we only allow request up to max page.
          $pagenum = min($pagenum, (static::MAX_RESULTS / $perpage) - 1);
  
          // Calculate the first and last document number for the current page, 1 based.
          $mindoc = ($pagenum * $perpage) + 1;
          $maxdoc = ($pagenum + 1) * $perpage;
  
          // Get engine documents, up to max.
          $docs = $this->search($formdata, $maxdoc);
  
          $resultcount = count($docs);
          if ($resultcount < $maxdoc) {
              // This means it couldn't give us results to max, so the count must be the max.
              $out->totalcount = $resultcount;
          } else {
              // Get the possible count reported by engine, and limit to our max.
              $out->totalcount = $this->engine->get_query_total_count();
              $out->totalcount = min($out->totalcount, static::MAX_RESULTS);
          }
  
          // Determine the actual page.
          if ($resultcount < $mindoc) {
              // We couldn't get the min docs for this page, so determine what page we can get.
              $out->actualpage = floor(($resultcount - 1) / $perpage);
          } else {
              $out->actualpage = $pagenum;
          }
  
          // Split the results to only return the page.
          $out->results = array_slice($docs, $out->actualpage * $perpage, $perpage, true);
  
          return $out;
      }
code_tokens: public function paged_search ( \ stdClass $ formdata , $ pagenum ) { $ out = new \ stdClass ( ) ; if ( self :: is_search_area_categories_enabled ( ) && ! empty ( $ formdata -> cat ) ) { $ cat = self :: get_search_area_category_by_name ( $ formdata -> cat ) ; if ( empty ( $ formdata -> areaids ) ) { $ formdata -> areaids = array_keys ( $ cat -> get_areas ( ) ) ; } else { foreach ( $ formdata -> areaids as $ key => $ areaid ) { if ( ! key_exists ( $ areaid , $ cat -> get_areas ( ) ) ) { unset ( $ formdata -> areaids [ $ key ] ) ; } } } } $ perpage = static :: DISPLAY_RESULTS_PER_PAGE ; // Make sure we only allow request up to max page. $ pagenum = min ( $ pagenum , ( static :: MAX_RESULTS / $ perpage ) - 1 ) ; // Calculate the first and last document number for the current page, 1 based. $ mindoc = ( $ pagenum * $ perpage ) + 1 ; $ maxdoc = ( $ pagenum + 1 ) * $ perpage ; // Get engine documents, up to max. $ docs = $ this -> search ( $ formdata , $ maxdoc ) ; $ resultcount = count ( $ docs ) ; if ( $ resultcount < $ maxdoc ) { // This means it couldn't give us results to max, so the count must be the max. $ out -> totalcount = $ resultcount ; } else { // Get the possible count reported by engine, and limit to our max. $ out -> totalcount = $ this -> engine -> get_query_total_count ( ) ; $ out -> totalcount = min ( $ out -> totalcount , static :: MAX_RESULTS ) ; } // Determine the actual page. if ( $ resultcount < $ mindoc ) { // We couldn't get the min docs for this page, so determine what page we can get. $ out -> actualpage = floor ( ( $ resultcount - 1 ) / $ perpage ) ; } else { $ out -> actualpage = $ pagenum ; } // Split the results to only return the page. $ out -> results = array_slice ( $ docs , $ out -> actualpage * $ perpage , $ perpage , true ) ; return $ out ; }
docstring: Returns requested page of documents plus additional information for paging.
  
  This function does not perform any kind of security checking for access, the caller code
  should check that the current user have moodle/search:query capability.
  
  If a page is requested that is beyond the last result, the last valid page is returned in
  results, and actualpage indicates which page was returned.
  
  @param stdClass $formdata
  @param int $pagenum The 0 based page number.
  @return object An object with 3 properties:
  results    => An array of \core_search\documents for the actual page.
  totalcount => Number of records that are possibly available, to base paging on.
  actualpage => The actual page returned.
docstring_tokens: Returns requested page of documents plus additional information for paging .