/**
 * Builds a person (full) name depending on the convention for a given language.
 * @param string $first_name            The first name of the preson.
 * @param string $last_name                The last name of the person.
 * @param string $title                    The title of the person.
 * @param int/string $format (optional)    The person name format. It may be a pattern-string (for example '%t %l, %f' or '%T %F %L', ...) or some of the constants PERSON_NAME_COMMON_CONVENTION (default), PERSON_NAME_WESTERN_ORDER, PERSON_NAME_EASTERN_ORDER, PERSON_NAME_LIBRARY_ORDER.
 * @param string $language (optional)    The language identificator. if it is omitted, the current interface language is assumed. This parameter has meaning with the format PERSON_NAME_COMMON_CONVENTION only.
 * @param string $encoding (optional)    The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
 * @return bool                            The result is sort of full name of the person.
 * Sample results:
 * Peter Ustinoff or Dr. Peter Ustinoff     - the Western order
 * Ustinoff Peter or Dr. Ustinoff Peter     - the Eastern order
 * Ustinoff, Peter or - Dr. Ustinoff, Peter - the library order
 * Note: See the file chamilo/main/inc/lib/internationalization_database/name_order_conventions.php where you can revise the convention for your language.
 * @author Carlos Vargas <*****@*****.**> - initial implementation.
 * @author Ivan Tcholakov
 */
function api_get_person_name($first_name, $last_name, $title = null, $format = null, $language = null, $encoding = null)
{
    static $valid = array();
    if (empty($format)) {
        $format = PERSON_NAME_COMMON_CONVENTION;
    }
    if (empty($language)) {
        $language = api_get_interface_language(false, true);
    }
    if (empty($encoding)) {
        $encoding = mb_internal_encoding();
    }
    if (!isset($valid[$format][$language])) {
        if (is_int($format)) {
            switch ($format) {
                case PERSON_NAME_COMMON_CONVENTION:
                    $valid[$format][$language] = _api_get_person_name_convention($language, 'format');
                    $usernameOrderFromDatabase = api_get_setting('display.user_name_order');
                    if (isset($usernameOrderFromDatabase) && !empty($usernameOrderFromDatabase)) {
                        $valid[$format][$language] = $usernameOrderFromDatabase;
                    }
                    break;
                case PERSON_NAME_WESTERN_ORDER:
                    $valid[$format][$language] = '%t %f %l';
                    break;
                case PERSON_NAME_EASTERN_ORDER:
                    $valid[$format][$language] = '%t %l %f';
                    break;
                case PERSON_NAME_LIBRARY_ORDER:
                    $valid[$format][$language] = '%t %l, %f';
                    break;
                default:
                    $valid[$format][$language] = '%t %f %l';
                    break;
            }
        } else {
            $valid[$format][$language] = _api_validate_person_name_format($format);
        }
    }
    $format = $valid[$format][$language];
    $person_name = str_replace(array('%f', '%l', '%t'), array($first_name, $last_name, $title), $format);
    if (strpos($format, '%F') !== false || strpos($format, '%L') !== false || strpos($format, '%T') !== false) {
        $person_name = str_replace(array('%F', '%L', '%T'), array(api_strtoupper($first_name, $encoding), api_strtoupper($last_name, $encoding), api_strtoupper($title, $encoding)), $person_name);
    }
    return _api_clean_person_name($person_name);
}
/**
 * Returns returns person name convention for a given language.
 * @param string $language	The input language.
 * @param string $type		The type of the requested convention.
 * It may be 'format' for name order convention or 'sort_by' for name sorting convention.
 * @return mixed Depending of the requested type,
 * the returned result may be string or boolean; null is returned on error;
 */
