|
|
@ -1,5 +1,5 @@ |
|
|
|
<?php |
|
|
|
<?php |
|
|
|
|
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
namespace ChamiloLMS\Controller; |
|
|
|
namespace ChamiloLMS\Controller; |
|
|
|
|
|
|
|
|
|
|
|
use Silex\Application; |
|
|
|
use Silex\Application; |
|
|
@ -8,10 +8,10 @@ use Symfony\Component\HttpFoundation\Response; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Class LearnpathController |
|
|
|
* Class LearnpathController |
|
|
|
* @package ChamiloLMS\Controller |
|
|
|
* @package ChamiloLMS\Controller |
|
|
|
|
|
|
|
* @author Julio Montoya <gugli100@gmail.com> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class LearnpathController |
|
|
|
class LearnpathController |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Index |
|
|
|
* Index |
|
|
|
* |
|
|
|
* |
|
|
@ -25,11 +25,21 @@ class LearnpathController |
|
|
|
public function indexAction(Application $app, $lpId) |
|
|
|
public function indexAction(Application $app, $lpId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$request = $app['request']; |
|
|
|
$request = $app['request']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$courseId = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@todo use the before filter to aborts this course calls |
|
|
|
|
|
|
|
if (empty($courseId)) { |
|
|
|
|
|
|
|
$app->abort(403, 'Course not available'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$courseCode = api_get_course_id(); |
|
|
|
$courseCode = api_get_course_id(); |
|
|
|
|
|
|
|
|
|
|
|
$lp = new \learnpath($courseCode, $lpId, api_get_user_id()); |
|
|
|
$lp = new \learnpath($courseCode, $lpId, api_get_user_id()); |
|
|
|
|
|
|
|
|
|
|
|
$url = $app['url_generator']->generate('subscribe_users', array('lpId' => $lpId)); |
|
|
|
$url = $app['url_generator']->generate('subscribe_users', array('lpId' => $lpId)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Setting breadcrumb @todo move this in the template lib |
|
|
|
$breadcrumb = array( |
|
|
|
$breadcrumb = array( |
|
|
|
array( |
|
|
|
array( |
|
|
|
'url' => api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?action=list', |
|
|
|
'url' => api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?action=list', |
|
|
@ -44,51 +54,64 @@ class LearnpathController |
|
|
|
|
|
|
|
|
|
|
|
$app['breadcrumb'] = $breadcrumb; |
|
|
|
$app['breadcrumb'] = $breadcrumb; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Find session |
|
|
|
$sessionId = api_get_session_id(); |
|
|
|
$sessionId = api_get_session_id(); |
|
|
|
|
|
|
|
|
|
|
|
$session = null; |
|
|
|
$session = null; |
|
|
|
if (!empty($sessionId)) { |
|
|
|
if (!empty($sessionId)) { |
|
|
|
$session = $app['orm.em']->getRepository('Entity\EntitySession')->find($sessionId); |
|
|
|
$session = $app['orm.em']->getRepository('Entity\EntitySession')->find($sessionId); |
|
|
|
} |
|
|
|
} |
|
|
|
$courseId = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@todo use the before filter do not put all aborts in controllers |
|
|
|
|
|
|
|
if (empty($courseId)) { |
|
|
|
|
|
|
|
$app->abort(403, 'Course not availablel'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Find course |
|
|
|
$course = $app['orm.em']->getRepository('Entity\EntityCourse')->find($courseId); |
|
|
|
$course = $app['orm.em']->getRepository('Entity\EntityCourse')->find($courseId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Getting subscribe users to the course |
|
|
|
$subscribedUsers = $app['orm.em']->getRepository('Entity\EntityCourse')->getSubscribedStudents($course); |
|
|
|
$subscribedUsers = $app['orm.em']->getRepository('Entity\EntityCourse')->getSubscribedStudents($course); |
|
|
|
$subscribedUsers = $subscribedUsers->getQuery(); |
|
|
|
$subscribedUsers = $subscribedUsers->getQuery(); |
|
|
|
$subscribedUsers = $subscribedUsers->execute(); |
|
|
|
$subscribedUsers = $subscribedUsers->execute(); |
|
|
|
|
|
|
|
|
|
|
|
//Getting all users |
|
|
|
//Getting all users in a nice format |
|
|
|
$choices = array(); |
|
|
|
$choices = array(); |
|
|
|
foreach ($subscribedUsers as $user) { |
|
|
|
foreach ($subscribedUsers as $user) { |
|
|
|
$choices[$user->getUserId()] = $user->getCompleteNameWithClasses(); |
|
|
|
$choices[$user->getUserId()] = $user->getCompleteNameWithClasses(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Getting subscribed users to a LP |
|
|
|
$subscribedUsersInLp = $app['orm.em']->getRepository('Entity\EntityCItemProperty')->getUsersSubscribedToItem( |
|
|
|
$subscribedUsersInLp = $app['orm.em']->getRepository('Entity\EntityCItemProperty')->getUsersSubscribedToItem( |
|
|
|
'learnpath', |
|
|
|
'learnpath', |
|
|
|
$lpId, |
|
|
|
$lpId, |
|
|
|
$course, |
|
|
|
$course, |
|
|
|
$session |
|
|
|
$session |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
//Getting users subscribed to the LP |
|
|
|
|
|
|
|
$selectedChoices = array(); |
|
|
|
$selectedChoices = array(); |
|
|
|
foreach ($subscribedUsersInLp as $itemProperty) { |
|
|
|
foreach ($subscribedUsersInLp as $itemProperty) { |
|
|
|
$selectedChoices[] = $itemProperty->getToUserId(); |
|
|
|
$selectedChoices[] = $itemProperty->getToUserId(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$form = new \FormValidator('lp_edit', 'post', $url); |
|
|
|
//Building the form for Users |
|
|
|
$form->addElement('header', get_lang('SubscribeUsersToLp')); |
|
|
|
$formUsers = new \FormValidator('lp_edit', 'post', $url); |
|
|
|
|
|
|
|
$formUsers->addElement('hidden', 'user_form', 1); |
|
|
|
|
|
|
|
$formUsers->addElement('header', get_lang('SubscribeUsersToLp')); |
|
|
|
|
|
|
|
|
|
|
|
$userMultiSelect = $form->addElement('advmultiselect', 'users', get_lang('Users'), $choices); |
|
|
|
$userMultiSelect = $formUsers->addElement('advmultiselect', 'users', get_lang('Users'), $choices); |
|
|
|
$userMultiSelect->setButtonAttributes('add'); |
|
|
|
$userMultiSelect->setButtonAttributes('add'); |
|
|
|
$userMultiSelect->setButtonAttributes('remove'); |
|
|
|
$userMultiSelect->setButtonAttributes('remove'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$formUsers->addElement('style_submit_button', 'submit', get_lang('Save'), 'class="save"'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$defaults = array(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($selectedChoices)) { |
|
|
|
|
|
|
|
$defaults['users'] = $selectedChoices; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$formUsers->setDefaults($defaults); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Building the form for Groups |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$form = new \FormValidator('lp_edit', 'post', $url); |
|
|
|
|
|
|
|
$form->addElement('header', get_lang('SubscribeGroupsToLp')); |
|
|
|
|
|
|
|
$form->addElement('hidden', 'group_form', 1); |
|
|
|
|
|
|
|
|
|
|
|
//Group list |
|
|
|
//Group list |
|
|
|
$groupList = \CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id(), 1); |
|
|
|
$groupList = \CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id(), 1); |
|
|
|
$groupChoices = array(); |
|
|
|
$groupChoices = array(); |
|
|
@ -147,39 +170,45 @@ class LearnpathController |
|
|
|
->getForm(); |
|
|
|
->getForm(); |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
$defaults = array(); |
|
|
|
$defaults = array(); |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($selectedChoices)) { |
|
|
|
|
|
|
|
$defaults['users'] = $selectedChoices; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($selectedGroupChoices)) { |
|
|
|
if (!empty($selectedGroupChoices)) { |
|
|
|
$defaults['groups'] = $selectedGroupChoices; |
|
|
|
$defaults['groups'] = $selectedGroupChoices; |
|
|
|
} |
|
|
|
} |
|
|
|
$form->setDefaults($defaults); |
|
|
|
$form->setDefaults($defaults); |
|
|
|
|
|
|
|
|
|
|
|
if ($request->getMethod() == 'POST') { |
|
|
|
if ($request->getMethod() == 'POST') { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Subscribing users |
|
|
|
$users = $request->get('users'); |
|
|
|
$users = $request->get('users'); |
|
|
|
$app['orm.em']->getRepository('Entity\EntityCItemProperty')->SubscribedUsersToItem( |
|
|
|
$userForm = $request->get('user_form'); |
|
|
|
|
|
|
|
if (!empty($userForm)) { |
|
|
|
|
|
|
|
$app['orm.em']->getRepository('Entity\EntityCItemProperty')->subscribeUsersToItem( |
|
|
|
'learnpath', |
|
|
|
'learnpath', |
|
|
|
$course, |
|
|
|
$course, |
|
|
|
$session, |
|
|
|
$session, |
|
|
|
$lpId, |
|
|
|
$lpId, |
|
|
|
$users |
|
|
|
$users |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Subscribing groups |
|
|
|
$groups = $request->get('groups'); |
|
|
|
$groups = $request->get('groups'); |
|
|
|
$app['orm.em']->getRepository('Entity\EntityCItemProperty')->SubscribedGroupsToItem( |
|
|
|
$groupForm = $request->get('group_form'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($groupForm)) { |
|
|
|
|
|
|
|
$app['orm.em']->getRepository('Entity\EntityCItemProperty')->subscribeGroupsToItem( |
|
|
|
'learnpath', |
|
|
|
'learnpath', |
|
|
|
$course, |
|
|
|
$course, |
|
|
|
$session, |
|
|
|
$session, |
|
|
|
$lpId, |
|
|
|
$lpId, |
|
|
|
$groups |
|
|
|
$groups |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $app->redirect($url); |
|
|
|
return $app->redirect($url); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$app['template']->assign('form', $form->toHtml()); |
|
|
|
$app['template']->assign('formUsers', $formUsers->toHtml()); |
|
|
|
|
|
|
|
$app['template']->assign('formGroups', $form->toHtml()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$response = $app['template']->render_template('learnpath/subscribe_users.tpl'); |
|
|
|
$response = $app['template']->render_template('learnpath/subscribe_users.tpl'); |
|
|
|
|
|
|
|
|
|
|
|
return new Response($response, 200, array()); |
|
|
|
return new Response($response, 200, array()); |
|
|
|