function recently_read_entity_view in Recently Read 7.3
Same name and namespace in other branches
- 8 recently_read.module \recently_read_entity_view()
Implements hook_entity_view().
File
- ./
recently_read.module, line 37 - Recently read module file. Displays a history of recently read entities.
Code
function recently_read_entity_view($entity, $type, $view_mode, $langcode) {
$config =& drupal_static(__FUNCTION__);
if (!isset($config)) {
$config = variable_get('rr_config', array());
}
//If the entity is not config for recently read track...
if (!isset($config[$type])) {
return;
}
if (isset($config[$type]) && !$config[$type]['enable']) {
return;
}
//If the currently view mode is not support recently read track...
if (!in_array($view_mode, array_filter($config[$type]['view_mode']))) {
return;
}
list($entity_id, $vid, $bundle) = entity_extract_ids($type, $entity);
//Write the record to DB.
//TODO::implements hook_cron to clean up the outdated data from the DB.
if (session_api_get_sid() && $entity_id) {
db_merge('recently_read')
->key(array(
'sid' => session_api_get_sid(),
'entity_id' => $entity_id,
'type' => $type,
))
->fields(array(
'type' => $type,
'language' => $langcode,
'timestamp' => REQUEST_TIME,
))
->execute();
}
}