function _api_get_person_name_convention($language, $type)
{
    static $conventions;
    $language = api_purify_language_id($language);
    if (!isset($conventions)) {
        $file = dirname(__FILE__) . '/internationalization_database/name_order_conventions.php';
        if (file_exists($file)) {
            $conventions = (include $file);
        } else {
            $conventions = array('english' => array('format' => 'title first_name last_name', 'sort_by' => 'first_name'));
        }
        // Overwrite classic conventions
        $customConventions = api_get_configuration_value('name_order_conventions');
        if (!empty($customConventions)) {
            foreach ($customConventions as $key => $data) {
                $conventions[$key] = $data;
            }
        }
        $search1 = array('FIRST_NAME', 'LAST_NAME', 'TITLE');
        $replacement1 = array('%F', '%L', '%T');
        $search2 = array('first_name', 'last_name', 'title');
        $replacement2 = array('%f', '%l', '%t');
        foreach (array_keys($conventions) as $key) {
            $conventions[$key]['format'] = str_replace($search1, $replacement1, $conventions[$key]['format']);
            $conventions[$key]['format'] = _api_validate_person_name_format(_api_clean_person_name(str_replace('%', ' %', str_ireplace($search2, $replacement2, $conventions[$key]['format']))));
            $conventions[$key]['sort_by'] = strtolower($conventions[$key]['sort_by']) != 'last_name' ? true : false;
        }
    }
    switch ($type) {
        case 'format':
            return is_string($conventions[$language]['format']) ? $conventions[$language]['format'] : '%t %f %l';
        case 'sort_by':
            return is_bool($conventions[$language]['sort_by']) ? $conventions[$language]['sort_by'] : true;
    }
    return null;
}
/**
 * Builds a person (full) name depending on the convention for a given language.
 * @param string $first_name			The first name of the preson.
 * @param string $last_name				The last name of the person.
 * @param string $title					The title of the person.
 * @param int/string $format (optional)	The person name format. It may be a pattern-string (for example '%t %l, %f' or '%T %F %L', ...) or some of the constants PERSON_NAME_COMMON_CONVENTION (default), PERSON_NAME_WESTERN_ORDER, PERSON_NAME_EASTERN_ORDER, PERSON_NAME_LIBRARY_ORDER.
 * @param string $language (optional)	The language indentificator. If it is omited, the current interface language is assumed. This parameter has meaning with the format PERSON_NAME_COMMON_CONVENTION only.
 * @param string $encoding (optional)	The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
 * @return bool							The result is sort of full name of the person.
 * Sample results:
 * Peter Ustinoff or Dr. Peter Ustinoff     - the Western order
 * Ustinoff Peter or Dr. Ustinoff Peter     - the Eastern order
 * Ustinoff, Peter or - Dr. Ustinoff, Peter - the library order
 * Note: See the file chamilo/main/inc/lib/internationalization_database/name_order_conventions.php where you can revise the convention for your language.
 * @author Carlos Vargas <*****@*****.**> - initial implementation.
 * @author Ivan Tcholakov
 */
