From 94cef3382735000b57e148d72dcc1182d6dbdbef Mon Sep 17 00:00:00 2001 From: jmontoya Date: Wed, 30 Mar 2016 16:06:11 +0200 Subject: [PATCH] Fixing sonata dashboard. --- app/AppKernel.php | 8 ++++---- app/config/routing.yml | 2 +- main/inc/lib/api.lib.php | 12 ++++++++++++ main/inc/lib/usermanager.lib.php | 20 +++++++++++++------- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/AppKernel.php b/app/AppKernel.php index ec024b6076..3f46063f79 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -94,10 +94,10 @@ class AppKernel extends Kernel new Chamilo\CoreBundle\ChamiloCoreBundle(), new Chamilo\CourseBundle\ChamiloCourseBundle(), /* new Chamilo\SettingsBundle\ChamiloSettingsBundle(), - new Chamilo\ThemeBundle\ChamiloThemeBundle(), - new Chamilo\NotificationBundle\ChamiloNotificationBundle(), - new Chamilo\AdminBundle\ChamiloAdminBundle(), - new Chamilo\TimelineBundle\ChamiloTimelineBundle(),*/ + new Chamilo\ThemeBundle\ChamiloThemeBundle(), */ + //new Chamilo\NotificationBundle\ChamiloNotificationBundle(), + //new Chamilo\AdminBundle\ChamiloAdminBundle(), + //new Chamilo\TimelineBundle\ChamiloTimelineBundle(), // Based in Sonata new Chamilo\ClassificationBundle\ChamiloClassificationBundle(), diff --git a/app/config/routing.yml b/app/config/routing.yml index 3a390098f8..2568948ef4 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -58,7 +58,7 @@ sonata_user_admin_security_logout: _admin: resource: routing_admin.yml - prefix: /administration + prefix: / #_api: # resource: routing_api.yml diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index a270600cf9..877ef26b6d 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -1545,6 +1545,18 @@ function api_get_user_info( return false; } +/** + * @param int $userId + * @return User + */ +function api_get_user_entity($userId) +{ + /** @var \Chamilo\UserBundle\Repository\UserRepository $repo */ + $repo = Database::getManager()->getRepository('ChamiloUserBundle:User'); + + return $repo->find($userId); +} + /** * Finds all the information about a user from username instead of user id * @param string $username diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index f8401ff846..7721a8156c 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -370,7 +370,7 @@ class UserManager Database::query($sql); if ($isAdmin) { - UserManager::add_user_as_admin($userId); + UserManager::add_user_as_admin($user); } if (api_get_multiple_access_url()) { @@ -4762,16 +4762,22 @@ EOF; } /** - * @param int $userId + * @param User $user */ - static function add_user_as_admin($userId) + static function add_user_as_admin(User $user) { $table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN); - $userId = intval($userId); + if ($user) { + $userId = $user->getId(); - if (!self::is_admin($userId)) { - $sql = "INSERT INTO $table_admin SET user_id = $userId"; - Database::query($sql); + if (!self::is_admin($userId)) { + $sql = "INSERT INTO $table_admin SET user_id = $userId"; + Database::query($sql); + } + + $user->addRole('ROLE_ADMIN'); + self::getManager()->updateUser($user, true); + exit; } }