Unsubscribe a user from a forum.

@param \Claroline\ForumBundle\Entity\Forum $forum
@param \Claroline\CoreBundle\Entity\User $user
321395
public function unsubscribe(Forum $forum, User $user)
    {
        $this->om->startFlushSuite();
        $notification = $this->notificationRepo->findOneBy(array('forum' => $forum, 'user' => $user));
        $this->om->remove($notification);
        $this->dispatch(new UnsubscribeForumEvent($forum));
        $this->om->endFlushSuite();
    }
1175567
public function remove(UserInterface $user): bool
    {
        try {
            $this->storage->delete(User::TABLE, $user->getId()->toString());
        } catch (Exception $e) {
            throw $e;
        }
        return true;
    }
826337
public function remove(User $user) : bool
    {
        if (!$user->delete()) {
            throw new \RuntimeException($this->i18n->t('setrun/user', 'Removing error'));
        }
        return true;
    }
342999
public function deleteUser($user)
    {

        $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' .
               'WHERE (user_pk = :id)';
        $query = $this->db->prepare($sql);
        $query->bindValue('id', $user->getRecordId(), PDO::PARAM_INT);
        $ok = $query->execute();

        if ($ok) {
            $user->initialize();
        }

        return $ok;

    }
1245226
public function deleteUser(User $user)
    {

        /* When the api will identify a user, please uncomment this
        if ($this->container->get('security.token_storage')->getToken()->getUser()->getId() === $user->getId()) {
            throw new \Exception('A user cannot delete himself');
        }*/
        $userRole = $this->roleManager->getUserRoleByUser($user);

        //soft delete~
        $user->setMail('mail#' . $user->getId());
        $user->setFirstName('firstname#' . $user->getId());
        $user->setLastName('lastname#' . $user->getId());
        $user->setPlainPassword(uniqid());
        $user->setUsername('username#' . $user->getId());
        $user->setPublicUrl('removed#' . $user->getId());
        $user->setAdministrativeCode('code#' . $user->getId());
        $user->setIsEnabled(false);

        // keeping the user's workspace with its original code
        // would prevent creating a user with the same username
        // todo: workspace deletion should be an option
        $ws = $user->getPersonalWorkspace();

        if ($ws) {
            $ws->setCode($ws->getCode() . '#deleted_user#' . $user->getId());
            $ws->setDisplayable(false);
            $this->objectManager->persist($ws);
        }

        if ($userRole) {
            $this->objectManager->remove($userRole);
        }
        $this->objectManager->persist($user);
        $this->objectManager->flush();

        $this->strictEventDispatcher->dispatch('claroline_users_delete', 'GenericDatas', array(array($user)));
        $this->strictEventDispatcher->dispatch('log', 'Log\LogUserDelete', array($user));
        $this->strictEventDispatcher->dispatch('delete_user', 'DeleteUser', array($user));
    }
387975
public function subscribe(Forum $forum, User $user, $selfActivation = true)
    {
        $this->om->startFlushSuite();
        $notification = new Notification();
        $notification->setUser($user);
        $notification->setForum($forum);
        $notification->setSelfActivation($selfActivation);
        $this->om->persist($notification);
        $this->dispatch(new SubscribeForumEvent($forum));
        $this->om->endFlushSuite();
    }
1304246
public function delete(UserStructure $user)
    {
        $event = new Event\Delete();
        $event->setUser($user);
        $this->getEventManager()->trigger($event);
        return $event->getResult();  
    }
249054
private function cleanUserSessions(User $user)
    {
        $sessions = $this->objectManager->getRepository('Phraseanet:Session')
            ->findByUser(['user' => $user]);

        foreach ($sessions as $session) {
            $this->objectManager->remove($session);
        }
    }
632727
protected function get_post_author($userid, $course, $forum, $cm, $context) {
        if (!isset($this->users[$userid])) {
            // This user no longer exists.
            return false;
        }

        $user = $this->users[$userid];

        if (!isset($user->groups)) {
            // Initialise the groups list.
            $user->groups = [];
        }

        if (!isset($user->groups[$forum->id])) {
            $user->groups[$forum->id] = groups_get_all_groups($course->id, $user->id, $cm->groupingid);
        }

        // Clone the user object to prevent leaks between messages.
        return (object) (array) $user;
    }
285220
public function disableGlobalNotificationsAction(Forum $forum)
    {
        $collection = new ResourceCollection(array($forum->getResourceNode()));

        if (!$this->authorization->isGranted('MODERATE', $collection)) {
            throw new AccessDeniedException($collection->getErrorsForDisplay());
        }

        $this->manager->disableGlobalNotifications($forum);

        return new RedirectResponse(
            $this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
        );
    }
351065
public function removeUser( core_kernel_classes_Resource $user)
    {
        $returnValue = (bool) false;

        $returnValue = $user->delete();

        return (bool) $returnValue;
    }
1065815
public function delete($user, Thread $thread)
    {
        return Gate::allows('deleteThreads', $thread->category) || $user->getKey() === $thread->author_id;
    }
181577
public function removeUser(ChildUser $user)
    {
        if ($this->getUsers()->contains($user)) { $userRole = new ChildUserRole();

            $userRole->setUser($user);
            if ($user->isRolesLoaded()) {
                //remove the back reference if available
                $user->getRoles()->removeObject($this);
            }

            $userRole->setRole($this);
            $this->removeUserRole(clone $userRole);
            $userRole->clear();

            $this->collUsers->remove($this->collUsers->search($user));

            if (null === $this->usersScheduledForDeletion) {
                $this->usersScheduledForDeletion = clone $this->collUsers;
                $this->usersScheduledForDeletion->clear();
            }

            $this->usersScheduledForDeletion->push($user);
        }


        return $this;
    }
479434
public function countUnread(User $user)
    {
        return $this->createQueryBuilder('m')
            ->select('count(m)')
            ->join('m.userMessages', 'um')
            ->where('m.user != :sender')
            ->orWhere('m.user IS NULL')
            ->andWhere('um.user = :user')
            ->andWhere('um.isRead = 0')
            ->andWhere('um.isRemoved = 0')
            ->setParameter(':user', $user)
            ->setParameter(':sender', $user)
            ->getQuery()
            ->getSingleScalarResult();
    }
1153581
public function delete(UserInterface $user): ResponseInterface
    {
        // An administrator can only be deleted by another administrator
        if (!$user->getPreference('canadmin') && $user instanceof User) {
            $this->user_service->delete($user);
            Auth::logout();
        }

        return redirect(route('my-account'));
    }
967474
public function preRemove(User $user, LifecycleEventArgs $event)
    {
        $oldAvatarImage = $user->getAvatarImage();
        if (!empty($oldAvatarImage)) {
            $this->userService->deleteAvatar($oldAvatarImage);
        }
    }
872562
public function can_favourite_discussion(stdClass $user) : bool {
        $context = $this->get_context();
        return has_capability('mod/forum:cantogglefavourite', $context, $user);
    }