diff --git a/core/modules/history/history.module b/core/modules/history/history.module index 38dd8ab..faa2dae 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -41,6 +41,47 @@ function history_read($nid) { } /** + * Retrieves the timestamp for the current user's last view of a nodes. + * + * @param array $nids + * A node ID. + * + * @return int + * If a node has been previously viewed by the user, the timestamp in seconds + * of when the last view occurred; otherwise, zero. + */ +function history_read_multiple($nids) { + $history = &drupal_static('history_read', array()); + + $return = array(); + + $nodes_to_read = array(); + foreach ($nids as $nid) { + if (isset($history[$nid])) { + $return[$nid] = $history[$nid]; + } + else { + $nodes_to_read[$nid] = 0; + } + } + + if (empty($nodes_to_read)) { + return $return; + } + + $result = db_query('SELECT timestamp FROM {history} WHERE uid = :uid AND nid IN(:nids)', array( + ':uid' => \Drupal::currentUser()->id(), + ':nids' => array_keys($nodes_to_read), + )); + foreach ($result as $row) { + $nodes_to_read[$row->nid] = $row->timestamp; + } + $history += $nodes_to_read; + + return $return + $nodes_to_read; +} + +/** * Updates 'last viewed' timestamp of the specified entity for the current user. * * @param $nid