From b42b2cd94481fa0df49db10cf813a8f5e1678e93 Mon Sep 17 00:00:00 2001 From: jmontoya Date: Mon, 19 May 2014 19:45:04 +0200 Subject: [PATCH] Fixing translator, replacing $app variables, replacing entities names. --- composer.json | 6 +++++- main/admin/course_add.php | 5 +---- main/admin/user_add.php | 14 +++++++------- main/inc/lib/api.lib.php | 5 ++--- main/inc/lib/chamilo_session.class.php | 2 +- main/inc/lib/database.lib.php | 12 ++++++++++++ main/inc/lib/extra_field.lib.php | 5 ++--- main/inc/lib/internationalization.lib.php | 8 +++++--- main/inc/lib/usermanager.lib.php | 7 +++---- .../CoreBundle/Listener/LegacyListener.php | 3 +++ .../CoreBundle/Resources/config/services.yml | 6 ------ .../Resources/translations/{en.po => all.en.po} | 9 ++++++++- .../Resources/translations/{es.po => all.es.po} | 0 .../translations/{fr.po => all.fr_FR.po} | 17 ++++++++++++----- web/legacy.php | 3 +++ 15 files changed, 64 insertions(+), 38 deletions(-) rename src/ChamiloLMS/CoreBundle/Resources/translations/{en.po => all.en.po} (99%) rename src/ChamiloLMS/CoreBundle/Resources/translations/{es.po => all.es.po} (100%) rename src/ChamiloLMS/CoreBundle/Resources/translations/{fr.po => all.fr_FR.po} (99%) diff --git a/composer.json b/composer.json index 1946136eba..74324ae3bc 100755 --- a/composer.json +++ b/composer.json @@ -58,7 +58,11 @@ "oyejorge/less.php": "~1.5", "sonata-project/block-bundle": "~2.2", "knplabs/knp-menu-bundle": "~1.1", - "white-october/pagerfanta-bundle": "dev-master" + "white-october/pagerfanta-bundle": "dev-master", + "jbroadway/urlify": "1.0.0-stable", + "chamilo/chash": "dev-master", + "doctrine/migrations": "dev-master", + "composer/composer": "1.0.*@dev" }, "scripts": { "post-install-cmd": [ diff --git a/main/admin/course_add.php b/main/admin/course_add.php index 8dfe01d52d..cd1ae0ac70 100644 --- a/main/admin/course_add.php +++ b/main/admin/course_add.php @@ -150,7 +150,4 @@ if ($form->validate()) { // Display the form. $content = $form->return_form(); -$tpl = $app['template']; -$app['title'] = $tool_name; -$tpl->assign('content', $content); -$tpl->display_one_col_template(); +echo $content; \ No newline at end of file diff --git a/main/admin/user_add.php b/main/admin/user_add.php index d537c7bfdf..a28e5a7b85 100644 --- a/main/admin/user_add.php +++ b/main/admin/user_add.php @@ -6,7 +6,7 @@ // User permissions api_protect_admin_script(true); - +$is_platform_admin = api_is_platform_admin(); $message = null; $htmlHeadXtra[] = api_get_password_checker_js('#username', '#password'); @@ -268,9 +268,9 @@ if( $form->validate()) { $language = $user['language']; $picture = $_FILES['picture']; $send_mail = intval($user['mail']['send_mail']); - $hr_dept_id = intval($user['hr_dept_id']); + $hr_dept_id = isset($user['hr_dept_id']) ? intval($user['hr_dept_id']) : 0; - if (count($extAuthSource) > 0 && $user['password']['password_auto'] == '2') { + if (isset($extAuthSource) && count($extAuthSource) > 0 && $user['password']['password_auto'] == '2') { $auth_source = $user['password']['auth_source']; $password = 'PLACEHOLDER'; } else { @@ -380,7 +380,7 @@ if (!empty($message)){ $content = $form->return_form(); $app['title'] = $tool_name; -$tpl = $app['template']; -$tpl->assign('message', $message); -$tpl->assign('content', $content); -$tpl->display_one_col_template(); +//$tpl = $app['template']; +echo $message; + +echo $content; \ No newline at end of file diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index 21e0aee152..1b37f3c21f 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -6775,9 +6775,8 @@ function api_get_language_interface() */ function api_get_user_roles() { - global $app; - $em = $app['orm.ems']['db_read']; - $roles = $em->getRepository('ChamiloLMS\Entity\Role')->findBy(array(), array('name'=>'asc')); + $em = Database::getManager(); + $roles = $em->getRepository('ChamiloLMSCoreBundle:Role')->findBy(array(), array('name'=>'asc')); $userRoles = array(); foreach ($roles as $role) { $userRoles[$role->getId()] = $role->getName(); diff --git a/main/inc/lib/chamilo_session.class.php b/main/inc/lib/chamilo_session.class.php index be458dbc92..c4cc1271c3 100644 --- a/main/inc/lib/chamilo_session.class.php +++ b/main/inc/lib/chamilo_session.class.php @@ -73,7 +73,7 @@ class ChamiloSession } /** - * @return Symfony\Component\Security\Core\SecurityContextInterface + * @return Symfony\Bundle\FrameworkBundle\Translation\Translator */ public static function getTranslator() { diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 119422c4fe..085ac949d8 100644 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -36,6 +36,8 @@ class Database */ private static $connectionWrite; + private static $em; + /** * Constructor * @@ -60,6 +62,16 @@ class Database self::$connectionWrite = isset($dbs['db_write']) ? $dbs['db_write'] : $db; } + public static function setManager($em) + { + self::$em = $em; + } + + public static function getManager() + { + return self::$em; + } + /** * Return current connection * @return \Doctrine\DBAL\Connection diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index e97011f348..553d69c6a0 100644 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -643,14 +643,13 @@ class ExtraField extends Model $addOptions = array(); - global $app; - $optionsExists = $app['orm.em']->getRepository('ChamiloLMS\Entity\ExtraFieldOptionRelFieldOption')-> + $optionsExists = Database::getManager()->getRepository('ChamiloLMSCoreBundle:ExtraFieldOptionRelFieldOption')-> findOneBy(array('fieldId' => $field_details['id'])); if ($optionsExists) { if (isset($userInfo['status']) && !empty($userInfo['status'])) { - $fieldWorkFlow = $app['orm.em']->getRepository('ChamiloLMS\Entity\ExtraFieldOptionRelFieldOption') + $fieldWorkFlow = Database::getManager()->getRepository('ChamiloLMSCoreBundle:ExtraFieldOptionRelFieldOption') ->findBy( array( 'fieldId' => $field_details['id'], diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index 7d1e2eb1c2..facd5c8330 100644 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -49,10 +49,12 @@ define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER); // Contextual: for */ function get_lang($variable) { - $translated = Session::getTranslator()->trans($variable); + $defaultDomain = 'all'; + $translated = Session::getTranslator()->trans($variable, array(), $defaultDomain); + if ($translated == $variable) { // Check the langVariable for BC - $translated = Session::getTranslator()->trans("lang$variable"); + $translated = Session::getTranslator()->trans("lang$variable", array(), $defaultDomain); if ($translated == "lang$variable") { return $variable; } @@ -966,7 +968,7 @@ function _api_mb_internal_encoding() */ function api_transliterate($string, $unknown = '?', $from_encoding = null) -{ +{ return $string; return URLify::transliterate($string); //return u::toAscii($string, $unknown); } diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 8a04030c40..acb0ff213d 100644 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -336,13 +336,12 @@ class UserManager UrlManager::add_user_to_url($return, 1); } - // Adding user /** @var ChamiloLMS\Entity\User $user */ - $em = self::$em; + $em = Database::getManager(); - $user = $em->getRepository('ChamiloLMS\Entity\User')->find($return); - $role = $em->getRepository('ChamiloLMS\Entity\Role')->find($status); + $user = $em->getRepository('ChamiloLMSCoreBundle:User')->find($return); + $role = $em->getRepository('ChamiloLMSCoreBundle:Role')->find($status); $user->getRolesObj()->add($role); $em->persist($user); diff --git a/src/ChamiloLMS/CoreBundle/Listener/LegacyListener.php b/src/ChamiloLMS/CoreBundle/Listener/LegacyListener.php index 554804c5d6..a1d7455125 100644 --- a/src/ChamiloLMS/CoreBundle/Listener/LegacyListener.php +++ b/src/ChamiloLMS/CoreBundle/Listener/LegacyListener.php @@ -28,6 +28,7 @@ class LegacyListener Session::setSession($request->getSession()); $dbConnection = $this->container->get('database_connection'); $database = new \Database($dbConnection, array()); + \Database::setManager($this->container->get('doctrine')->getManager()); Session::$urlGenerator = $this->container->get('router'); Session::$security = $this->container->get('security.context'); Session::$translator = $this->container->get('translator'); @@ -38,6 +39,8 @@ class LegacyListener Session::$courseDir = $this->container->get('kernel')->getDataDir(); Session::$configDir = $this->container->get('kernel')->getConfigDir(); + + // Injecting course in twig $courseCode = $request->get('code'); diff --git a/src/ChamiloLMS/CoreBundle/Resources/config/services.yml b/src/ChamiloLMS/CoreBundle/Resources/config/services.yml index 744d1c5d37..f2aa1b5430 100644 --- a/src/ChamiloLMS/CoreBundle/Resources/config/services.yml +++ b/src/ChamiloLMS/CoreBundle/Resources/config/services.yml @@ -31,9 +31,3 @@ services: arguments: ["sonata.block.service.course", @templating ] tags: - { name: sonata.block } - - translation.loader.po: - class: Symfony\Component\Translation\Loader\PoFileLoader - tags: - - { name: translation.loader, alias: po } - diff --git a/src/ChamiloLMS/CoreBundle/Resources/translations/en.po b/src/ChamiloLMS/CoreBundle/Resources/translations/all.en.po similarity index 99% rename from src/ChamiloLMS/CoreBundle/Resources/translations/en.po rename to src/ChamiloLMS/CoreBundle/Resources/translations/all.en.po index 4d417a113f..bee1ecc154 100644 --- a/src/ChamiloLMS/CoreBundle/Resources/translations/en.po +++ b/src/ChamiloLMS/CoreBundle/Resources/translations/all.en.po @@ -1,6 +1,13 @@ msgid "" msgstr "" -"Content-Type: text/plain; charset=utf-8 \n" +"Content-Type: text/plain; charset=utf-8\n" +"Project-Id-Version: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" msgid "ResourceAdded" msgstr "Resource added" diff --git a/src/ChamiloLMS/CoreBundle/Resources/translations/es.po b/src/ChamiloLMS/CoreBundle/Resources/translations/all.es.po similarity index 100% rename from src/ChamiloLMS/CoreBundle/Resources/translations/es.po rename to src/ChamiloLMS/CoreBundle/Resources/translations/all.es.po diff --git a/src/ChamiloLMS/CoreBundle/Resources/translations/fr.po b/src/ChamiloLMS/CoreBundle/Resources/translations/all.fr_FR.po similarity index 99% rename from src/ChamiloLMS/CoreBundle/Resources/translations/fr.po rename to src/ChamiloLMS/CoreBundle/Resources/translations/all.fr_FR.po index 15f8cda99e..6bc72be334 100644 --- a/src/ChamiloLMS/CoreBundle/Resources/translations/fr.po +++ b/src/ChamiloLMS/CoreBundle/Resources/translations/all.fr_FR.po @@ -1,6 +1,13 @@ msgid "" msgstr "" -"Content-Type: text/plain; charset=utf-8 \n" +"Content-Type: text/plain; charset=utf-8\n" +"Project-Id-Version: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" msgid "ResourceAdded" msgstr "Ressource ajoutée" @@ -922,13 +929,13 @@ msgid "ScoringUpdated" msgstr "Cotations mises à jour" msgid "CertificateWCertifiesStudentXFinishedCourseYWithGradeZ" -msgstr "%s certifie que +msgstr "%s certifie que - %s + %s -a réussi le cours +a réussi le cours - '%s' + '%s' avec la mention diff --git a/web/legacy.php b/web/legacy.php index bf59717d50..9b06aa4743 100644 --- a/web/legacy.php +++ b/web/legacy.php @@ -1,5 +1,8 @@