Skip to content

Instantly share code, notes, and snippets.

@duskohu
Created March 9, 2014 22:23
Show Gist options
  • Save duskohu/9455744 to your computer and use it in GitHub Desktop.
Save duskohu/9455744 to your computer and use it in GitHub Desktop.
Doctrine model
<?php
namespace Nas\UsersModule\Model;
/**
* @ORM\Entity
* @ORM\Table(name="roles")
*/
class Role extends Object
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @var int
*/
protected $id;
/**
* @ORM\Column
* @var string
*/
protected $slug;
/**
* @ORM\Column(name="users_id", type="integer")
* @var string
*/
protected $userId;
/**
* @ManyToOne(targetEntity="User", inversedBy="roles")
* @JoinColumn(name="users_id", referencedColumnName="id")
**/
private $user;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param string $slug
* @return Role
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* @return string
*/
public function getUserId()
{
return $this->userId;
}
/**
* @param int $id
* @return Role
*/
public function setUserId($id)
{
$this->userId = $id;
return $this;
}
}
<?php
namespace Nas\UsersModule\Model;
class RolesFacade extends Object
{
/** @var EntityDao */
private $dao;
/**
* @param EntityManager $em
*/
public function __construct(EntityManager $em)
{
$this->dao = $em->getDao('\Nas\UsersModule\Model\Role');
}
/**
* @return EntityDao
*/
public function getRoleDao()
{
return $this->dao;
}
/**
* @param Role $entity
* @return array|Role
*/
public function save(Role $entity)
{
return $this->dao->save($entity);
}
/**
* @return ResultSet
*/
public function findAll()
{
$qb = $this->dao->createQueryBuilder('r');
return new ResultSet($qb->getQuery());
}
}
<?php
namespace Nas\UsersModule\Model;
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User extends Object
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @var int
*/
protected $id;
/**
* @ORM\Column
* @var string
*/
protected $name;
/**
* @OneToMany(targetEntity="Role", mappedBy="user")
* @var ArrayCollection|Role[]
**/
protected $roles;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
* @return User
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getRoles()
{
return $this->roles;
}
}
<?php
namespace Nas\UsersModule\Model;
class UsersFacade extends Object
{
/** @var EntityDao */
private $dao;
/**
* @param EntityManager $em
*/
public function __construct(EntityManager $em)
{
$this->dao = $em->getDao('\Nas\UsersModule\Model\User');
}
/**
* @return EntityDao
*/
public function getUserDao()
{
return $this->dao;
}
/**
* @param User $entity
* @return array|User
*/
public function save(User $entity)
{
return $this->dao->save($entity);
}
/**
* @return ResultSet
*/
public function findAll()
{
$qb = $this->dao->createQueryBuilder('u');
return new ResultSet($qb->getQuery());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment