Created groups and membership table

This commit is contained in:
Polonkai Gergely 2012-07-15 20:44:43 +02:00
parent 47177333f9
commit 038ad5d018
3 changed files with 309 additions and 233 deletions

View File

@ -3,6 +3,9 @@
namespace KekRozsak\FrontBundle\Entity; namespace KekRozsak\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use KekRozsak\SecurityBundle\Entity\User;
/** /**
* KekRozsak\FrontBundle\Entity\Group * KekRozsak\FrontBundle\Entity\Group
@ -11,251 +14,195 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class Group class Group
{ {
/** public function __construct()
* @var integer $id {
* @ORM\Id $this->members = new ArrayCollection();
* @ORM\GeneratedValue(strategy="AUTO") }
* @ORM\Column(type="integer")
*/
private $id;
/** /**
* @var string $name * @var integer $id
* @ORM\Column(type="string", length=50, nullable=false, unique=true) * @ORM\Id
*/ * @ORM\GeneratedValue(strategy="AUTO")
private $name; * @ORM\Column(type="integer")
*/
protected $id;
/** /**
* @var string $slug * Get id
* @ORM\Column(type="string", length=50, nullable=false, unique=true) *
*/ * @return integer
private $slug; */
public function getId()
{
return $this->id;
}
/** /**
* @var datetime $createdAt * @var KekRozsak\SecurityBundle\Entity\User $leader
* @ORM\Column(type="datetime", name="created_at", nullable=false) * @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User")
*/ */
private $createdAt; protected $leader;
/** /**
* @var datetime $updatedAt * Set leader
* @ORM\Column(type="datetime", name="updated_at", nullable=true) *
*/ * @param KekRozsak\SecurityBundle\Entity\User $leader
private $updatedAt; * @return Group
*/
public function setLeader(\KekRozsak\SecurityBundle\Entity\User $leader = null)
{
$this->leader = $leader;
return $this;
}
/** /**
* @var text $updateReason * Get leader
* @ORM\Column(type="text", name="update_reason", nullable=true) *
*/ * @return KekRozsak\SecurityBundle\Entity\User
private $updateReason; */
public function getLeader()
{
return $this->leader;
}
/** /**
* @var KekRozsak\FrontBundle\Entity\User $createdBy * @var string $name
* @ORM\ManyToOne(targetEntity="User") * @ORM\Column(type="string", length=50, nullable=false, unique=true)
*/ */
private $createdBy; protected $name;
/** /**
* @var KekRozsak\FrontBundle\Entity\User $updatedBy * Set name
* @ORM\ManyToOne(targetEntity="User") *
*/ * @param string $name
private $updatedBy; * @return Group
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/** /**
* @var KekRozsak\FrontBundle\Entity\User $leader * Get name
* @ORM\ManyToOne(targetEntity="User", inversedBy="ledGroups") *
*/ * @return string
private $leader; */
public function getName()
{
return $this->name;
}
/** /**
* Get id * @var string $slug
* * @ORM\Column(type="string", length=50, nullable=false, unique=true)
* @return integer */
*/ protected $slug;
public function getId()
{
return $this->id;
}
/** /**
* Set name * Set slug
* *
* @param string $name * @param string $slug
* @return Group * @return Group
*/ */
public function setName($name) public function setSlug($slug)
{ {
$this->name = $name; $this->slug = $slug;
return $this; return $this;
} }
/** /**
* Get name * Get slug
* *
* @return string * @return string
*/ */
public function getName() public function getSlug()
{ {
return $this->name; return $this->slug;
} }
/** /**
* Set slug * @var KekRozsak\SecurityBundle\Entity\User $createdBy
* * @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User")
* @param string $slug * @ORM\JoinColumn(name="created_by_id")
* @return Group */
*/ protected $createdBy;
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/** /**
* Get slug * Set createdBy
* *
* @return string * @param KekRozsak\SecurityBundle\Entity\User $createdBy
*/ * @return Group
public function getSlug() */
{ public function setCreatedBy(\KekRozsak\SecurityBundle\Entity\User $createdBy)
return $this->slug; {
} $this->createdBy = $createdBy;
return $this;
}
/** /**
* Set createdAt * Get createdBy
* *
* @param datetime $createdAt * @return KekRozsak\SecurityBundle\Entity\User
* @return Group */
*/ public function getCreatedBy()
public function setCreatedAt($createdAt) {
{ return $this->createdBy;
$this->createdAt = $createdAt; }
return $this;
}
/** /**
* Get createdAt * @var DateTime $createdAt
* * @ORM\Column(type="datetime", name="created_at", nullable=false)
* @return datetime */
*/ protected $createdAt;
public function getCreatedAt()
{
return $this->createdAt;
}
/** /**
* Set updatedAt * Set createdAt
* *
* @param datetime $updatedAt * @param DateTime $createdAt
* @return Group * @return Group
*/ */
public function setUpdatedAt($updatedAt) public function setCreatedAt(\DateTime $createdAt)
{ {
$this->updatedAt = $updatedAt; $this->createdAt = $createdAt;
return $this; return $this;
} }
/** /**
* Get updatedAt * Get createdAt
* *
* @return datetime * @return DateTime
*/ */
public function getUpdatedAt() public function getCreatedAt()
{ {
return $this->updatedAt; return $this->createdAt;
} }
/** /**
* Set updateReason * @var Doctrine\Common\Collections\ArrayCollection $members
* * @ORM\OneToMany(targetEntity="UserGroupMembership", mappedBy="group")
* @param text $updateReason */
* @return Group protected $members;
*/
public function setUpdateReason($updateReason)
{
$this->updateReason = $updateReason;
return $this;
}
/** /**
* Get updateReason * Add member
* *
* @return text * @param KekRozsak\FrontBundle\Entity\UserGroupMembership $member
*/ * @return Group
public function getUpdateReason() */
{ public function addMember(\KekRozsak\FrontBundle\Entity\UserGroupMembership $member)
return $this->updateReason; {
} $this->members[] = $member;
return $this;
}
/** /**
* Set createdBy * Get all members
* *
* @param KekRozsak\FrontBundle\Entity\User $createdBy * @return Doctrine\Common\Collections\ArrayCollection
* @return Group */
*/ public function getMembers()
public function setCreatedBy(\KekRozsak\FrontBundle\Entity\User $createdBy = null) {
{ return $this->members;
$this->createdBy = $createdBy; }
return $this;
}
/**
* Get createdBy
*
* @return KekRozsak\FrontBundle\Entity\User
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* Set updatedBy
*
* @param KekRozsak\FrontBundle\Entity\User $updatedBy
* @return Group
*/
public function setUpdatedBy(\KekRozsak\FrontBundle\Entity\User $updatedBy = null)
{
$this->updatedBy = $updatedBy;
return $this;
}
/**
* Get updatedBy
*
* @return KekRozsak\FrontBundle\Entity\User
*/
public function getUpdatedBy()
{
return $this->updatedBy;
}
/**
* Set leader
*
* @param KekRozsak\FrontBundle\Entity\User $leader
* @return Group
*/
public function setLeader(\KekRozsak\FrontBundle\Entity\User $leader = null)
{
$this->leader = $leader;
return $this;
}
/**
* Get leader
*
* @return KekRozsak\FrontBundle\Entity\User
*/
public function getLeader()
{
return $this->leader;
}
/**
* @var ArrayCollection $documents
* @ORM\ManyToMany(targetEntity="Document", inversedBy="groups")
*/
private $documents;
} }

