Browse Source

Using setCourseParameters() in order to modify the query builder to inject course and session conditions.

Julio Montoya 11 years ago
parent
commit
f9e4145fa5

+ 5 - 4
src/ChamiloLMS/Controller/BaseController.php

@@ -367,17 +367,18 @@ abstract class BaseController extends FlintController
 
     /**
      * @param \Doctrine\ORM\QueryBuilder $qb
+     * @param string
      */
-    protected function setCourseParameters(\Doctrine\ORM\QueryBuilder & $qb)
+    protected function setCourseParameters(\Doctrine\ORM\QueryBuilder & $qb, $prefix)
     {
         $course = $this->getCourse();
         if ($course) {
-            $qb->andWhere('e.cId = :id');
-            $qb->setParameter('session_id', $course->getId());
+            $qb->andWhere($prefix.'.cId = :id');
+            $qb->setParameter('id', $course->getId());
 
             $session = $this->getSession();
             if (!empty($session)) {
-                $qb->andWhere('e.cId = :session_id');
+                $qb->andWhere($prefix.'.sessionId = :session_id');
                 $qb->setParameter('session_id', $session->getId());
             }
         }

+ 0 - 7
src/ChamiloLMS/Controller/Tool/CourseController.php

@@ -1,8 +1 @@
 <?php
-/**
- * Created by JetBrains PhpStorm.
- * User: jmontoya
- * Date: 7/18/13
- * Time: 11:38 AM
- * To change this template use File | Settings | File Templates.
- */

+ 4 - 6
src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumCategoryController.php

@@ -70,22 +70,20 @@ class CurriculumCategoryController extends CommonController
         // @todo put this in a function
         $repo = $this->getRepository();
 
-        $parameters = array('id' => $course->getId());
         $qb = $this->getManager()
             ->createQueryBuilder()
             ->select('node, i')
             ->from('Entity\CurriculumCategory', 'node')
             ->leftJoin('node.items', 'i')
             ->innerJoin('node.course', 'c')
-            ->where('node.cId = :id')
             ->orderBy('node.root, node.lft', 'ASC');
 
-        if (!empty($session)) {
+        $this->setCourseParameters($qb, 'node');
+
+        /*if (!empty($session)) {
             $qb->andWhere('node.sessionId = :session_id');
             $parameters['session_id'] = $session->getId();
-        }
-
-        $qb->setParameters($parameters);
+        }*/
 
         $query = $qb->getQuery();
 

+ 8 - 6
src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumUserController.php

@@ -39,18 +39,20 @@ class CurriculumUserController extends CommonController
         $course = $this->getCourse();
         $session = $this->getSession();
 
-        $query = $this->getManager()
+        $qb = $this->getManager()
             ->createQueryBuilder()
             ->select('node, i')
             ->from('Entity\CurriculumCategory', 'node')
             ->leftJoin('node.items', 'i')
             ->leftJoin('i.userItems', 'u')
             ->innerJoin('node.course', 'c')
-            ->where('node.cId = :id')
-            ->andWhere('node.sessionId = :session_id')
-            ->setParameters(array('id' => $course->getId(), 'session_id' => $session->getId()))
-            ->orderBy('node.root, node.lft, node.title', 'ASC')
-            ->getQuery();
+            //->where('node.cId = :id')
+            //->andWhere('node.sessionId = :session_id')
+            //->setParameters(array('id' => $course->getId(), 'session_id' => $session->getId()))
+            ->orderBy('node.root, node.lft, node.title', 'ASC');
+        $this->setCourseParameters($qb, 'node');
+        $query = $qb->getQuery();
+
 
         $categories = $query->getResult();