function api_get_person_name($first_name, $last_name, $title = null, $format = null, $language = null, $encoding = null, $username = null)
{
    static $valid = array();
    if (empty($format)) {
        $format = PERSON_NAME_COMMON_CONVENTION;
    }
    //We check if the language is supported, otherwise we check the interface language of the parent language of sublanguage
    $language_is_supported = api_is_language_supported($language);
    if (!$language_is_supported || empty($language)) {
        $language = api_get_interface_language(false, true);
    }
    if (empty($encoding)) {
        $encoding = _api_mb_internal_encoding();
    }
    if (!isset($valid[$format][$language])) {
        if (is_int($format)) {
            switch ($format) {
                case PERSON_NAME_COMMON_CONVENTION:
                    $valid[$format][$language] = _api_get_person_name_convention($language, 'format');
                    $usernameOrderFromDatabase = api_get_setting('user_name_order');
                    if (isset($usernameOrderFromDatabase) && !empty($usernameOrderFromDatabase)) {
                        $valid[$format][$language] = $usernameOrderFromDatabase;
                    }
                    break;
                case PERSON_NAME_WESTERN_ORDER:
                    $valid[$format][$language] = '%t %f %l';
                    break;
                case PERSON_NAME_EASTERN_ORDER:
                    $valid[$format][$language] = '%t %l %f';
                    break;
                case PERSON_NAME_LIBRARY_ORDER:
                    $valid[$format][$language] = '%t %l, %f';
                    break;
                default:
                    $valid[$format][$language] = '%t %f %l';
                    break;
            }
        } else {
            $valid[$format][$language] = _api_validate_person_name_format($format);
        }
    }
    $format = $valid[$format][$language];
    $keywords = array('%firstname', '%f', '%F', '%lastname', '%l', '%L', '%title', '%t', '%T', '%username', '%u', '%U');
    $values = array($first_name, $first_name, api_strtoupper($first_name, $encoding), $last_name, $last_name, api_strtoupper($last_name, $encoding), $title, $title, api_strtoupper($title, $encoding), $username, $username, api_strtoupper($username, $encoding));
    $person_name = str_replace($keywords, $values, $format);
    return _api_clean_person_name($person_name);
}
示例#4
0
 public function register(Application $app)
 {
     // Database.
     $app['database'] = $app->share(function () use($app) {
         $db = new Database($app['db'], $app['dbs']);
         return $db;
     });
     $database = $app['database'];
     // Template class
     $app['template'] = $app->share(function () use($app) {
         $template = new Template($app, $app['database'], $app['security'], $app['translator'], $app['url_generator']);
         return $template;
     });
     Display::setUrlGenerator($app['url_generator']);
     $app['html_editor'] = $app->share(function ($app) {
         $editor = new Chamilo\CoreBundle\Component\Editor\CkEditor\CkEditor($app['translator'], $app['url_generator'], $app['template'], $app['course']);
         $editor->setJavascriptToInclude();
         return $editor;
         /*return new Chamilo\CoreBundle\Component\Editor\TinyMce\TinyMce(
               $app['translator'], $app['url_generator']
           );*/
     });
     $app['editor_connector'] = $app->share(function ($app) {
         $token = $app['security']->getToken();
         $user = $token->getUser();
         return new Connector($app['orm.em'], $app['paths'], $app['url_generator'], $app['translator'], $app['security'], $user, $app['course']);
     });
     // Paths
     // @todo
     $app['paths'] = $app->share(function () use($app) {
         return array('root_sys' => $app['path.base'], 'sys_root' => $app['path.base'], 'sys_data_path' => $app['path.data'], 'sys_config_path' => $app['path.config'], 'path.temp' => $app['path.temp'], 'sys_log_path' => $app['path.logs']);
     });
     $app['course'] = $app->share(function () use($app) {
         $request = $app['request'];
         $session = $request->getSession();
         $courseCode = $request->get('course');
         if (empty($courseCode)) {
             $courseCode = $session->get('_cid');
         }
         if (!empty($courseCode)) {
             // Converting /courses/XXX/ to a Entity/Course object.
             return $app['orm.em']->getRepository('Chamilo\\CoreBundle\\Entity\\Course')->findOneByCode($courseCode);
             //$app['template']->assign('course', $course);
             return $course;
         }
         return null;
     });
     $app['course_session'] = $app->share(function () use($app) {
         $request = $app['request'];
         $session = $request->getSession();
         $sessionId = $request->get('id_session');
         if (empty($sessionId)) {
             $sessionId = $session->get('id_session');
         }
         if (!empty($sessionId)) {
             return $app['orm.em']->getRepository('Chamilo\\CoreBundle\\Entity\\Session')->findOneById($sessionId);
             //                $app['template']->assign('course_session', $courseSession);
             return $courseSession;
         }
         return null;
     });
     // Chamilo data filesystem.
     $app['chamilo.filesystem'] = $app->share(function () use($app) {
         $mediaConverter = null;
         if (isset($app->getConfiguration()->services->mediaalchemyst)) {
             $mediaConverter = $app['media-alchemyst'];
         }
         $filesystem = new DataFilesystem($app['paths'], $app['filesystem'], $app['editor_connector'], $mediaConverter);
         return $filesystem;
     });
     // Page controller class.
     $app['page_controller'] = $app->share(function () use($app) {
         $pageController = new PageController($app);
         return $pageController;
     });
     // Mail template generator.
     $app['mail_generator'] = $app->share(function () use($app) {
         $mailGenerator = new MailGenerator($app['twig'], $app['mailer']);
         return $mailGenerator;
     });
     // Setting up name conventions
     $conventions = (require_once $app['path.base'] . 'main/inc/lib/internationalization_database/name_order_conventions.php');
     if (isset($configuration['name_order_conventions']) && !empty($configuration['name_order_conventions'])) {
         $conventions = array_merge($conventions, $configuration['name_order_conventions']);
     }
     $search1 = array('FIRST_NAME', 'LAST_NAME', 'TITLE');
     $replacement1 = array('%F', '%L', '%T');
     $search2 = array('first_name', 'last_name', 'title');
     $replacement2 = array('%f', '%l', '%t');
     $keyConventions = array_keys($conventions);
     foreach ($keyConventions as $key) {
         $conventions[$key]['format'] = str_replace($search1, $replacement1, $conventions[$key]['format']);
         $conventions[$key]['format'] = _api_validate_person_name_format(_api_clean_person_name(str_replace('%', ' %', str_ireplace($search2, $replacement2, $conventions[$key]['format']))));
         $conventions[$key]['sort_by'] = strtolower($conventions[$key]['sort_by']) != 'last_name' ? true : false;
     }
     $app['name_order_conventions'] = $conventions;
     $app['exporter'] = $app->share(function () use($app) {
         return new Chamilo\CoreBundle\Framework\Exporter();
     });
 }
