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() . ')');
}
}