123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- <?php
-
- namespace Muzich\CoreBundle\Entity;
-
- use Doctrine\ORM\Mapping as ORM;
- use \Doctrine\Common\Collections\ArrayCollection;
- use Gedmo\Mapping\Annotation as Gedmo;
- use Doctrine\ORM\EntityManager;
- use Muzich\CoreBundle\Entity\GroupsTagsFavorites;
- use Symfony\Component\Validator\Constraints as Assert;
- use Muzich\CoreBundle\Validator as MuzichAssert;
- use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
-
-
- class Group
- {
-
-
-
- protected $id;
-
-
-
- protected $name;
-
-
-
- protected $slug;
-
-
-
- protected $description;
-
-
-
- protected $open = false;
-
-
-
- protected $followers;
-
-
-
- protected $owner;
-
-
-
- protected $tags;
-
-
-
- protected $elements;
-
-
-
- public function __construct()
- {
- $this->followers = new ArrayCollection();
- }
-
- public function __toString()
- {
- return $this->getName();
- }
-
-
-
- public function getId()
- {
- return $this->id;
- }
-
-
-
- public function setName($name)
- {
- $this->name = $name;
- }
-
-
-
- public function getName()
- {
- return $this->name;
- }
-
-
-
- public function setSlug($slug)
- {
- $this->slug = $slug;
- }
-
-
-
- public function getSlug()
- {
- return $this->slug;
- }
-
-
-
- public function setDescription($description)
- {
- $this->description = $description;
- }
-
-
-
- public function getDescription()
- {
- return $this->description;
- }
-
-
-
- public function setOpen($open)
- {
- $this->open = $open;
- }
-
-
-
- public function getOpen()
- {
- return $this->open;
- }
-
-
-
- public function addFollowGroup(FollowGroup $followers)
- {
- $this->followers[] = $followers;
- }
-
-
-
- public function getFollowers()
- {
- return $this->followers;
- }
-
-
-
- public function setOwner(User $owner = null)
- {
- $this->owner = $owner;
- }
-
-
-
- public function getOwner()
- {
- return $this->owner;
- }
-
-
-
- public function addGroupsTagsFavorites(GroupsTagsFavorites $tags)
- {
- $this->tags[] = $tags;
- }
-
-
-
- public function getTags()
- {
- return $this->tags;
- }
-
-
-
- public function addTag(Tag $tag, EntityManager $em)
- {
- $GroupsTagsFavorites = new GroupsTagsFavorites();
- $GroupsTagsFavorites->setTag($tag);
- $GroupsTagsFavorites->setPosition(0);
- $GroupsTagsFavorites->setGroup($this);
- $em->persist($this);
- $em->persist($GroupsTagsFavorites);
- $em->persist($tag);
- $this->tags[] = $GroupsTagsFavorites;
- }
-
- public function setTags($tags)
- {
- $this->tags = $tags;
- }
-
-
-
- public function addElement(Element $elements)
- {
- $this->elements[] = $elements;
- }
-
-
-
- public function getElements()
- {
- return $this->elements;
- }
-
- public function getTagsIdsJson()
- {
- $ids = array();
- if (count($this->getTags()))
- {
- foreach ($this->getTags() as $tag)
- {
- $ids[] = $tag->getTag()->getId();
- }
- }
- return json_encode($ids);
- }
-
-
-
-
- public function setTagsWithIds(EntityManager $em, $ids)
- {
- if (count($ids))
- {
-
- $nids = array();
- foreach ($ids as $id)
- {
- $nids[] = $id;
- }
-
- $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($nids)->execute();
-
-
- foreach ($tags as $tag)
- {
- $this->addTag($tag, $em);
- }
- }
- }
-
- public function setTagsToIds()
- {
- $tags_id = array();
- foreach ($this->getTags() as $tag_r)
- {
- $tags_id[] = $tag_r->getTag()->getId();
- }
- $this->tags = $tags_id;
- }
-
-
-
- public function userCanAddElement($user_id)
- {
- if ($this->open)
- {
- return true;
- }
-
- if ($this->getOwner()->getId() == $user_id)
- {
- return true;
- }
-
- return false;
- }
-
- public function hasThisTag($tag_id)
- {
- foreach ($this->tags as $tag)
- {
- if ($tag_id == $tag->getTag()->getId())
- {
- return true;
- }
- }
- return false;
- }
- }
|