public static function PhotosAlbum::setCount in Album Photos 8.4
Same name and namespace in other branches
- 8.5 src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::setCount()
- 6.0.x src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::setCount()
Calculate number of $type.
8 calls to PhotosAlbum::setCount()
- PhotosAlbum::resetCount in src/
PhotosAlbum.php - Update count.
- PhotosImage::delete in src/
PhotosImage.php - Delete image.
- PhotosImageEditForm::submitForm in src/
Form/ PhotosImageEditForm.php - Form submission handler.
- PhotosUpload::finishedMovingImageFiles in src/
PhotosUpload.php - Finished batch operation moving image files.
- PhotosUpload::saveImage in src/
PhotosUpload.php - Image written to database.
File
- src/
PhotosAlbum.php, line 567
Class
- PhotosAlbum
- Create an album object.
Namespace
Drupal\photosCode
public static function setCount($type, $id = 0) {
$db = \Drupal::database();
$requestTime = \Drupal::time()
->getRequestTime();
switch ($type) {
case 'user_image':
$count = $db
->query('SELECT count(p.fid) FROM {photos_image} p INNER JOIN {file_managed} f ON p.fid = f.fid WHERE f.uid = :id', [
':id' => $id,
])
->fetchField();
$query = $db
->update('photos_count');
$query
->fields([
'value' => $count,
'changed' => $requestTime,
]);
$query
->condition('cid', $id);
$query
->condition('type', $type);
$affected_rows = $query
->execute();
if (!$affected_rows) {
$db
->insert('photos_count')
->fields([
'cid' => $id,
'changed' => $requestTime,
'type' => $type,
'value' => $count,
])
->execute();
}
// Clear cache tags.
Cache::invalidateTags([
'photos:image:user:' . $id,
]);
break;
case 'user_album':
$count = $db
->query('SELECT count(p.pid) FROM {photos_album} p INNER JOIN {node_field_data} n ON p.pid = n.nid WHERE n.uid = :uid', [
':uid' => $id,
])
->fetchField();
$query = $db
->update('photos_count')
->fields([
'value' => $count,
'changed' => $requestTime,
])
->condition('cid', $id)
->condition('type', $type);
$affected_rows = $query
->execute();
if (!$affected_rows) {
$db
->insert('photos_count')
->fields([
'cid' => $id,
'changed' => $requestTime,
'type' => $type,
'value' => $count,
])
->execute();
}
// Clear cache tags.
Cache::invalidateTags([
'photos:album:user:' . $id,
]);
break;
case 'site_album':
$count = $db
->query('SELECT COUNT(pid) FROM {photos_album}')
->fetchField();
$query = $db
->update('photos_count')
->fields([
'value' => $count,
'changed' => $requestTime,
])
->condition('cid', 0)
->condition('type', $type);
$affected_rows = $query
->execute();
if (!$affected_rows) {
$db
->insert('photos_count')
->fields([
'cid' => 0,
'changed' => $requestTime,
'type' => $type,
'value' => $count,
])
->execute();
}
break;
case 'site_image':
$count = $db
->query('SELECT COUNT(fid) FROM {photos_image}')
->fetchField();
$query = $db
->update('photos_count')
->fields([
'value' => $count,
'changed' => $requestTime,
])
->condition('cid', 0)
->condition('type', $type);
$affected_rows = $query
->execute();
if (!$affected_rows) {
$db
->insert('photos_count')
->fields([
'cid' => 0,
'changed' => $requestTime,
'type' => $type,
'value' => $count,
])
->execute();
}
// Clear cache tags.
Cache::invalidateTags([
'photos:image:recent',
]);
break;
case 'node_node':
$count = $db
->query('SELECT COUNT(nid) FROM {photos_node} WHERE nid = :nid', [
':nid' => $id,
])
->fetchField();
$query = $db
->update('photos_count')
->fields([
'value' => $count,
'changed' => $requestTime,
])
->condition('cid', $id)
->condition('type', $type);
$affected_rows = $query
->execute();
if (!$affected_rows) {
$db
->insert('photos_count')
->fields([
'cid' => $id,
'changed' => $requestTime,
'type' => $type,
'value' => $count,
])
->execute();
}
break;
case 'node_album':
$count = $db
->query("SELECT COUNT(fid) FROM {photos_image} WHERE pid = :pid", [
':pid' => $id,
])
->fetchField();
$db
->update('photos_album')
->fields([
'count' => $count,
])
->condition('pid', $id)
->execute();
break;
}
}