public function PhotosStatisticsUpdateController::recordView in Album Photos 8.5
Same name and namespace in other branches
- 6.0.x src/Controller/PhotosStatisticsUpdateController.php \Drupal\photos\Controller\PhotosStatisticsUpdateController::recordView()
Record the image view to the database.
Parameters
int $id: The photos_image entity id.
Return value
int The current visit count for this image.
1 call to PhotosStatisticsUpdateController::recordView()
- PhotosStatisticsUpdateController::updateCount in src/
Controller/ PhotosStatisticsUpdateController.php - Ajax callback to record photos_image visit.
File
- src/
Controller/ PhotosStatisticsUpdateController.php, line 73
Class
- PhotosStatisticsUpdateController
- Class PhotosStatisticsUpdateController.
Namespace
Drupal\photos\ControllerCode
public function recordView($id) {
// @todo use core stats instead (when ready).
$count = 1;
try {
$this->connection
->merge('photos_count')
->keys([
'cid' => $id,
'type' => 'image_views',
])
->fields([
'value' => $count,
'changed' => \Drupal::time()
->getRequestTime(),
])
->expression('value', 'value + :count', [
':count' => $count,
])
->execute();
$count = $this->connection
->select('photos_count', 'c')
->fields('c', [
'value',
])
->condition('c.cid', $id)
->condition('c.type', 'image_views')
->execute()
->fetchField();
return $count;
} catch (\Exception $e) {
\Drupal::logger('photos')
->notice('Image view statistics failed.');
watchdog_exception('photos', $e);
return $count;
}
}