diff --git a/main/inc/Entity/CurriculumCategory.php b/main/inc/Entity/CurriculumCategory.php index ead4554b93..1420e3a406 100644 --- a/main/inc/Entity/CurriculumCategory.php +++ b/main/inc/Entity/CurriculumCategory.php @@ -143,7 +143,6 @@ class CurriculumCategory $this->session = $session; } - /** * @return mixed */ @@ -161,18 +160,25 @@ class CurriculumCategory $this->course = $course; } - + /** + * @return ArrayCollection + */ public function getItems() { return $this->items; } - + /** + * @param CurriculumCategory $parent + */ public function setParent(CurriculumCategory $parent = null) { $this->parent = $parent; } + /** + * @return CurriculumCategory + */ public function getParent() { return $this->parent; diff --git a/main/inc/Entity/CurriculumItemRelUser.php b/main/inc/Entity/CurriculumItemRelUser.php index 064c4529ad..8ba2659998 100644 --- a/main/inc/Entity/CurriculumItemRelUser.php +++ b/main/inc/Entity/CurriculumItemRelUser.php @@ -66,12 +66,17 @@ class CurriculumItemRelUser */ private $item; - + /** + * @return mixed + */ public function getUser() { return $this->user; } + /** + * @return mixed + */ public function getItem() { return $this->item; @@ -85,6 +90,9 @@ class CurriculumItemRelUser $this->item = $item; } + /** + * @param User $user + */ public function setUser(User $user) { $this->user = $user; diff --git a/main/inc/Entity/CurriculumRelUser.php b/main/inc/Entity/CurriculumRelUser.php index de6855b882..07dd3b0a3f 100644 --- a/main/inc/Entity/CurriculumRelUser.php +++ b/main/inc/Entity/CurriculumRelUser.php @@ -42,7 +42,6 @@ class CurriculumRelUser */ private $score; - /** * Get id * diff --git a/main/template/default/tool/curriculum/category/read.tpl b/main/template/default/tool/curriculum/category/read.tpl index 852492d54f..5ed69901ef 100644 --- a/main/template/default/tool/curriculum/category/read.tpl +++ b/main/template/default/tool/curriculum/category/read.tpl @@ -11,5 +11,4 @@ {% endfor %} - {% endblock %} diff --git a/main/template/default/tool/curriculum/category/results.tpl b/main/template/default/tool/curriculum/category/results.tpl new file mode 100644 index 0000000000..4333e74209 --- /dev/null +++ b/main/template/default/tool/curriculum/category/results.tpl @@ -0,0 +1,17 @@ +{% extends app.template_style ~ "/layout/layout_1_col.tpl" %} +{% block content %} + {{ 'Results' | trans }} +
+ + +{% endblock %} diff --git a/main/template/default/tool/curriculum/user/get_user_items.tpl b/main/template/default/tool/curriculum/user/get_user_items.tpl new file mode 100644 index 0000000000..967e11fbfe --- /dev/null +++ b/main/template/default/tool/curriculum/user/get_user_items.tpl @@ -0,0 +1,61 @@ +{% extends app.template_style ~ "/layout/layout_1_col.tpl" %} + +{% macro widget_prototype(widget, remove_text) %} + {% if widget.get('prototype') %} + {% set form = widget.get('prototype') %} + {% set name = widget.get('prototype').get('description') %} + {% else %} + {% set form = widget %} + {% set name = widget.get('full_name') %} + {% endif %} + +
+ {{ form_widget(form) }} +
+{% endmacro %} + +{% block content %} + + +
+
+

Trayectoria

+

Explicaciones

+

Las respuestas a este formulario son de carácter jurado.

+
+ {% for subcategory in categories %} + {% if subcategory.lvl == 0 %} + {#

{{ subcategory.title }}

+
#} + {% else %} +

+ {{ subcategory.title }} + {% if category_score[subcategory.id] %} +
{{ category_score[subcategory.id] }}
+ {% endif %} +

+ {% endif %} + + {% for item in subcategory.items %} + {# Items #} + {{ item.title }} (item) - {{ 'CurriculumMaximumItem' | trans }} {{ item.maxRepeat }} +
+ {{ form_start(form_list[item.id]) }} +
+ {% for widget in form_list[item.id].userItems.children %} + {{ _self.widget_prototype(widget, 'Remove item') }} + {% endfor %} +
    +
+
+ {{ form_end(form_list[item.id]) }} +
+ {% endfor %} + {% endfor %} +
+
+
+{% endblock %} diff --git a/main/template/default/tool/curriculum/user/list.tpl b/main/template/default/tool/curriculum/user/list.tpl index 7d10d11b81..b6a062e38c 100644 --- a/main/template/default/tool/curriculum/user/list.tpl +++ b/main/template/default/tool/curriculum/user/list.tpl @@ -25,7 +25,6 @@ $(function() { var input = $(this); var removeForm = $(''); - //var id = input.parent().parent().parent().parent().attr('id'); var maxRepeat = input.parent().parent().parent().parent().attr('data-max'); if (maxRepeat != 1) { @@ -33,13 +32,12 @@ $(function() { addTagFormDeleteLink(removeForm); } }); + // Create add buttons: $(".items").each(function(index, value) { var itemId = $(this).attr('id'); var lastInput = $(this).find("input:text").last(); - console.log(lastInput.attr('id')); var addButton = $(''); - //lastInput.parent().append(addButton ); }); // When clicking in the add button: @@ -48,7 +46,15 @@ $(function() { var maxRepeat = collectionHolder.attr('data-max'); var countInput = collectionHolder.find('input:text').length; + // Disables the add button when reached the max count + var showButtonWhenIsHidden = false; + if (countInput > maxRepeat - 2) { + showButtonWhenIsHidden = true; + } + + // Disables the clicking when it's disabled if (countInput > maxRepeat - 1) { + $(this).addClass('disabled'); return false; } @@ -66,44 +72,62 @@ $(function() { liItem.find('.controls').append(removeForm); var item = collectionHolder.find('ul').append(liItem); - addTagFormDeleteLink(removeForm); + if (showButtonWhenIsHidden) { + addTagFormDeleteLink(removeForm, $(this)); + } else { + + addTagFormDeleteLink(removeForm); + } event && event.preventDefault(); }); $('#saveQuestionBar').affix(); }); -function addTagFormDeleteLink($tagFormLi) { +function addTagFormDeleteLink($tagFormLi, showButton) { $tagFormLi.on('click', function(e) { e.preventDefault(); $(this).parent().remove(); + // Restore the add button. + if (showButton) { + showButton.removeClass('disabled'); + } }); } function save(itemId) { var form = $("#"+itemId).parent(); var serializedForm = form.serialize(); - $.post('{{ url('curriculum_user.controller:saveUserItemAction', {'course' : course.code }) }}', serializedForm); - return false; + $.ajax({ + 'url' : '{{ url('curriculum_user.controller:saveUserItemAction', {'course' : course.code, 'id_session' : course_session.id }) }}', + 'data' : serializedForm, + 'async': false, + 'type' : 'post' + } + ); } function saveAll() { var items = $("form").find(".items"); $(items).each(function(index, value) { - var itemId = $(this).attr('id') + var itemId = $(this).attr('id'); save(itemId); }); + window.location = '{{ url('index') }}'; }
- {% 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');