Newscoop\Services\UserTopicService::unfollowTopic PHP Метод

unfollowTopic() публичный Метод

Unfollow topic
public unfollowTopic ( User $user, Topic $topic ) : void
$user Newscoop\Entity\User
$topic Newscoop\NewscoopBundle\Entity\Topic
Результат void
    public function unfollowTopic(User $user, Topic $topic)
    {
        try {
            $userTopics = $this->em->getRepository('Newscoop\\Entity\\UserTopic')->findByTopicAndUser($user, $topic);
            if ($userTopics) {
                if (is_array($userTopics)) {
                    foreach ($userTopics as $userTopic) {
                        $this->em->remove($userTopic);
                    }
                } else {
                    $this->em->remove($userTopics);
                }
                $this->em->flush();
            }
        } catch (Exception $e) {
            throw new Exception('Could not unfollow topic. (' . $e->getMessage() . ')');
        }
    }