You are here

function callback_mostpopular_refresh_viewed in Drupal Most Popular 7

Implements the 'refresh_$delta' callback.

Parameters

object $service : The service definition.

object $block : The block definition.

integer $span : The number of seconds over which to search.

integer $last_run : The timestamp of the last time this service was run.

Return value

boolean|array If there was a failure, this function should return FALSE. Otherwise, return an array of mostpopular_item objects with the following keys:

  • entity_type: the type of entity, if applicable.
  • entity_id: the ID of the entity, if applicable.
  • title: the title of the entity.
  • url: the external URL of the entity.
  • path: the internal Drupal path of the entity.
  • count: the number of times the entity was referenced.
1 string reference to 'callback_mostpopular_refresh_viewed'
hook_mostpopular_service_info in ./mostpopular.api.inc
Defines one or more Most Popular services provided by this module.

File

./mostpopular.api.inc, line 90
Provides examples of the hooks and callbacks that can be implemented to add new services to the Most Popular framework.

Code

function callback_mostpopular_refresh_viewed($service, $block, $span, $last_run) {
  $ts = time() - $span;
  $limit = $block->count;

  // Get a set of URLs and counts
  try {
    $data = mymodule_get_data($ts);
  } catch (Exception $ex) {

    // Ther was an
    return FALSE;
  }
  $out = array();
  if (!empty($data)) {
    foreach ($data as $v) {
      $count = $v['shares'];
      $url = $v['url'];

      // Match the URL to an existing entity
      $obj = mostpopular_match_result_nodes($url, $count, $service->data);
      if (isset($obj)) {
        $out[] = $obj;
      }

      // Return only the first N results
      if (count($out) >= $limit) {
        break;
      }
    }
  }
  return $out;
}