Updates language table for better compatibility with iso codes.
authorStéphane Jacob <sj@m4x.org>
Wed, 5 Jan 2011 17:17:46 +0000 (18:17 +0100)
committerStéphane Jacob <sj@m4x.org>
Wed, 5 Jan 2011 17:55:38 +0000 (18:55 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
bin/cron/clean.php
modules/profile/skills.inc.php
templates/profile/skill.tpl
upgrade/1.1.0/06_language.sql [new file with mode: 0644]
upgrade/1.1.0/languages.php [new file with mode: 0755]

index add5458..5925900 100755 (executable)
@@ -48,7 +48,7 @@ query('ALTER TABLE  profile_education_field_enum
 query('ALTER TABLE  profile_job_enum
           ORDER BY  name');
 query('ALTER TABLE  profile_langskill_enum
-          ORDER BY  langue_fr');
+          ORDER BY  language');
 query('ALTER TABLE  profile_medal_enum
           ORDER BY  text');
 query('ALTER TABLE  profile_networking_enum
index 21e3aa6..2ad367e 100644 (file)
 class ProfileSettingSkill implements ProfileSetting
 {
     private $table;
+    private $id;
     private $skill_field;
     private $text_field;
 
-    public function __construct($table, $skill, $text)
+    public function __construct($table, $id, $skill, $text)
     {
         $this->table = $table;
+        $this->id = $id;
         $this->skill_field = $skill;
         $this->text_field = $text;
     }
@@ -36,9 +38,9 @@ class ProfileSettingSkill implements ProfileSetting
     {
         if (is_null($value)) {
             $value = array();
-            $res = XDB::iterRow("SELECT  s.id, s.{$this->text_field}, i.level
+            $res = XDB::iterRow("SELECT  s.{$this->id}, s.{$this->text_field}, i.level
                                    FROM  profile_{$this->table}_enum AS s
-                             INNER JOIN  profile_{$this->table}s AS i ON(s.id = i.{$this->skill_field})
+                             INNER JOIN  profile_{$this->table}s     AS i ON (s.{$this->id} = i.{$this->skill_field})
                                   WHERE  i.pid = {?}",
                                 $page->pid());
             while (list($sid, $text, $level) = $res->next()) {
@@ -52,7 +54,7 @@ class ProfileSettingSkill implements ProfileSetting
                 if (!isset($skill['text']) || empty($skill['text'])) {
                     $res = XDB::query("SELECT  {$this->text_field}
                                          FROM  profile_{$this->table}_enum
-                                        WHERE  id = {?}", $id);
+                                        WHERE  {$this->id} = {?}", $id);
                     $skill['text'] = $res->fetchOneCell();
                 }
             }
@@ -109,8 +111,8 @@ class ProfilePageSkills extends ProfilePage
     public function __construct(PlWizard &$wiz)
     {
         parent::__construct($wiz);
-        $this->settings['competences'] = new ProfileSettingSkill('skill', 'cid', 'text_fr');
-        $this->settings['langues'] = new ProfileSettingSkill('langskill', 'lid', 'langue_fr');
+        $this->settings['competences'] = new ProfileSettingSkill('skill', 'id', 'cid', 'text_fr');
+        $this->settings['langues'] = new ProfileSettingSkill('langskill', 'iso_639_2b', 'lid', 'language');
     }
 
     public function _prepare(PlPage &$page, $id)
@@ -120,9 +122,9 @@ class ProfilePageSkills extends ProfilePage
         $page->assign('comp_level', array('initié' => 'initié',
                                           'bonne connaissance' => 'bonne connaissance',
                                           'expert' => 'expert'));
-        $page->assign('lang_list', XDB::iterator("SELECT  id, langue_fr
+        $page->assign('lang_list', XDB::iterator('SELECT  iso_639_2b, language
                                                     FROM  profile_langskill_enum
-                                                ORDER BY  langue_fr"));
+                                                ORDER BY  language'));
         $page->assign('lang_level', array(1 => 'connaissance basique',
                                           2 => 'maîtrise des bases',
                                           3 => 'maîtrise limitée',
index 280aa92..7b423a8 100644 (file)
@@ -76,7 +76,7 @@
       <select name="langues_sel" onchange="updateElement('langues')">
         <option value="">&nbsp;</option>
         {iterate from=$lang_list item=lang}
-        <option value="{$lang.id}">{$lang.langue_fr}</option>
+        <option value="{$lang.iso_639_2b}">{$lang.language}</option>
         {/iterate}
       </select>
       <span id="langues_add" style="display: none">
diff --git a/upgrade/1.1.0/06_language.sql b/upgrade/1.1.0/06_language.sql
new file mode 100644 (file)
index 0000000..85d6a29
--- /dev/null
@@ -0,0 +1,12 @@
+UPDATE profile_langskill_enum SET id = SUBSTRING(id, 1, 3);
+ALTER TABLE profile_langskills DROP FOREIGN KEY profile_langskills_ibfk_2;
+ALTER TABLE profile_langskill_enum CHANGE COLUMN id iso_639_2b CHAR(3) NOT NULL DEFAULT '';
+ALTER TABLE profile_langskills ADD FOREIGN KEY (lid) REFERENCES profile_langskill_enum (iso_639_2b) ON DELETE CASCADE ON UPDATE CASCADE;
+ALTER TABLE profile_langskill_enum ADD COLUMN iso_639_2t CHAR(3) NOT NULL DEFAULT '';
+ALTER TABLE profile_langskill_enum ADD COLUMN iso_639_1 CHAR(2) DEFAULT NULL;
+ALTER TABLE profile_langskill_enum CHANGE COLUMN langue_en language_en VARCHAR(255) NOT NULL DEFAULT '';
+ALTER TABLE profile_langskill_enum CHANGE COLUMN langue_fr language VARCHAR(255) NOT NULL DEFAULT '';
+ALTER TABLE profile_langskill_enum ADD KEY (iso_639_2t);
+ALTER TABLE profile_langskill_enum ADD KEY (iso_639_1);
+
+-- vim:set syntax=mysql:
diff --git a/upgrade/1.1.0/languages.php b/upgrade/1.1.0/languages.php
new file mode 100755 (executable)
index 0000000..5736497
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/php5
+<?php
+
+require_once 'connect.db.inc.php';
+
+$globals->debug = 0; // Do not store backtraces.
+
+// First build the list provided by the iso codes.
+$list = array();
+exec('isoquery --iso=639', $list);
+
+foreach ($list as $key => $item) {
+    $array = explode("\t", $item);
+    unset($list[$key]);
+    $list[$array[0]] = array();
+    foreach (array('iso_639_2t', 'iso_639_1') as $i => $field) {
+        $list[$array[0]][$field] = $array[$i + 1];
+    }
+}
+
+$res = XDB::iterator('SELECT  iso_639_2b
+                        FROM  profile_langskill_enum
+                       WHERE  iso_639_2b IN {?}',
+                     array_keys($list));
+while ($item = $res->next()) {
+    $id = $item['iso_639_2b'];
+    XDB::execute('UPDATE  profile_langskill_enum
+                     SET  iso_639_2t = {?}, iso_639_1 = {?}
+                   WHERE  iso_639_2b = {?}',
+                 $list[$id]['iso_639_2t'], (($list[$id]['iso_639_1']) ? $list[$id]['iso_639_1'] : null), $id);
+}
+
+/* vim:set et sw=4 sts=4 ts=4: */
+?>