Commit 45bb6564 authored by Mat's avatar Mat

wip.. tente sans succès d'implémenter une extension à Doctrine

* source: https://github.com/beberlei/DoctrineExtensions
parent 07fced54
......@@ -64,6 +64,9 @@ doctrine:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
string_functions:
field: PotageBundle\Query\Mysql\Field
# Swiftmailer Configuration
swiftmailer:
......
<?php
namespace PotageBundle\Query\Mysql;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
/**
* @author Jeremy Hicks <jeremy.hicks@gmail.com>
*/
class Field extends FunctionNode
{
private $field = null;
private $values = [];
/**
* @param Parser $parser
* @throws \Doctrine\ORM\Query\QueryException
*/
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
// Do the field.
$this->field = $parser->ArithmeticPrimary();
// Add the strings to the values array. FIELD must
// be used with at least 1 string not including the field.
$lexer = $parser->getLexer();
while (count($this->values) < 1 ||
$lexer->lookahead['type'] != Lexer::T_CLOSE_PARENTHESIS) {
$parser->match(Lexer::T_COMMA);
$this->values[] = $parser->ArithmeticPrimary();
}
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
/**
* @param SqlWalker $sqlWalker
* @return string
*/
public function getSql(SqlWalker $sqlWalker)
{
$query = 'FIELD(';
$query .= $this->field->dispatch($sqlWalker);
$query .= ', ';
for ($i = 0; $i < count($this->values); $i++) {
if ($i > 0) {
$query .= ', ';
}
$query .= $this->values[$i]->dispatch($sqlWalker);
}
$query .= ')';
return $query;
}
}
......@@ -68,23 +68,27 @@ class OffreLegumesRepository extends \Doctrine\ORM\EntityRepository
* @param $id_offre = '22'
* @param $sorted = '20,26,22,27,45,46'
*
*/
//1
$qb = $this->createQueryBuilder('ol')
->select(
'ol.id', 'ol.nom', 'ol.description', 'ol.origine', 'ol.image',
'ol.quantiteMin', 'ol.quantiteMax', 'ol.quantiteStep', 'ol.prixUnitaire', 'ol.unite',
':sorted AS HIDDEN field'
'ol.quantiteMin', 'ol.quantiteMax', 'ol.quantiteStep', 'ol.prixUnitaire', 'ol.unite'
)
->where('ol.offre = :id_offre')
->orderBy('field')
->add('orderBy',
$qb->expr()->field('ol.id', ':sorted')
)
//->orderBy(FIELD( ol.id, :sorted))
->setParameters(array(
':id_offre' => $id_offre,
':sorted' => 'FIELD( ol.id, '. $sorted .')'
':sorted' => $sorted
))
;
return $qb->getQuery()->getResult();
/*
//2
return $this
->getEntityManager()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment