- {% if is_granted('ROLE_ADMIN') %}
-
+ {% if is_granted('ROLE_ADMIN') and isAllowed %}
+
{% endif %}
Trayectoria
@@ -112,14 +136,15 @@ function saveAll() {
{% for subcategory in categories %}
{% if subcategory.lvl == 0 %}
-
{{ subcategory.title }}
-
+ {#
{{ subcategory.title }}
+
#}
{% else %}
{{ subcategory.title }}
{% endif %}
{% for item in subcategory.items %}
-
{{ item.title }} (item) - Max {{ item.maxRepeat }}
+ {# Items #}
+ {{ item.title }} (item) - {{ 'CurriculumMaximumItem' | trans }} {{ item.maxRepeat }}
{{ form_start(form_list[item.id]) }}
@@ -127,15 +152,12 @@ function saveAll() {
{% for widget in form_list[item.id].userItems.children %}
{{ _self.widget_prototype(widget, 'Remove item') }}
{% endfor %}
-
- {# form_widget(form_list[item.id].submit) #}
-
{% if item.maxRepeat > 1 %}
{% endif %}
@@ -144,7 +166,6 @@ function saveAll() {
{{ form_end(form_list[item.id]) }}
{% endfor %}
-
{% endfor %}
diff --git a/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumCategoryController.php b/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumCategoryController.php
index a50a4cb1cd..7d5a0ce525 100644
--- a/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumCategoryController.php
+++ b/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumCategoryController.php
@@ -99,6 +99,8 @@ class CurriculumCategoryController extends CommonController
$this->get('template')->assign('tree', $htmlTree);
$this->get('template')->assign('links', $this->generateLinks());
+ $this->get('template')->assign('isAllowed', api_is_allowed_to_edit(true, true, true));
+
$response = $this->get('template')->render_template($this->getTemplatePath().'list.tpl');
return new Response($response, 200, array());
@@ -269,6 +271,95 @@ class CurriculumCategoryController extends CommonController
return parent::deleteAction($id);
}
+ /**
+ *
+ * @Route("/results")
+ * @Method({"GET"})
+ */
+ public function resultsAction()
+ {
+ $breadcrumbs = array(
+ array(
+ 'name' => get_lang('Curriculum'),
+ 'url' => array(
+ 'route' => 'curriculum_user.controller:indexAction',
+ 'routeParameters' => array(
+ 'course' => $this->getCourse()->getCode()
+ )
+ )
+ ),
+ array(
+ 'name' => get_lang('Categories'),
+ 'url' => array(
+ 'route' => 'curriculum_category.controller:indexAction',
+ 'routeParameters' => array(
+ 'course' => $this->getCourse()->getCode()
+ )
+ )
+
+ ),
+ array(
+ 'name' => get_lang('Results'),
+ )
+ );
+ $this->setBreadcrumb($breadcrumbs);
+ if (!api_is_allowed_to_edit(true, true, true)) {
+ $this->abort('405');
+ }
+
+ $session = $this->getSession();
+ $sessionId = 0;
+ if ($session) {
+ $sessionId = $this->getSession()->getId();
+ }
+
+ // @todo move in a function
+ $users = \CourseManager::get_user_list_from_course_code(
+ $this->getCourse()->getCode(),
+ $sessionId,
+ null,
+ null,
+ STUDENT
+ );
+
+ $qb = $this->getManager()
+ ->createQueryBuilder()
+ ->select('node.id, u.userId, SUM(i.score) as score')
+ ->from('Entity\CurriculumCategory', 'node')
+ ->innerJoin('node.course', 'c')
+ ->innerJoin('node.items', 'i')
+ ->innerJoin('i.userItems', 'u')
+ ->groupby('u.userId') ;
+ $this->setCourseParameters($qb, 'node');
+ $query = $qb->getQuery();
+ $userResults = $query->getResult();
+
+ $userResultsByUserId = array();
+ if (!empty($userResults)) {
+ foreach ($userResults as $item) {
+ $userResultsByUserId[$item['userId']] = $item['score'];
+ }
+ }
+
+ if (!empty($users)) {
+ foreach ($users as &$user) {
+ if (!empty($userResultsByUserId)) {
+ if (isset($userResultsByUserId[$user['user_id']])) {
+ $user['score'] = $userResultsByUserId[$user['user_id']];
+ } else {
+ $user['score'] = 0;
+ }
+ }
+ }
+ }
+
+ $template = $this->getTemplate();
+ $template->assign('users', $users);
+
+ $response = $template->render_template($this->getTemplatePath().'results.tpl');
+ return new Response($response, 200, array());
+ }
+
protected function getControllerAlias()
{
return 'curriculum_category.controller';
diff --git a/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumItemController.php b/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumItemController.php
index 662d355e96..a3bb0d419a 100644
--- a/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumItemController.php
+++ b/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumItemController.php
@@ -26,6 +26,31 @@ class CurriculumItemController extends CommonController
*/
public function indexAction()
{
+ $breadcrumbs = array(
+ array(
+ 'name' => get_lang('Curriculum'),
+ 'url' => array(
+ 'route' => 'curriculum_user.controller:indexAction',
+ 'routeParameters' => array(
+ 'course' => $this->getCourse()->getCode()
+ )
+ )
+ ),
+ array(
+ 'name' => get_lang('Categories'),
+ 'url' => array(
+ 'route' => 'curriculum_category.controller:indexAction',
+ 'routeParameters' => array(
+ 'course' => $this->getCourse()->getCode()
+ )
+ )
+
+ ),
+ array(
+ 'name' => get_lang('List')
+ )
+ );
+ $this->setBreadcrumb($breadcrumbs);
return parent::listingAction();
}
diff --git a/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumUserController.php b/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumUserController.php
index 5369f6002d..af2b8a3eeb 100644
--- a/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumUserController.php
+++ b/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumUserController.php
@@ -51,16 +51,18 @@ class CurriculumUserController extends CommonController
$this->setBreadcrumb($breadcrumbs);
+ $userId = $this->getUser()->getUserId();
+
$qb = $this->getManager()
->createQueryBuilder()
- ->select('node, i')
+ ->select('node, i, u')
->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()))
+ ->leftJoin('node.items', 'i')
+ ->leftJoin('i.userItems', 'u', 'WITH', 'u.userId = :userId OR u.userId IS NULL')
+ //->where('u.userId = :userId or u.userId IS NULL')
+ //->orWhere('u.userId IS NULL')
+ ->setParameter('userId', $userId)
->orderBy('node.root, node.lft, node.title', 'ASC');
$this->setCourseParameters($qb, 'node');
$query = $qb->getQuery();
@@ -71,11 +73,15 @@ class CurriculumUserController extends CommonController
/** @var \Entity\CurriculumCategory $category */
foreach ($categories as $category) {
+
/** @var \Entity\CurriculumItem $item */
+
foreach ($category->getItems() as $item) {
+
$formType = new CurriculumItemRelUserCollectionType($item->getId());
$count = count($item->getUserItems());
+
// If there are no items for the user, then create a new one!
if ($count == 0) {
$userItem = new Entity\CurriculumItemRelUser();
@@ -85,7 +91,6 @@ class CurriculumUserController extends CommonController
);
$item->setUserItems($userItemList);
}
-
$form = $this->get('form.factory')->create($formType, $item);
$formList[$item->getId()] = $form->createView();
}
@@ -98,6 +103,7 @@ class CurriculumUserController extends CommonController
$this->get('template')->assign('categories', $categories);
$this->get('template')->assign('links', $this->generateLinks());
$this->get('template')->assign('form_list', $formList);
+ $this->get('template')->assign('isAllowed', api_is_allowed_to_edit(true, true, true));
$response = $this->get('template')->render_template($this->getTemplatePath().'list.tpl');
return new Response($response, 200, array());
@@ -223,6 +229,91 @@ class CurriculumUserController extends CommonController
return new Response($response, 200, array());
}
+ /**
+ *
+ * @Route("{userId}/get-user-items")
+ * @Method({"GET"})
+ */
+ public function getUserItemsAction($userId)
+ {
+ $breadcrumbs = array(
+ array(
+ 'name' => get_lang('Curriculum'),
+ 'url' => array(
+ 'route' => 'curriculum_user.controller:indexAction',
+ 'routeParameters' => array(
+ 'course' => $this->getCourse()->getCode()
+ )
+ )
+ ),
+ array(
+ 'name' => get_lang('Categories'),
+ 'url' => array(
+ 'route' => 'curriculum_category.controller:indexAction',
+ 'routeParameters' => array(
+ 'course' => $this->getCourse()->getCode()
+ )
+ )
+
+ ),
+ array(
+ 'name' => get_lang('Results'),
+ 'url' => array(
+ 'route' => 'curriculum_category.controller:resultsAction',
+ 'routeParameters' => array(
+ 'course' => $this->getCourse()->getCode()
+ )
+ )
+ ),
+ array(
+ 'name' => get_lang('UserResults'),
+ )
+ );
+ $this->setBreadcrumb($breadcrumbs);
+
+ if (!api_is_allowed_to_edit()) {
+ return $this->abort(403);
+ }
+
+ $qb = $this->getManager()
+ ->createQueryBuilder()
+ ->select('node, i, u')
+ ->from('Entity\CurriculumCategory', 'node')
+ ->innerJoin('node.course', 'c')
+ ->leftJoin('node.items', 'i')
+ ->leftJoin('i.userItems', 'u', 'WITH', 'u.userId = :userId OR u.userId IS NULL')
+ ->setParameter('userId', $userId)
+ ->orderBy('node.root, node.lft, node.title', 'ASC');
+ $this->setCourseParameters($qb, 'node');
+ $query = $qb->getQuery();
+
+ $categories = $query->getResult();
+
+ foreach ($categories as $category) {
+ /** @var \Entity\CurriculumItem $item */
+ $score = 0;
+ foreach ($category->getItems() as $item) {
+
+ $formType = new CurriculumItemRelUserCollectionType($item->getId());
+ $form = $this->get('form.factory')->create($formType, $item, array('disabled' => true));
+ $formList[$item->getId()] = $form->createView();
+
+ foreach ($item->getUserItems() as $userItem) {
+ $score += $item->getScore();
+ }
+ $categoryScore[$item->getCategoryId()] = $score;
+ }
+ }
+
+ $this->get('template')->assign('categories', $categories);
+ $this->get('template')->assign('category_score', $categoryScore);
+ $this->get('template')->assign('form_list', $formList);
+ $this->get('template')->assign('isAllowed', api_is_allowed_to_edit(true, true, true));
+
+ $response = $this->get('template')->render_template($this->getTemplatePath().'get_user_items.tpl');
+ return new Response($response, 200, array());
+ }
+
/**
* @param Entity\CurriculumItemRelUser $object
* @return JsonResponse
diff --git a/src/ChamiloLMS/Form/CurriculumItemType.php b/src/ChamiloLMS/Form/CurriculumItemType.php
index 3fb6a5bb24..8d9bdcb37e 100644
--- a/src/ChamiloLMS/Form/CurriculumItemType.php
+++ b/src/ChamiloLMS/Form/CurriculumItemType.php
@@ -17,7 +17,7 @@ class CurriculumItemType extends AbstractType
$parentIdDisabled = true;
}*/
- $builder->add('title', 'text');
+ $builder->add('title', 'textarea');
$builder->add('score', 'text');
$builder->add('max_repeat', 'text');