Current path: home/webdevt/cryptoimpot.fr/module/Application/src/Mapper/
?? Go up: /home/webdevt/cryptoimpot.fr/module/Application/src
<?php
namespace Application\Mapper;
use Doctrine\ORM\EntityManager;
use TheSeer\Tokenizer\Exception;
use Laminas\Hydrator\HydratorInterface;
use Laminas\Paginator\Adapter\ArrayAdapter;
use Laminas\Paginator\Paginator;
class SourceMapper {
/**
* @var EntityManager
*/
protected $em;
protected $entityClass;
protected $orderAuthorized;
protected $orderByAuthorized;
public function __construct(EntityManager $em) {
$this->em = $em;
$this->entityClass = 'Application\Entity\Source';
$this->orderByAuthorized = array(
'id',
'name',
);
$this->orderAuthorized = array(
'ASC',
'DESC'
);
}
public function findById($id) {
$er = $this->em->getRepository($this->entityClass);
return $er->findOneBy(array('id' => $id));
}
public function findByName($name) {
$er = $this->em->getRepository($this->entityClass);
return $er->findOneBy(array('name' => $name));
}
public function findByUrl($url) {
$er = $this->em->getRepository($this->entityClass);
return $er->findOneBy(array('url' => $url));
}
public function insert($entity, $tableName = null, HydratorInterface $hydrator = null) {
return $this->persist($entity);
}
public function update($entity, $where = null, $tableName = null, HydratorInterface $hydrator = null) {
return $this->persist($entity);
}
public function delete($entity, $where = null, $tableName = null, HydratorInterface $hydrator = null) {
try {
$this->em->remove($entity);
$this->em->flush();
return true;
} catch (Exception $e) {
return false;
}
}
protected function persist($entity) {
$this->em->persist($entity);
$this->em->flush();
return $entity;
}
}