1 installer.browser.inc installer_browser_fetch_results($filters)

Fetches results from the server based on the parameters passed in.

$filters should be an associative array with the following keys:

  • version: The Major Version of Backdrop that is running on the Client.
  • text: The text that was entered as the search query, or '' if none.
  • type: The type of project being searched.
  • page: The zero-based page number.
  • items_per_page: How many results are requested per page.

For example:

array(
  'version' => '1',
  'text' => 'views',
  'type' => 'module',
  'page' => 3,
  'items_per_page' => 12,
)

The installer_browser_fetch_results($filters) call returns an array with the following keys:

  • total: The total number of results found for the filters.
  • projects: An array of projects returned for this page request keyed by machine name. Each project array may contain the following key-value pairs:

    • type: The type of project this is. Can be 'module' or 'theme'.
    • title: The title of the project.
    • name: The machine name of the project.
    • author: The author's name.
    • description: The project description.
    • image: Absolute url to the image, if any.
    • usage: Number of reported active installs.
    • project url: Absolute url to the project page, if any.
    • project status url: The absolute url of the update checker.
    • last updated: UNIX Timestamp of when the project was last updated.
    • maintenance status: The project maintenance status.
    • development status: The project development status.
    • rating: A rating on a scale of 1 to 10 of the project, if available.
    • dependencies: An array of the dependencies of this module.

The following is an example of a valid return array:

<?php
   array(
     'total' = 5,
     'projects' => array(
       'views' => array(
         'type' => 'module',
         'title' => 'Views',
         'name' => 'views',
         'author' => 'merlinofchaos',
         'description' => 'Long project description',
         'image' => 'http://www.example.com/image.jpg',
         'usage' => '542312',
         'project url' => 'https://www.example.org/projects/views',
         'project status url' => 'https://updates.example.org/release-history/views/1.x',
         'last updated' => '12342523',
         'maintenance status' => 'Actively maintained',
         'development status' => 'Under active development',
         'rating' => '9.6',
         'dependencies' => array(
           'entity',
         ),
       ),
       'another_project => array(
         'type' => 'module',
         ...
       ),
     ),
   );
   ?>

Parameters

array $filters: An associative array of queries to use to filter results.

Return value

Returns an array of results.:

File

core/modules/installer/installer.browser.inc, line 237
Various functions that are required by the Installer browse pages.

Code

function installer_browser_fetch_results($filters) {
  $server = installer_browser_get_server();
  // Attempt to retrieve the cached version of this page.
  $cid = 'installer:results:' . md5(serialize(array_merge($filters, $server)));
  if ($cache = cache_get($cid)) {
    return $cache->data;
  }

  $local_filters = $filters;
  $local_filters['method'] = 'query';

  $query_url = $server['url'] . '/query/' . $local_filters['type'] . '/1?' . http_build_query($local_filters, FALSE, '&');
  $response = backdrop_http_request($query_url);

  if ($response->code == '200') {
    $results = backdrop_json_decode($response->data);
  }
  else {
    backdrop_set_message(t("Encountered an error when trying to fetch results from @name. Error @code : @message", 
    array('@name' => $server['name'], '@code' => $response->code, '@message' => $response->error)));
    return array();
  }

  // Set the cached version of the results.
  cache_set($cid, $results, 'cache', strtotime("+24 hours"));

  return $results;
}