View File

@ -0,0 +1,93 @@
<?php
namespace KekRozsak\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use KekRozsak\SecurityBundle\Entity\User;
/**
* KekRozsak\FrontBundle\Entity\UserGroupMembership
* @ORM\Entity
* @ORM\Table(name="user_group_memberships", uniqueConstraints={
* @ORM\UniqueConstraint(columns={"user_id", "group_id"})
* })
*/
class UserGroupMembership
{
/**
* @var integer $id
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @var KekRozsak\SecurityBundle\Entity\User $user
* @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User", inversedBy="groups")
* @ORM\JoinColumn(name="user_id")
*/
protected $user;
/**
* Set user
*
* @param KekRozsak\SecurityBundle\Entity\User $user
* @return UserGroupMembership
*/
public function setUser(\KekRozsak\SecurityBundle\Entity\User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return KekRozsak\SecurityBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* @var KekRozsak\FrontBundle\Entity\Group
* @ORM\ManyToOne(targetEntity="Group", inversedBy="members")
* @ORM\JoinColumn(name="group_id")
*/
protected $group;
/**
* Set group
*
* @param KekRozsak\FrontBundle\Entity\Group
* @return UserGroupMembership
*/
public function setGroup(\KekRozsak\FrontBundle\Entity\Group $group)
{
$this->group = $group;
return $this;
}
/**
* Get group
*
* @return KekRozsak\FrontBundle\Entity\Group
*/
public function getGroup()
{
return $this->group;
}
}

View File

@ -2,13 +2,15 @@
namespace KekRozsak\SecurityBundle\Entity; namespace KekRozsak\SecurityBundle\Entity;
use \Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use \Symfony\Component\Security\Core\User\UserInterface; use Doctrine\Common\Collections\ArrayCollection;
use \Symfony\Component\Security\Core\User\AdvancedUserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use \Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use \Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert; use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
use \KekRozsak\FrontBundle\Entity\UserData; use KekRozsak\FrontBundle\Entity\UserData;
use KekRozsak\FrontBundle\Entity\UserGroupMembership;
/** /**
* KekRozsak\SecurityBundle\Entity\User * KekRozsak\SecurityBundle\Entity\User
@ -20,6 +22,11 @@ use \KekRozsak\FrontBundle\Entity\UserData;
*/ */
class User implements UserInterface, AdvancedUserInterface class User implements UserInterface, AdvancedUserInterface
{ {
public function __construct()
{
$this->groups = new ArrayCollection();
}
/** /**
* @var integer $id * @var integer $id
* @ORM\Id * @ORM\Id
@ -268,6 +275,35 @@ class User implements UserInterface, AdvancedUserInterface
return $this->userData; return $this->userData;
} }
/**
* @var Doctrine\Common\Collections\ArrayCollection $groups
* @ORM\OneToMany(targetEntity="KekRozsak\FrontBundle\Entity\UserGroupMembership", mappedBy="user")
* @ORM\JoinColumn(referencedColumnName="user_id")
*/
private $groups;
/**
* Add group
*
* @param KekRozsak\FrontBundle\Entity\UserGroupMembership $group
* @return User
*/
public function addGroup(\KekRozsak\FrontBundle\Entity\UserGroupMembership $group)
{
$this->groups[] = $group;
return $this;
}
/**
* Get all groups
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getGroups()
{
return $this->groups;
}
/* Here comes the remaining part of UserInterface implementation */ /* Here comes the remaining part of UserInterface implementation */
public function getRoles() public function getRoles()