<?php
/***************************************************************************
- * Copyright (C) 2003-2011 Polytechnique.org *
+ * Copyright (C) 2003-2014 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-// Some particles should not be capitalized (cf "ORTHOTYPO", by Jean-Pierre
-// Lacroux).
-// Note that some of them are allowed to use capital letters in some cases,
-// for instance "De" in American English.
-static $particles = array('d', 'de', 'an', 'auf', 'von', 'von dem',
- 'von der', 'zu', 'of', 'del', 'de las',
- 'de les', 'de los', 'las', 'los', 'y', 'a',
- 'da', 'das', 'do', 'dos', 'af', 'av');
+class Particles
+{
+ // Some particles should not be capitalized (cf "ORTHOTYPO", by Jean-Pierre
+ // Lacroux).
+ // Note that some of them are allowed to use capital letters in some cases,
+ // for instance "De" in American English.
+ public static $particles = array('d', 'de', 'an', 'auf', 'von', 'von dem',
+ 'von der', 'zu', 'of', 'del', 'de las',
+ 'de les', 'de los', 'las', 'los', 'y', 'a',
+ 'da', 'das', 'do', 'dos', 'af', 'av');
+}
function build_javascript_names($data, $isFemale)
$firstname = build_first_name($public_names);
$display_names = array();
- $display_names['public_name'] = $firstname . ' ' . $full_last_name;
+ $display_names['public_name'] = build_full_name($firstname, $full_last_name);
$display_names['private_name'] = $display_names['public_name'] . $private_last_name_end;
- $display_names['directory_name'] = $full_last_name . ' ' . $firstname;
- $display_names['short_name'] = $firstname . ' ' . $short_last_name;
- $display_names['sort_name'] = $short_last_name . ' ' . $firstname;
+ $display_names['directory_name'] = build_directory_name($firstname, $full_last_name);
+ $display_names['short_name'] = build_full_name($firstname, $short_last_name);
+ $display_names['sort_name'] = build_sort_name($firstname, $short_last_name);
return $display_names;
}
return ' (' . implode(', ', $names_array) . ')';
}
+function build_directory_name($firstname, $lastname)
+{
+ if ($firstname == '') {
+ return mb_strtoupper($lastname);
+ }
+ return mb_strtoupper($lastname) . ' ' . $firstname;
+}
+
+function build_full_name($firstname, $lastname)
+{
+ if ($firstname == '') {
+ return $lastname;
+ }
+ return $firstname . ' ' . $lastname;
+}
+
+// Returns the name on which the sort is performed, according to French
+// typographic rules.
+function build_sort_name($firstname, $lastname)
+{
+ // Remove uncapitalized particles.
+ $particles = "/^(d'|(" . implode(Particles::$particles, '|') . ') )/';
+ $name = preg_replace($particles, '', $lastname);
+ // Mac must also be uniformized.
+ $lastname = preg_replace("/^(Mac|Mc)( |)/", 'Mac', $name);
+
+ if ($firstname == '') {
+ return $lastname;
+ }
+ return $lastname . ' ' . $firstname;
+}
+
/** Splits a name into tokens, as used in search_name.
* Used for search_name rebuilding and for queries.
*/
INNER JOIN profile_display AS pd ON (pd.pid = ap.pid)
SET a.lastname = IF(ppn.lastname_ordinary = '', ppn.lastname_main, ppn.lastname_ordinary),
a.firstname = IF(ppn.firstname_ordinary = '', ppn.firstname_main, ppn.firstname_ordinary),
- a.full_name = pd.short_name, a.directory_name = pd.directory_name
+ a.full_name = pd.short_name, a.directory_name = pd.directory_name, a.sort_name = pd.sort_name
WHERE a.uid = {?}",
$uid);
}
// Extracts the first token of the name.
if (!preg_match('/^(\pL+)(([\' -])(.*))?$/ui', $name, $m)) {
- return false;
+ return '';
}
$token = mb_strtolower($m[1]);
}
// Capitalizes the first token.
- if (!in_array($token, $particles)) {
+ if (!in_array($token, Particles::$particles)) {
$token = mb_ucfirst($token);
}
if (($tail = capitalize_name($tail))) {
return $token . $separator . $tail;
}
- return false;
+ return '';
}
return $token . $separator;
}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
?>