Skip to content
Snippets Groups Projects

Issue #3381654: Service method to get all flags for a user

Open Issue #3381654: Service method to get all flags for a user
All threads resolved!
All threads resolved!
Files
3
+ 26
15
@@ -267,6 +267,31 @@ class FlagService implements FlagServiceInterface {
->loadMultiple($user_ids);
}
/**
* {@inheritdoc}
*/
public function getAllFlaggingByUser(?AccountInterface $account = NULL, $flag = NULL, $session_id = NULL): array {
$query = $this->entityTypeManager->getStorage('flagging')->getQuery();
$query->accessCheck();
$query->condition('uid', $account->id());
if (!empty($flag)) {
$query->condition('flag_id', $flag->id());
}
if ($account->isAnonymous()) {
if (empty($session_id)) {
throw new \LogicException('An anonymous user must be identified by session ID.');
}
$query->condition('session_id', $session_id);
}
$ids = $query->execute();
return $this->getFlaggingsByIds($ids);
}
/**
* {@inheritdoc}
*/
@@ -371,21 +396,7 @@ class FlagService implements FlagServiceInterface {
* {@inheritdoc}
*/
public function unflagAllByUser(AccountInterface $account, $session_id = NULL) {
$query = $this->entityTypeManager->getStorage('flagging')->getQuery();
$query->accessCheck();
$query->condition('uid', $account->id());
if ($account->isAnonymous()) {
if (empty($session_id)) {
throw new \LogicException('An anonymous user must be identified by session ID.');
}
$query->condition('session_id', $session_id);
}
$ids = $query->execute();
$flaggings = $this->getFlaggingsByIds($ids);
$flaggings = $this->getAllFlaggingByUser($account, NULL, $session_id);
$this->entityTypeManager->getStorage('flagging')->delete($flaggings);
}
Loading