Added forum topic favourite function

Solves issue #12

Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely Polonkai (W00d5t0ck)
2012-08-23 19:06:26 +02:00
parent 4d8ae5c0f0
commit 6bdb9530a3
5 changed files with 223 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
namespace KekRozsak\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use KekRozsak\SecurityBundle\Entity\User;
@@ -21,6 +22,7 @@ class UserData
$this->googleTalkPublic = false;
$this->skypePublic = false;
$this->phoneNumberPublic = false;
$this->favouriteTopics = new ArrayCollection();
}
/**
@@ -452,4 +454,66 @@ class UserData
{
return $this->phoneNumberPublic;
}
/**
* ArrayCollection of the User's favourite ForumTopics
*
* @var Doctrine\Common\Collections\ArrayCollection $favouriteTopics
*
* @ORM\ManyToMany(targetEntity="ForumTopic", fetch="LAZY")
* @ORM\JoinTable(name="user_favourite_forum_topics", joinColumns={
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* }, inverseJoinColumns={
* @ORM\JoinColumn(name="forum_topic_id")
* }
* )
*/
protected $favouriteTopics;
/**
* Add a favourite ForumTopic
*
* @param KekRozsak\FrontBundle\Entity\ForumTopic $topic
* @return UserData
*/
public function addFavouriteTopic(ForumTopic $topic)
{
// TODO: Check if not null
$this->favouriteTopics->add($topic);
return $this;
}
/**
* Remove a favourite ForumTopic
*
* @param KekRozsak\FrontBundle\Entity\ForumTopic $topic
* @return UserData
*/
public function removeFavouriteTopic(ForumTopic $topic)
{
// TODO: Check if not null
$this->favouriteTopics->removeElement($topic);
return $this;
}
/**
* Get favourite ForumTopics
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getFavouriteTopics()
{
return $this->favouriteTopics;
}
/**
* Check if given ForumTopic is favourited by User
*
* @param KekRozsak\FrontBundle\Entity\ForumTopic $topic
* @return boolean
*/
public function isFavouriteForumTopic(ForumTopic $topic)
{
return $this->favouriteTopics->contains($topic);
}
}