Nice hack in the advmultiselect in order to filter selects see BT#5768

skala
Julio Montoya 12 years ago
parent 8fd11797d8
commit c1a649d22e
  1. 1
      main/group/group_edit.php
  2. 5
      main/inc/lib/pear/HTML/QuickForm/advmultiselect.php
  3. 3
      main/template/default/learnpath/subscribe_users.tpl
  4. 59
      src/ChamiloLMS/Controller/LearnpathController.php

@ -158,7 +158,6 @@ $selected_tutors = array();
foreach ($group_tutor_list as $index => $user) {
$selected_tutors[] = $user['user_id'];
}
$group_tutors_element = $form->addElement('advmultiselect', 'group_tutors', get_lang('GroupTutors'), $possible_users);
$group_tutors_element->setButtonAttributes('add');
$group_tutors_element->setButtonAttributes('remove');

@ -645,7 +645,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$tabs = $this->_getTabs();
$tab = $this->_getTab();
$selectId = $this->getName();
$selectName = $this->getName().'[]';
$selectNameFrom = $this->getName().'-f[]';
@ -794,6 +793,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
// prepare option tables to be displayed as in POST order
$append = count($this->_values);
if ($append > 0) {
$arrHtmlSelected = array_fill(0, $append, ' ');
} else {
@ -806,6 +806,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$arrHtmlHidden = array_fill(0, $options, ' ');
foreach ($this->_options as $option) {
if (is_array($this->_values)
&& in_array(
(string)$option['attr']['value'],
@ -875,8 +876,10 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
= array_merge($this->_attributes, $this->_attributesSelected);
$attrSelected = $this->_getAttrString($this->_attributesSelected);
}
$strHtmlSelected = "<select$attrSelected>".PHP_EOL;
if ($selected_count > 0) {
foreach ($arrHtmlSelected as $data) {
$strHtmlSelected
.= $tabs.$tab

@ -1,5 +1,6 @@
{% extends "default/layout/layout_1_col.tpl" %}
{% block content %}
{#
<h2>{{ 'SubscribeUsersToLp' | get_lang }}</h2>
<script>
$().ready(function() {
@ -42,4 +43,6 @@
</div>
{{ form_rest(form) }}
</form>
#}
{{ form }}
{% endblock %}

@ -20,6 +20,8 @@ class LearnpathController {
$courseCode = api_get_course_id();
$lp = new \learnpath($courseCode, $lpId, api_get_user_id());
$url = $app['url_generator']->generate('subscribe_users', array('lpId' => $lpId));
$breadcrumb = array(
array('url' => api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?action=list', 'name' => get_lang('LearningPaths')),
array('url' => api_get_path(WEB_CODE_PATH)."newscorm/lp_controller.php?action=build&lp_id=".$lp->get_id(), 'name' => $lp->get_name()),
@ -53,24 +55,35 @@ class LearnpathController {
foreach ($subscribedUsersInLp as $itemProperty) {
$userId = $itemProperty->getToUserId();
$user = $app['orm.em']->getRepository('Entity\EntityUser')->find($userId);
$selectedChoices[$user->getUserId()] = $user->getCompleteName();
//$selectedChoices[$user->getUserId()] = $user->getCompleteName();
$selectedChoices[] = $user->getUserId();
if (isset($choices[$user->getUserId()])) {
unset($choices[$user->getUserId()]);
//unset($choices[$user->getUserId()]);
}
}
$form = $app['form.factory']->createBuilder('form')
$form = new \FormValidator('lp_edit', 'post', $url);
$form->addElement('header', get_lang('SubscribeUsersToLp'));
$group_tutors_element = $form->addElement('advmultiselect', 'users', get_lang('Users'), $choices);
$group_tutors_element->setButtonAttributes('add');
$group_tutors_element->setButtonAttributes('remove');
// submit button
$form->addElement('style_submit_button', 'submit', get_lang('Save'), 'class="save"');
/*$form = $app['form.factory']->createBuilder('form')
->add('origin', 'choice', array(
'label' => get_lang('Origin'),
'multiple' => true,
'required' => false,
'expanded' => false,
/*'class' => 'Entity\EntityCourse',
'property' => 'complete_name',
'query_builder' => function(\Entity\Repository\CourseRepository $repo) use ($course) {
//'class' => 'Entity\EntityCourse',
//'property' => 'complete_name',
//'query_builder' => function(\Entity\Repository\CourseRepository $repo) use ($course) {
$repo = $repo->getSubscribedStudents($course);
return $repo;
},*/
},
'choices' => $choices
))
->add('destination', 'choice', array(
@ -78,28 +91,34 @@ class LearnpathController {
'multiple' => true,
'expanded' => false,
'required' => false,
/*'class' => 'Entity\EntityCourse',
'property' => 'complete_name',
'query_builder' => function(\Entity\Repository\CourseRepository $repo) use ($course) {
return $repo->getSubscribedStudents($course);
},*/
//'class' => 'Entity\EntityCourse',
//'property' => 'complete_name',
//'query_builder' => function(\Entity\Repository\CourseRepository $repo) use ($course) {
// return $repo->getSubscribedStudents($course);
//},
'choices' => $selectedChoices
))
->getForm();
*/
if (!empty($selectedChoices)) {
$defaults['users'] = $selectedChoices;
$form->setDefaults($defaults);
}
if ($request->getMethod() == 'POST') {
$form->bind($request);
//$form->bind($request);
//$data = $form->getData();
$data = $request->get('form');
$destination = isset($data['destination']) ? $data['destination'] : array();
$app['orm.em']->getRepository('Entity\EntityCItemProperty')->SubscribedUsersToItem('learnpath', $course, $sessionId, $lpId, $destination);
return $app->redirect($app['url_generator']->generate('subscribe_users', array ('lpId' => $lpId)));
//var_dump($request->request);exit;
$users = $request->get('users');
//$destination = isset($data['destination']) ? $data['destination'] : array();
$app['orm.em']->getRepository('Entity\EntityCItemProperty')->SubscribedUsersToItem('learnpath', $course, $sessionId, $lpId, $users);
return $app->redirect($url);
} else {
$app['template']->assign('form', $form->createView());
$app['template']->assign('form', $form->toHtml());
}
$response = $app['template']->render_template('learnpath/subscribe_users.tpl');
//return new Response($response, 200, array('Cache-Control' => 's-maxage=3600, private'));
$response = $app['template']->render_template('learnpath/subscribe_users.tpl');
return new Response($response, 200, array());
}
}
Loading…
Cancel
Save