Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Admin\Entity;
- use Doctrine\ORM\EntityManager;
- use Doctrine\ORM\Mapping as ORM;
- use \ArrayObject;
- /**
- * @ORM\MappedSuperclass
- */
- abstract class Base {
- protected $errors = null;
- public function setError($key, $msg) {
- $this->initializeErrors();
- $this->errors->offsetSet($key, $msg);
- }
- public function getErrors() {
- return $this->errors;
- }
- public function initializeErrors() {
- if (is_null($this->getErrors())) {
- $this->errors = new ArrayObject();
- }
- return $this;
- }
- /**
- * Return Dataset of Entities
- * @return Mixed
- */
- public function getAll() {
- return $this->getEntityManager()->getRepository(get_class($this))->findBy(array('ativo' => 1), array('nome' => 'ASC'));
- }
- /**
- * Get By ID
- * @param integer $id
- * @return type
- */
- public function getById($id) {
- return $this->getEntityManager()->getRepository(get_class($this))->find($id);
- }
- private $entityManager = null;
- /**
- * Return EntityManager
- * @return object
- */
- function getEntityManager() {
- return $this->entityManager;
- }
- /**
- * Set EntityManager
- * @param EntityManager $entityManager
- * @return \Admin\Entity\Base
- */
- function setEntityManager(EntityManager $entityManager) {
- $this->entityManager = $entityManager;
- return $this;
- }
- /**
- * Set EntityManager
- * @param EntityManager $entityManager
- */
- function __construct(EntityManager $entityManager = null) {
- if (!is_null($entityManager)) {
- $this->setEntityManager($entityManager);
- }
- $this->initializeErrors();
- }
- public function __toString() {
- return $this->getNome();
- }
- abstract public function store();
- abstract public function populate(array $params);
- public function remove(){
- $this->getEntityManager()->remove($this);
- $this->getEntityMAnager()->flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement