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,61 +14,18 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class Group class Group
{ {
public function __construct()
{
$this->members = new ArrayCollection();
}
/** /**
* @var integer $id * @var integer $id
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
*/ */
private $id; protected $id;
/**
* @var string $name
* @ORM\Column(type="string", length=50, nullable=false, unique=true)
*/
private $name;
/**
* @var string $slug
* @ORM\Column(type="string", length=50, nullable=false, unique=true)
*/
private $slug;
/**
* @var datetime $createdAt
* @ORM\Column(type="datetime", name="created_at", nullable=false)
*/
private $createdAt;
/**
* @var datetime $updatedAt
* @ORM\Column(type="datetime", name="updated_at", nullable=true)
*/
private $updatedAt;
/**
* @var text $updateReason
* @ORM\Column(type="text", name="update_reason", nullable=true)
*/
private $updateReason;
/**
* @var KekRozsak\FrontBundle\Entity\User $createdBy
* @ORM\ManyToOne(targetEntity="User")
*/
private $createdBy;
/**
* @var KekRozsak\FrontBundle\Entity\User $updatedBy
* @ORM\ManyToOne(targetEntity="User")
*/
private $updatedBy;
/**
* @var KekRozsak\FrontBundle\Entity\User $leader
* @ORM\ManyToOne(targetEntity="User", inversedBy="ledGroups")
*/
private $leader;
/** /**
* Get id * Get id
@ -77,6 +37,40 @@ class Group
return $this->id; return $this->id;
} }
/**
* @var KekRozsak\SecurityBundle\Entity\User $leader
* @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User")
*/
protected $leader;
/**
* Set leader
*
* @param KekRozsak\SecurityBundle\Entity\User $leader
* @return Group
*/
public function setLeader(\KekRozsak\SecurityBundle\Entity\User $leader = null)
{
$this->leader = $leader;
return $this;
}
/**
* Get leader
*
* @return KekRozsak\SecurityBundle\Entity\User
*/
public function getLeader()
{
return $this->leader;
}
/**
* @var string $name
* @ORM\Column(type="string", length=50, nullable=false, unique=true)
*/
protected $name;
/** /**
* Set name * Set name
* *
@ -99,6 +93,12 @@ class Group
return $this->name; return $this->name;
} }
/**
* @var string $slug
* @ORM\Column(type="string", length=50, nullable=false, unique=true)
*/
protected $slug;
/** /**
* Set slug * Set slug
* *
@ -122,78 +122,19 @@ class Group
} }
/** /**
* Set createdAt * @var KekRozsak\SecurityBundle\Entity\User $createdBy
* * @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User")
* @param datetime $createdAt * @ORM\JoinColumn(name="created_by_id")
* @return Group
*/ */
public function setCreatedAt($createdAt) protected $createdBy;
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return datetime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param datetime $updatedAt
* @return Group
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return datetime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set updateReason
*
* @param text $updateReason
* @return Group
*/
public function setUpdateReason($updateReason)
{
$this->updateReason = $updateReason;
return $this;
}
/**
* Get updateReason
*
* @return text
*/
public function getUpdateReason()
{
return $this->updateReason;
}
/** /**
* Set createdBy * Set createdBy
* *
* @param KekRozsak\FrontBundle\Entity\User $createdBy * @param KekRozsak\SecurityBundle\Entity\User $createdBy
* @return Group * @return Group
*/ */
public function setCreatedBy(\KekRozsak\FrontBundle\Entity\User $createdBy = null) public function setCreatedBy(\KekRozsak\SecurityBundle\Entity\User $createdBy)
{ {
$this->createdBy = $createdBy; $this->createdBy = $createdBy;
return $this; return $this;
@ -202,7 +143,7 @@ class Group
/** /**
* Get createdBy * Get createdBy
* *
* @return KekRozsak\FrontBundle\Entity\User * @return KekRozsak\SecurityBundle\Entity\User
*/ */
public function getCreatedBy() public function getCreatedBy()
{ {
@ -210,52 +151,58 @@ class Group
} }
/** /**
* Set updatedBy * @var DateTime $createdAt
* @ORM\Column(type="datetime", name="created_at", nullable=false)
*/
protected $createdAt;
/**
* Set createdAt
* *
* @param KekRozsak\FrontBundle\Entity\User $updatedBy * @param DateTime $createdAt
* @return Group * @return Group
*/ */
public function setUpdatedBy(\KekRozsak\FrontBundle\Entity\User $updatedBy = null) public function setCreatedAt(\DateTime $createdAt)
{ {
$this->updatedBy = $updatedBy; $this->createdAt = $createdAt;
return $this; return $this;
} }
/** /**
* Get updatedBy * Get createdAt
* *
* @return KekRozsak\FrontBundle\Entity\User * @return DateTime
*/ */
public function getUpdatedBy() public function getCreatedAt()
{ {
return $this->updatedBy; return $this->createdAt;
} }
/** /**
* Set leader * @var Doctrine\Common\Collections\ArrayCollection $members
* @ORM\OneToMany(targetEntity="UserGroupMembership", mappedBy="group")
*/
protected $members;
/**
* Add member
* *
* @param KekRozsak\FrontBundle\Entity\User $leader * @param KekRozsak\FrontBundle\Entity\UserGroupMembership $member
* @return Group * @return Group
*/ */
public function setLeader(\KekRozsak\FrontBundle\Entity\User $leader = null) public function addMember(\KekRozsak\FrontBundle\Entity\UserGroupMembership $member)
{ {
$this->leader = $leader; $this->members[] = $member;
return $this; return $this;
} }
/** /**
* Get leader * Get all members
* *
* @return KekRozsak\FrontBundle\Entity\User * @return Doctrine\Common\Collections\ArrayCollection
*/ */
public function getLeader() public function getMembers()
{ {
return $this->leader; return $this->members;
} }
/**
* @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()