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 Laminas\Paginator\Adapter\ArrayAdapter;
use Laminas\Paginator\Paginator;
class UserExchangeLinkerMapper {
/**
* @var \Doctrine\ORM\EntityManager
*/
protected $em;
protected $entityClass;
protected $orderAuthorized;
protected $orderByAuthorized;
public function __construct(EntityManager $em) {
$this->em = $em;
$this->entityClass = 'Application\Entity\UserExchangeLinker';
// $this->orderByAuthorized = array(
// 'id',
// 'partenaire',
// 'email',
// 'code',
// 'prescripteur',
// 'coordinateur',
// 'dateCreation',
// 'dateInscription'
// );
// $this->orderAuthorized = array(
// 'ASC',
// 'DESC'
// );
}
// public function findByCodeBox($codeBox) {
// $er = $this->em->getRepository($this->entityClass);
// return $er->findOneBy(array('code' => $codeBox));
// }
//
// public function findByToken($token) {
//
// $er = $this->em->getRepository($this->entityClass);
// return $er->findOneBy(array('token' => $token));
// }
//
// public function findByPatient($patientId) {
//
// $er = $this->em->getRepository($this->entityClass);
// return $er->findOneByPatient($patientId);
// }
//
// public function getList($parameters, $pagination = true, $onlyPublished = false) {
// $er = $this->em->getRepository($this->entityClass);
// $query = $er->createQueryBuilder('c')
// ->leftJoin('c.patient', 'pa')
// ->leftJoin('pa.activitePatient', 'ac')
// ->leftJoin('c.partenaire', 'p')
// ->leftJoin('c.prescripteur', 'pr')
// ->leftJoin('c.coordinateur', 'co')
// ->leftJoin('c.statut', 'st')
// ;
// if (isset($parameters['sort_by'])) {
//
// $sort_by = in_array($parameters['sort_by'], $this->orderByAuthorized) ? $parameters['sort_by'] : 'id';
//
// if (isset($parameters['sort'])) {
// $sort = in_array($parameters['sort'], $this->orderAuthorized) ? $parameters['sort'] : 'DESC';
// if ($parameters['sort_by'] == 'statut') {
// $query->orderBy('st.statut', $sort);
// }
// elseif ($parameters['sort_by'] == 'prescripteur') {
// $query->orderBy('pr.nom', $sort);
// }
// elseif ($parameters['sort_by'] == 'coordinateur') {
// $query->orderBy('co.nom', $sort);
// }
//
// else {
// $query->orderBy('c.' . $sort_by, $sort);
// }
// }
// }
//
// if (isset($parameters['search'])) {
// $search = $parameters['search'];
// // Gestion recherche phrase exacte si présence de " début et fin de chaine, ou un des mots présents
// if (substr($search, 0, 1) == '"' && substr($search, -1, 1) == '"') {
// $search = substr($search, 1, -1);
// } else {
// // recherche date format fr ex 10 decembre 2016
// $expression = '#(\d{1,2})\s(\w+)\s(\d{4})#i';
// $expression2 = '#(\w+)\s(\d{4})#i';
//// if (preg_match($expression, $search)) {
//// echo $search;
//// }
// if ($search != 'non utilisé' && $search != 'utilisé' && !preg_match($expression, $search) && !preg_match($expression2, $search)) {
// $search = explode(' ', $search);
// }
// }
// if (is_array($search)) {
// $i = 1;
// foreach ($search as $searchElement) {
// $query->orWhere('c.code LIKE ?' . $i)
// ->orWhere('c.dateCreation LIKE ?' . $i)
// ->orWhere('p.nom LIKE ?' . $i)
//// ->orWhere('st.statut = :search' . $i)
// ->setParameter($i, '%' . $searchElement . '%')
// //->setParameter('search' . $i, $search)
// ;
// $i++;
// }
// } else {
// if ($search == 'non utilisé') {
// $query->where('c.code = :search')
// ->orWhere('c.dateCreation = :search')
// ->orWhere('p.nom = :search')
// ->orWhere('st.statut = :search')
// ->setParameter('search', $search);
// } else {
//
//
// $query->where('c.code LIKE :search')
// ->orWhere('c.dateCreation LIKE :search')
// ->orWhere('p.nom LIKE :search')
// ->orWhere('st.statut = :search2')
// ->setParameter('search', '%' . $search . '%')
// ->setParameter('search2', $search);
//
// if (preg_match($expression, $search, $matches) || preg_match($expression2, $search, $matches2)) {
// $arrayMonth = array(
// 'janvier' => '01',
// 'février' => '02',
// 'mars' => '03',
// 'avril' => '04',
// 'mai' => '05',
// 'juin' => '06',
// 'juillet' => '07',
// 'août' => '08',
// 'septembre' => '09',
// 'octobre' => 10,
// 'novembre' => 11,
// 'décembre' => 12
// );
// if ($matches) {
//
// if (!empty($arrayMonth[$matches[2]])) {
// $monthDigit = $arrayMonth[$matches[2]];
// }
// $dateEN = $matches[3] . '-' . $monthDigit . '-' . $matches[1];
//// echo $dateYYYYMMDD;
// }elseif ($matches2) {
//
// if (!empty($arrayMonth[$matches2[1]])) {
// $monthDigit = $arrayMonth[$matches2[1]];
// }
// $dateEN = $matches2[2] . '-' . $monthDigit ;
//// echo $dateYYYYMMDD;
// }
//// echo $dateYYYYMM;
//// echo $matches[3] . '-' . $matches[2] . '-' . $matches[1];
//// echo $matches2[2] . '-' . $monthDigit;
// $query->orWhere('c.dateCreation LIKE :searchDate')
// ->setParameter('searchDate', '%' . $dateEN . '%')
//
//
// ;
// }
// }
// }
// }
//
// if ($onlyPublished) {
// $query->andWhere('st.id = :publish')
// ->setParameter('publish', 1);
// }
// $arrayOfTests = $query->getQuery()
// ->getResult();
//
//// \Doctrine\Common\Util\Debug::dump($arrayOfTests[0]);
//
// if ($pagination === true) {
// $paginatorAdapter = new ArrayAdapter($arrayOfTests);
// return new Paginator($paginatorAdapter);
// } else {
// return $arrayOfTests;
// }
// }
// public function getListPatient($parameters, $pagination = true, $onlyPublished = false) {
// $er = $this->em->getRepository($this->entityClass);
// $query = $er->createQueryBuilder('c')
// ->leftJoin('c.partenaire', 'p')
// ->leftJoin('c.statut', 'st')
// ->leftJoin('c.patient', 'pa');
// if (isset($parameters['sort_by'])) {
//
// $sort_by = in_array($parameters['sort_by'], $this->orderByAuthorized) ? $parameters['sort_by'] : 'c.id';
//
// if (isset($parameters['sort'])) {
// $sort = in_array($parameters['sort'], $this->orderAuthorized) ? $parameters['sort'] : 'DESC';
// if ($parameters['sort_by'] == 'statut') {
// $query->orderBy('st.statut', $sort);
// } elseif ($parameters['sort_by'] == 'email') {
// $query->orderBy('pa.email', $sort);
// } else {
// $query->orderBy('c.' . $sort_by, $sort);
// }
// }
// }
//
// if (isset($parameters['search'])) {
// $search = $parameters['search'];
//
// // Gestion recherche phrase exacte si présence de " début et fin de chaine, ou un des mots présents
//// if (substr($search, 0, 1) == '"' && substr($search, -1, 1) == '"') {
//// $search = substr($search, 1, -1);
//// } else {
//// $search = explode(' ', $search);
//// }
//
//
// if (is_array($search)) {
// $i = 1;
// foreach ($search as $searchElement) {
// $query->orWhere('c.code LIKE ?' . $i)
// ->orWhere('c.dateCreation LIKE ?' . $i)
// ->orWhere('p.nom LIKE ?' . $i)
// ->orWhere('st.statut LIKE ?' . $i)
// ->setParameter($i, '%' . $searchElement . '%');
// $i++;
// }
// } else {
// if ($search == 'publié') {
// $query->orWhere('c.code = :search')
// ->orWhere('c.dateCreation = :search')
// ->orWhere('p.nom = :search')
// ->orWhere('st.statut = :search')
// ->setParameter('search', $search);
// } else if (strpos($search,'Inscrit le') !== false) {
//
// $expression = '#(\d{1,2})\s(\w+)\s(\d{4})#i';
// $expression2 = '#(\w+)\s(\d{4})#i';
// $expression3 = '#(\d{1,2})-(\d{1,2})-(\d{4})#i';
// $expression4 = '#(\d{1,2})-(\d{1,2})#i';
//
// $search = str_replace('Inscrit le', '', $search);
//
// if (preg_match($expression, $search, $matches)
// || preg_match($expression2, $search, $matches2)
// || preg_match($expression3, $search, $matches3)
// || preg_match($expression4, $search, $matches4)
// ) {
// $arrayMonth = array(
// 'janvier' => '01',
// 'février' => '02',
// 'mars' => '03',
// 'avril' => '04',
// 'mai' => '05',
// 'juin' => '06',
// 'juillet' => '07',
// 'août' => '08',
// 'septembre' => '09',
// 'octobre' => 10,
// 'novembre' => 11,
// 'décembre' => 12
// );
// if ($matches) {
//
// if (!empty($arrayMonth[$matches[2]])) {
// $monthDigit = $arrayMonth[$matches[2]];
// }
// $dateEN = $matches[3] . '-' . $monthDigit . '-' . $matches[1];
//// echo $dateYYYYMMDD;
// } elseif ($matches2) {
//
// if (!empty($arrayMonth[$matches2[1]])) {
// $monthDigit = $arrayMonth[$matches2[1]];
// }
// $dateEN = $matches2[2] . '-' . $monthDigit;
//// echo $dateYYYYMMDD;
// }
// elseif ($matches3) {
// $dateEN = $matches3[3] . '-' . $matches3[2] . '-' . $matches3[1] ;
// }elseif ($matches4) {
// $dateEN = $matches4[2] . '-' . $matches4[1] ;
// }
//// echo $dateYYYYMM;
//// echo $matches[3] . '-' . $matches[2] . '-' . $matches[1];
//// echo $matches2[2] . '-' . $monthDigit;
//// echo $dateEN;
//
// if (!empty($dateEN)) {
//
//// echo $dateEN;
// $query->orWhere('c.dateInscription LIKE :searchDate')
// ->setParameter('searchDate', '%' . $dateEN . '%');
//
// }
//
//
// }
// }
// else {
// $query->orWhere('c.code LIKE :search')
// ->orWhere('c.dateCreation LIKE :search')
// ->orWhere('p.nom LIKE :search')
// ->orWhere('pa.email LIKE :search')
// ->orWhere('st.statut LIKE :search')
// ->setParameter('search', '%' . $search . '%');
// }
// }
// }
//
// if ($onlyPublished) {
// $query->andWhere('st.id = :publish')
// ->setParameter('publish', 1);
// }
// $query->andWhere('pa.email != :empty')
// ->setParameter('empty', '');
// $arrayOfTests = $query->getQuery()
// ->getResult();
//
//// \Doctrine\Common\Util\Debug::dump($arrayOfTests[0]);
//
// if ($pagination === true) {
// $paginatorAdapter = new ArrayAdapter($arrayOfTests);
// return new Paginator($paginatorAdapter);
// } else {
// return $arrayOfTests;
// }
// }
public function findByUser($user) {
$er = $this->em->getRepository($this->entityClass);
return $er->findOneByUser($user);
}
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;
}
}