From f7d7d8d2d91fdcbfae3fd659078cceff203ef551 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 5 Mar 2013 09:47:03 +0100 Subject: [PATCH] Replacing public with web + adding LearnpathController --- index.php | 1 + main/inc/global.inc.php | 10 ++- main/newscorm/lp_list.php | 16 ++-- .../Controller/LearnpathController.php | 88 +++++++++++++++++++ user_portal.php | 7 +- {public => web}/.htaccess | 0 {public => web}/index.php | 0 7 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 src/ChamiloLMS/Controller/LearnpathController.php rename {public => web}/.htaccess (100%) rename {public => web}/index.php (100%) diff --git a/index.php b/index.php index e7dde85ec1..4c635deb2e 100644 --- a/index.php +++ b/index.php @@ -38,4 +38,5 @@ $htmlHeadXtra[] = ' //$cookie = new Cookie('TestCookie', 'cookies_yes', time()+3600*24*31*12); //$response->headers->setCookie($cookie); + $app->run(); \ No newline at end of file diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index b0c0235ad9..9351e4798e 100755 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -130,6 +130,7 @@ $app->register(new Silex\Provider\HttpCacheServiceProvider(), array( //$app->register(new Silex\Provider\SessionServiceProvider()); +/* use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\User; @@ -172,7 +173,7 @@ class UserProvider implements UserProviderInterface return $class === 'Symfony\Component\Security\Core\User\User'; } } -/* + $app->register(new Silex\Provider\SecurityServiceProvider(), array( 'security.firewalls' => array( 'secured' => array( @@ -953,6 +954,10 @@ $app['userportal.controller'] = $app->share(function () use ($app) { return new ChamiloLMS\Controller\UserPortalController(); }); +$app['learnpath.controller'] = $app->share(function () use ($app) { + return new ChamiloLMS\Controller\LearnpathController(); +}); + /* class PostController { @@ -977,5 +982,8 @@ $app->get('/', 'index.controller:indexAction'); //user_portal.php $app->get('/userportal', 'userportal.controller:indexAction'); +$app->get('/learnpath/subscribe_users/{id}', 'learnpath.controller:indexAction')->bind('subscribe_users'); +$app->post('/learnpath/subscribe_users/{id}', 'learnpath.controller:indexAction')->bind('subscribe_users'); + //$app->mount('/', 'index.controller'); return $app; \ No newline at end of file diff --git a/main/newscorm/lp_list.php b/main/newscorm/lp_list.php index 97eb3d7e6e..479849d0e7 100644 --- a/main/newscorm/lp_list.php +++ b/main/newscorm/lp_list.php @@ -277,10 +277,13 @@ foreach ($categories as $item) { // Session test not necessary if we want to show base course learning paths inside the session (see http://support.chamilo.org/projects/chamilo-18/wiki/Tools_and_sessions). //if ($current_session == $details['lp_session']) { - if ($details['lp_visibility'] == 0) { - $dsp_visible = "".Display::return_icon('invisible.png', get_lang('Show'), '', ICON_SIZE_SMALL).""; - } else { - $dsp_visible = "".Display::return_icon('visible.png', get_lang('Hide'), '', ICON_SIZE_SMALL).""; + + if (!isset($details['subscribe_users']) || $details['subscribe_users'] != 1) { + if ($details['lp_visibility'] == 0) { + $dsp_visible = "".Display::return_icon('invisible.png', get_lang('Show'), '', ICON_SIZE_SMALL).""; + } else { + $dsp_visible = "".Display::return_icon('visible.png', get_lang('Hide'), '', ICON_SIZE_SMALL).""; + } } /* PUBLISH COMMAND */ @@ -326,7 +329,7 @@ foreach ($categories as $item) { /* FUll screen VIEW */ if ($current_session == $details['lp_session']) { - switch($details['lp_view_mode']) { + switch ($details['lp_view_mode']) { case 'fullscreen': $dsp_default_view = ''. Display::return_icon('view_fullscreen.png', get_lang('ViewModeFullScreen'), '', ICON_SIZE_SMALL).''; @@ -364,7 +367,6 @@ foreach ($categories as $item) { } } - /* Export */ if ($details['lp_type'] == 1) { @@ -381,7 +383,7 @@ foreach ($categories as $item) { //Subscribe users $subscribe_users = null; if ($details['subscribe_users'] == 1) { - $subscribe_users = Display::url(Display::return_icon('add.png', get_lang('AddUsers')), "lp_subscribe_users.php?lp_id=$id"); + $subscribe_users = Display::url(Display::return_icon('add.png', get_lang('AddUsers')), api_get_path(WEB_PATH)."learnpath/subscribe_users/$id"); } /* Auto Lunch LP code */ diff --git a/src/ChamiloLMS/Controller/LearnpathController.php b/src/ChamiloLMS/Controller/LearnpathController.php new file mode 100644 index 0000000000..98685b9f5d --- /dev/null +++ b/src/ChamiloLMS/Controller/LearnpathController.php @@ -0,0 +1,88 @@ +redirect('lp_controller.php'); + } + + $course = $app['orm.em']->getRepository('Entity\EntityCourse')->find(api_get_course_int_id()); + + $subscribedUsers = $app['orm.em']->getRepository('Entity\EntityCourse')->getSubscribedStudents($course); + + $subscribedUsers = $subscribedUsers->getQuery(); + $subscribedUsers = $subscribedUsers->execute(); + + $choices = array(); + foreach ($subscribedUsers as $user) { + $choices[$user->getUserId()] = $user->getCompleteName(); + } + + $subscribedUsersInLp = $app['orm.em']->getRepository('Entity\EntityCItemProperty')->getUsersSubscribedToItem('learnpath', $lpId, $course); + + $selectedChoices = array(); + foreach ($subscribedUsersInLp as $itemProperty) { + $userId = $itemProperty->getToUserId(); + $user = $app['orm.em']->getRepository('Entity\EntityUser')->find($userId); + $selectedChoices[$user->getUserId()] = $user->getCompleteName(); + if (isset($choices[$user->getUserId()])) { + unset($choices[$user->getUserId()]); + } + } + + $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) { + $repo = $repo->getSubscribedStudents($course); + return $repo; + },*/ + 'choices' => $choices + )) + ->add('destination', 'choice', array( + 'label' => get_lang('Destination'), + '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); + },*/ + 'choices' => $selectedChoices + )) + ->getForm(); + + if ($request->getMethod() == 'POST') { + $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('lp_id' => $lpId))); + } else { + $app['template']->assign('form', $form->createView()); + } + $response = $app['template']->render_template('learnpath/subscribe_users.tpl'); + + //return new Response($response, 200, array('Cache-Control' => 's-maxage=3600, private')); + return new Response($response, 200, array()); + } +} \ No newline at end of file diff --git a/user_portal.php b/user_portal.php index 18ac39332a..515ce0788b 100644 --- a/user_portal.php +++ b/user_portal.php @@ -15,6 +15,10 @@ * @todo display_digest, shouldn't this be removed and be made into an extension? */ +//Temporal hack +header('Location: web/userportal'); +exit; + /** * INIT SECTION */ @@ -78,6 +82,3 @@ if ($load_dirs) { }); '; } - -$app->get('/', 'UserPortalController::indexAction'); -$app->run(); \ No newline at end of file diff --git a/public/.htaccess b/web/.htaccess similarity index 100% rename from public/.htaccess rename to web/.htaccess diff --git a/public/index.php b/web/index.php similarity index 100% rename from public/index.php rename to web/index.php