|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = array(); |
|
|
$response = array(); |
|
|
foreach ($values as $value) { |
|
|
foreach ($values as $value) { |
|
|
$response[] = $value[$field]; |
|
|
|
|
|
|
|
|
$response[] = $value[$this->utils->getFilterWithoutAssociationAlias($field, '_')]; |
|
|
} |
|
|
} |
|
|
return new JsonResponse($response); |
|
|
return new JsonResponse($response); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($pos = strpos($dqlFilter, 'TODAYSTART')) { |
|
|
if ($pos = strpos($dqlFilter, 'TODAYSTART')) { |
|
|
$date = new \DateTime(); |
|
|
$date = new \DateTime(); |
|
|
$dqlFilter = sprintf(str_replace('TODAYSTART', $date->format('Y-m-d').' 00:00:00', $dqlFilter)); |
|
|
|
|
|
|
|
|
$dqlFilter = sprintf(str_replace('TODAYSTART', $date->format('Y-m-d') . ' 00:00:00', $dqlFilter)); |
|
|
} |
|
|
} |
|
|
if ($pos = strpos($dqlFilter, 'TODAYEND')) { |
|
|
if ($pos = strpos($dqlFilter, 'TODAYEND')) { |
|
|
$date = new \DateTime(); |
|
|
$date = new \DateTime(); |
|
|
$dqlFilter = sprintf(str_replace('TODAYEND', $date->format('Y-m-d').' 23:59:59', $dqlFilter)); |
|
|
|
|
|
|
|
|
$dqlFilter = sprintf(str_replace('TODAYEND', $date->format('Y-m-d') . ' 23:59:59', $dqlFilter)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($pos = strpos($dqlFilter, 'sectionLunch')) { |
|
|
if ($pos = strpos($dqlFilter, 'sectionLunch')) { |
|
|
|
|
|
|
|
|
$this->filtersForm->handleRequest($this->request); |
|
|
$this->filtersForm->handleRequest($this->request); |
|
|
$easyadmin = $this->request->attributes->get('easyadmin'); |
|
|
$easyadmin = $this->request->attributes->get('easyadmin'); |
|
|
$view = $easyadmin['view']; |
|
|
$view = $easyadmin['view']; |
|
|
if($easyadmin['view']=='listChildren') $view = 'list'; |
|
|
|
|
|
if (($this->filtersForm->isSubmitted() && $this->filtersForm->isValid()) || $this->entity[$view]['filters']!==false) { |
|
|
|
|
|
|
|
|
if ($easyadmin['view'] == 'listChildren') $view = 'list'; |
|
|
|
|
|
if (($this->filtersForm->isSubmitted() && $this->filtersForm->isValid()) || $this->entity[$view]['filters'] !== false) { |
|
|
foreach ($listFields as $field) { |
|
|
foreach ($listFields as $field) { |
|
|
|
|
|
$field['initProperty'] = $field['property']; |
|
|
|
|
|
$field['property'] = $this->utils->getFilterPropertyClean($field['property']); |
|
|
//if ($this->filtersForm->has($field['property'])->getConfig()->getOption('AdminController')) { |
|
|
//if ($this->filtersForm->has($field['property'])->getConfig()->getOption('AdminController')) { |
|
|
if ($this->filtersForm->has($field['property'])) { |
|
|
if ($this->filtersForm->has($field['property'])) { |
|
|
switch ($field['dataType']) { |
|
|
switch ($field['dataType']) { |
|
|
|
|
|
|
|
|
$filter = $this->getListFilterParam($field['property']); |
|
|
$filter = $this->getListFilterParam($field['property']); |
|
|
//$filter = $this->filtersForm->get($field['property'])->getData(); |
|
|
//$filter = $this->filtersForm->get($field['property'])->getData(); |
|
|
if ($filter !== null) { |
|
|
if ($filter !== null) { |
|
|
|
|
|
if ($this->utils->hasFilterAssociation($field['initProperty'])) { |
|
|
|
|
|
$aliasRelation = $this->utils->getFilterAssociationAlias($field['initProperty']); |
|
|
|
|
|
if(array_search($aliasRelation, $queryBuilder->getAllAliases())===false){ |
|
|
|
|
|
$queryBuilder->innerJoin('entity.'.$aliasRelation, $aliasRelation); |
|
|
|
|
|
} |
|
|
|
|
|
$queryBuilder->andWhere($field['initProperty'] . ' LIKE :' . $field['property'] . ''); |
|
|
|
|
|
$queryBuilder->setParameter($field['property'], '%' . $filter . '%'); |
|
|
|
|
|
} else { |
|
|
|
|
|
$queryBuilder->andWhere('entity.' . $field['property'] . ' LIKE :' . $field['property'] . ''); |
|
|
|
|
|
$queryBuilder->setParameter($field['property'], '%' . $filter . '%'); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$queryBuilder->andWhere('entity.' . $field['property'] . ' LIKE :' . $field['property'] . ''); |
|
|
|
|
|
$queryBuilder->setParameter($field['property'], '%' . $filter . '%'); |
|
|
|
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case 'association' : |
|
|
case 'association' : |
|
|
$filter = $this->getListFilterParam($field['property']); |
|
|
$filter = $this->getListFilterParam($field['property']); |
|
|
//$filter = $this->filtersForm->get($field['property'])->getData(); |
|
|
|
|
|
|
|
|
//$filter = $this->filtersForm->get($field['property'])->getData(); |
|
|
if ($filter !== null) { |
|
|
if ($filter !== null) { |
|
|
if ($field['type_options']['multiple']) { |
|
|
|
|
|
$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . ''); |
|
|
|
|
|
} else { |
|
|
|
|
|
$queryBuilder->andWhere('entity.' . $field['property'] . ' = :' . $field['property'] . ''); |
|
|
|
|
|
} |
|
|
|
|
|
if ($filter instanceof TreeInterface && $filter->getParent() == null) { |
|
|
|
|
|
$queryBuilder->setParameter($field['property'], array_merge(array($filter), $filter->getChildrens()->toArray())); |
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO Faut généraliser avec TreeInterface, ça ne doit pas être ici |
|
|
|
|
|
if($field['property'] == 'productCategories') { |
|
|
|
|
|
|
|
|
|
|
|
$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'].' OR product_categories.parent = :' . $field['property']); |
|
|
$queryBuilder->setParameter($field['property'], $filter); |
|
|
$queryBuilder->setParameter($field['property'], $filter); |
|
|
} |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if ($field['type_options']['multiple']) { |
|
|
|
|
|
$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . ''); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$queryBuilder->andWhere('entity.' . $field['property'] . ' = :' . $field['property'] . ''); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($filter instanceof TreeInterface && $filter->getParent() == null) { |
|
|
|
|
|
$queryBuilder->setParameter($field['property'], array_merge(array($filter), $filter->getChildrens()->toArray())); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$queryBuilder->setParameter($field['property'], $filter); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case 'datetime': |
|
|
case 'datetime': |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//TODO déplacer dans LC |
|
|
//TODO déplacer dans LC |
|
|
if($this->entity['name']== 'OrderShopLunch' || $this->entity['name']== 'OrderShopLunchDay'){ |
|
|
|
|
|
|
|
|
if ($this->entity['name'] == 'OrderShopLunch' || $this->entity['name'] == 'OrderShopLunchDay') { |
|
|
$queryBuilder->addOrderBy('entity.user', 'asc'); |
|
|
$queryBuilder->addOrderBy('entity.user', 'asc'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO finaliser la sauvegarde des filtres |
|
|
//TODO finaliser la sauvegarde des filtres |
|
|
|
|
|
|
|
|
protected function getListFilterParam($param, $extraParam = null){ |
|
|
|
|
|
|
|
|
protected function getListFilterParam($param, $extraParam = null) |
|
|
|
|
|
{ |
|
|
$entityName = $this->entity['name']; |
|
|
$entityName = $this->entity['name']; |
|
|
$sessionParam = $entityName.$param.$extraParam; |
|
|
|
|
|
|
|
|
$sessionParam = $entityName . $param . $extraParam; |
|
|
//CUSTOM |
|
|
//CUSTOM |
|
|
if($extraParam){ |
|
|
|
|
|
|
|
|
if ($extraParam) { |
|
|
$value = $this->filtersForm->get($param)->get($extraParam)->getViewData(); |
|
|
$value = $this->filtersForm->get($param)->get($extraParam)->getViewData(); |
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
$value = $this->filtersForm->get($param)->getViewData(); |
|
|
$value = $this->filtersForm->get($param)->getViewData(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($this->request->query->get('filterClear')){ |
|
|
|
|
|
|
|
|
if ($this->request->query->get('filterClear')) { |
|
|
$this->session->remove($sessionParam); |
|
|
$this->session->remove($sessionParam); |
|
|
}else { |
|
|
|
|
|
|
|
|
} else { |
|
|
if ($value) { |
|
|
if ($value) { |
|
|
$this->session->set($sessionParam, $value); |
|
|
$this->session->set($sessionParam, $value); |
|
|
} else if ($this->session->get($sessionParam) && !$this->filtersForm->isSubmitted() && $this->filtersForm->get($param)) { |
|
|
} else if ($this->session->get($sessionParam) && !$this->filtersForm->isSubmitted() && $this->filtersForm->get($param)) { |
|
|
$value = $this->session->get($sessionParam); |
|
|
$value = $this->session->get($sessionParam); |
|
|
|
|
|
|
|
|
if($extraParam){ |
|
|
|
|
|
|
|
|
if ($extraParam) { |
|
|
|
|
|
|
|
|
if($this->filtersForm->get($param)->get($extraParam)->getConfig()->getOption('input')=='datetime'){ |
|
|
|
|
|
|
|
|
if ($this->filtersForm->get($param)->get($extraParam)->getConfig()->getOption('input') == 'datetime') { |
|
|
|
|
|
|
|
|
$this->filtersForm->get($param)->get($extraParam)->setData(new \DateTime($value)); |
|
|
$this->filtersForm->get($param)->get($extraParam)->setData(new \DateTime($value)); |
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
$this->filtersForm->get($param)->get($extraParam)->setData($value); |
|
|
$this->filtersForm->get($param)->get($extraParam)->setData($value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
|
} else { |
|
|
//Champ association |
|
|
//Champ association |
|
|
if ($this->filtersForm->get($param)->getConfig()->getOption('class')) { |
|
|
if ($this->filtersForm->get($param)->getConfig()->getOption('class')) { |
|
|
$valFormated = $this->em->getRepository($this->filtersForm->get($param)->getConfig()->getOption('class'))->find($value); |
|
|
$valFormated = $this->em->getRepository($this->filtersForm->get($param)->getConfig()->getOption('class'))->find($value); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($value !== "")return $value; |
|
|
|
|
|
|
|
|
if ($value !== "") return $value; |
|
|
else return null; |
|
|
else return null; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function renderTemplate($actionName, $templatePath, array $parameters = []) |
|
|
public function renderTemplate($actionName, $templatePath, array $parameters = []) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getListParam($param, $default =null){ |
|
|
|
|
|
|
|
|
protected function getListParam($param, $default = null) |
|
|
|
|
|
{ |
|
|
$entityName = $this->entity['name']; |
|
|
$entityName = $this->entity['name']; |
|
|
$sessionParam = $entityName.$param; |
|
|
|
|
|
|
|
|
$sessionParam = $entityName . $param; |
|
|
//CUSTOM |
|
|
//CUSTOM |
|
|
if($param == 'maxResults'){ |
|
|
|
|
|
$val = $this->entity['list']['max_results']; |
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
|
if ($param == 'maxResults') { |
|
|
|
|
|
$val = $this->entity['list']['max_results']; |
|
|
|
|
|
} else { |
|
|
$val = $this->request->query->get($param, $default); |
|
|
$val = $this->request->query->get($param, $default); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(isset($_GET[$param])){ |
|
|
|
|
|
$val = $this->request->query->get($param); |
|
|
|
|
|
|
|
|
if (isset($_GET[$param])) { |
|
|
|
|
|
$val = $this->request->query->get($param); |
|
|
$this->session->set($sessionParam, $val); |
|
|
$this->session->set($sessionParam, $val); |
|
|
}else if($this->session->get($sessionParam)){ |
|
|
|
|
|
$val = $this->session->get($sessionParam); |
|
|
|
|
|
|
|
|
} else if ($this->session->get($sessionParam)) { |
|
|
|
|
|
$val = $this->session->get($sessionParam); |
|
|
$this->request->query->set($param, $val); |
|
|
$this->request->query->set($param, $val); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fields = $this->entity['list']['fields']; |
|
|
$fields = $this->entity['list']['fields']; |
|
|
|
|
|
|
|
|
$paginator = $this->findAll($this->entity['class'], $this->getListParam('page', 1), $this->getListParam('maxResults'), $this->getListParam('sortField'), $this->getListParam('sortDirection'), $this->entity['list']['dql_filter']); |
|
|
|
|
|
|
|
|
$paginator = $this->findAll($this->entity['class'], $this->getListParam('page', 1), $this->getListParam('maxResults'), $this->getListParam('sortField'), $this->getListParam('sortDirection'), $this->entity['list']['dql_filter']); |
|
|
|
|
|
|
|
|
$this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]); |
|
|
$this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]); |
|
|
|
|
|
|