Commit d18bca8d authored by dj3c1t's avatar dj3c1t

SourceRepo orderBy

parent 3aecc197
......@@ -74,8 +74,10 @@ class SourceRepository extends EntityRepository {
$em = $this->getEntityManager();
$dql = "SELECT s FROM Dj3c1tSourceMLBundle:Source s";
$dqlWhere = "";
$orderBy = "";
$order = "";
$orderBy = array(
"s.creationDate" => "DESC",
"s.publicationDate" => "DESC",
);
$dqlParameters = array();
$isReference = isset($params["isReference"]) ? ($params["isReference"] ? true : false) : null;
if(isset($isReference)) {
......@@ -179,8 +181,13 @@ class SourceRepository extends EntityRepository {
($dqlWhere ? " AND " : " WHERE ")
."c.id = :composition";
$dqlParameters["composition"] = $params["composition"];
$orderBy = "sc.position";
$order = "ASC";
if(!isset($orderBy["sc.position"])) {
$_orderBy = array("sc.position" => "ASC");
foreach($orderBy as $orderAttribut => $orderWay) {
$_orderBy[$orderAttribut] = $orderWay;
}
$orderBy = $_orderBy;
}
}
if(isset($params["derivedFrom"])) {
$dql .=" JOIN s.derivationSources ds";
......@@ -189,7 +196,10 @@ class SourceRepository extends EntityRepository {
."ds.url = :derived_from_url";
$dqlParameters["derived_from_url"] = $params["derivedFrom"];
}
$dqlOrderBy = $orderBy ? (" ORDER BY ".$orderBy.($order ? " ".$order : "")." ") : "";
$dqlOrderBy = "";
foreach($orderBy as $orderAttribut => $orderWay) {
$dqlOrderBy .= ($dqlOrderBy ? "," : " ORDER BY ").$orderAttribut." ".$orderWay;
}
return $em->createQuery($dql.$dqlWhere.$dqlOrderBy)->setParameters($dqlParameters);
}
......
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