示例#5
0
 public function register(Application $app)
 {
     // Database.
     $app['database'] = $app->share(function () use($app) {
         $db = new Database($app['db'], $app['dbs']);
         return $db;
     });
     $database = $app['database'];
     // Template class
     $app['template'] = $app->share(function () use($app) {
         $template = new Template($app, $app['database'], $app['security'], $app['translator'], $app['url_generator']);
         return $template;
     });
     // Paths
     $app['paths'] = $app->share(function () use($app) {
         return array('root_sys' => $app['root_sys'], 'sys_root' => $app['root_sys'], 'sys_data_path' => $app['sys_data_path'], 'sys_config_path' => $app['sys_config_path'], 'sys_temp_path' => $app['sys_temp_path'], 'sys_log_path' => $app['sys_log_path']);
     });
     // Chamilo data filesystem.
     $app['chamilo.filesystem'] = $app->share(function () use($app) {
         $filesystem = new ChamiloLMS\Component\DataFilesystem\DataFilesystem($app['paths'], $app['filesystem']);
         return $filesystem;
     });
     // Page controller class.
     $app['page_controller'] = $app->share(function () use($app) {
         $pageController = new PageController($app);
         return $pageController;
     });
     // Mail template generator.
     $app['mail_generator'] = $app->share(function () use($app) {
         $mailGenerator = new ChamiloLMS\Component\Mail\MailGenerator($app['twig'], $app['mailer']);
         return $mailGenerator;
     });
     // Setting up name conventions
     $conventions = (require_once $app['sys_root'] . 'main/inc/lib/internationalization_database/name_order_conventions.php');
     if (isset($configuration['name_order_conventions']) && !empty($configuration['name_order_conventions'])) {
         $conventions = array_merge($conventions, $configuration['name_order_conventions']);
     }
     $search1 = array('FIRST_NAME', 'LAST_NAME', 'TITLE');
     $replacement1 = array('%F', '%L', '%T');
     $search2 = array('first_name', 'last_name', 'title');
     $replacement2 = array('%f', '%l', '%t');
     $keyConventions = array_keys($conventions);
     foreach ($keyConventions as $key) {
         $conventions[$key]['format'] = str_replace($search1, $replacement1, $conventions[$key]['format']);
         $conventions[$key]['format'] = _api_validate_person_name_format(_api_clean_person_name(str_replace('%', ' %', str_ireplace($search2, $replacement2, $conventions[$key]['format']))));
         $conventions[$key]['sort_by'] = strtolower($conventions[$key]['sort_by']) != 'last_name' ? true : false;
     }
     $app['name_order_conventions'] = $conventions;
 }