Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Admin\Entity;
  4.  
  5. use Doctrine\ORM\EntityManager;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use \ArrayObject;
  8. /**
  9. * @ORM\MappedSuperclass
  10. */
  11. abstract class Base {
  12.  
  13. protected $errors = null;
  14.  
  15. public function setError($key, $msg) {
  16. $this->initializeErrors();
  17. $this->errors->offsetSet($key, $msg);
  18. }
  19.  
  20. public function getErrors() {
  21. return $this->errors;
  22. }
  23.  
  24. public function initializeErrors() {
  25. if (is_null($this->getErrors())) {
  26. $this->errors = new ArrayObject();
  27. }
  28. return $this;
  29. }
  30.  
  31. /**
  32. * Return Dataset of Entities
  33. * @return Mixed
  34. */
  35. public function getAll() {
  36. return $this->getEntityManager()->getRepository(get_class($this))->findBy(array('ativo' => 1), array('nome' => 'ASC'));
  37. }
  38.  
  39. /**
  40. * Get By ID
  41. * @param integer $id
  42. * @return type
  43. */
  44. public function getById($id) {
  45. return $this->getEntityManager()->getRepository(get_class($this))->find($id);
  46. }
  47.  
  48. private $entityManager = null;
  49.  
  50. /**
  51. * Return EntityManager
  52. * @return object
  53. */
  54. function getEntityManager() {
  55. return $this->entityManager;
  56. }
  57.  
  58. /**
  59. * Set EntityManager
  60. * @param EntityManager $entityManager
  61. * @return \Admin\Entity\Base
  62. */
  63. function setEntityManager(EntityManager $entityManager) {
  64. $this->entityManager = $entityManager;
  65. return $this;
  66. }
  67.  
  68. /**
  69. * Set EntityManager
  70. * @param EntityManager $entityManager
  71. */
  72. function __construct(EntityManager $entityManager = null) {
  73. if (!is_null($entityManager)) {
  74. $this->setEntityManager($entityManager);
  75. }
  76. $this->initializeErrors();
  77. }
  78.  
  79. public function __toString() {
  80. return $this->getNome();
  81. }
  82.  
  83. abstract public function store();
  84.  
  85. abstract public function populate(array $params);
  86.  
  87. public function remove(){
  88. $this->getEntityManager()->remove($this);
  89. $this->getEntityMAnager()->flush();
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement