Skip to content

Instantly share code, notes, and snippets.

@cod1ingcoding
Forked from Ocramius/User.php
Created August 23, 2017 01:49
Show Gist options
  • Save cod1ingcoding/0b71a0558fb5a05bb3c7915c9cfdea5c to your computer and use it in GitHub Desktop.
Save cod1ingcoding/0b71a0558fb5a05bb3c7915c9cfdea5c to your computer and use it in GitHub Desktop.

Revisions

  1. @Ocramius Ocramius revised this gist Mar 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion UserGroup.php
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ class UserGroup
    /**
    * @var \Doctrine\Common\Collections\Collection|User[]
    *
    * @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
    * @ORM\ManyToMany(targetEntity="User", mappedBy="userGroups")
    */
    protected $users;

  2. @Ocramius Ocramius revised this gist Aug 18, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion User.php
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ class User
    * }
    * )
    */
    protected $groups;
    protected $userGroups;

    /**
    * Default constructor, initializes collections
  3. @Ocramius Ocramius revised this gist Feb 19, 2013. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion User.php
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ class User
    /**
    * @var \Doctrine\Common\Collections\Collection|UserGroup[]
    *
    * @ORM\ManyToMany(targetEntity="UserGroup", inversedBy="blocks")
    * @ORM\ManyToMany(targetEntity="UserGroup", inversedBy="users")
    * @ORM\JoinTable(
    * name="user_usergroup",
    * joinColumns={
    2 changes: 1 addition & 1 deletion UserGroup.php
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ class UserGroup
    /**
    * @var \Doctrine\Common\Collections\Collection|User[]
    *
    * @ORM\ManyToMany(targetEntity="User", mappedBy="blocks")
    * @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
    */
    protected $users;

  4. @Ocramius Ocramius revised this gist Aug 9, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion UserGroup.php
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ public function addUser(User $user)
    /**
    * @param User $user
    */
    public function removeUserGroup(User $user)
    public function removeUser(User $user)
    {
    if (!$this->users->contains($user)) {
    return;
  5. @Ocramius Ocramius created this gist Jul 16, 2012.
    69 changes: 69 additions & 0 deletions User.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    <?php

    use Doctrine\ORM\Mapping as ORM;
    use Doctrine\Common\Collections\ArrayCollection;

    /**
    * @ORM\Entity()
    * @ORM\Table(name="user")
    */
    class User
    {
    /**
    * @var int|null
    * @ORM\Id()
    * @ORM\GeneratedValue(strategy="AUTO")
    * @ORM\Column(type="integer", name="id")
    */
    protected $id;

    /**
    * @var \Doctrine\Common\Collections\Collection|UserGroup[]
    *
    * @ORM\ManyToMany(targetEntity="UserGroup", inversedBy="blocks")
    * @ORM\JoinTable(
    * name="user_usergroup",
    * joinColumns={
    * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
    * },
    * inverseJoinColumns={
    * @ORM\JoinColumn(name="usergroup_id", referencedColumnName="id")
    * }
    * )
    */
    protected $groups;

    /**
    * Default constructor, initializes collections
    */
    public function __construct()
    {
    $this->userGroups = new ArrayCollection();
    }

    /**
    * @param UserGroup $userGroup
    */
    public function addUserGroup(UserGroup $userGroup)
    {
    if ($this->userGroups->contains($userGroup)) {
    return;
    }

    $this->userGroups->add($userGroup);
    $userGroup->addUser($this);
    }

    /**
    * @param UserGroup $userGroup
    */
    public function removeUserGroup(UserGroup $userGroup)
    {
    if (!$this->userGroups->contains($userGroup)) {
    return;
    }

    $this->userGroups->removeElement($userGroup);
    $userGroup->removeUser($this);
    }
    }
    60 changes: 60 additions & 0 deletions UserGroup.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    <?php

    use Doctrine\ORM\Mapping as ORM;
    use Doctrine\Common\Collections\ArrayCollection;

    /**
    * @ORM\Entity()
    * @ORM\Table(name="usergroup")
    */
    class UserGroup
    {
    /**
    * @var int|null
    * @ORM\Id()
    * @ORM\GeneratedValue(strategy="AUTO")
    * @ORM\Column(type="integer", name="id")
    */
    protected $id;

    /**
    * @var \Doctrine\Common\Collections\Collection|User[]
    *
    * @ORM\ManyToMany(targetEntity="User", mappedBy="blocks")
    */
    protected $users;

    /**
    * Default constructor, initializes collections
    */
    public function __construct()
    {
    $this->users = new ArrayCollection();
    }

    /**
    * @param User $user
    */
    public function addUser(User $user)
    {
    if ($this->users->contains($user)) {
    return;
    }

    $this->users->add($user);
    $user->addUserGroup($this);
    }

    /**
    * @param User $user
    */
    public function removeUserGroup(User $user)
    {
    if (!$this->users->contains($user)) {
    return;
    }

    $this->users->removeElement($user);
    $user->removeUserGroup($this);
    }
    }