Gives details about main education (field and program).
authorStéphane Jacob <sj@m4x.org>
Wed, 20 Apr 2011 13:23:17 +0000 (15:23 +0200)
committerStéphane Jacob <sj@m4x.org>
Thu, 21 Apr 2011 16:33:53 +0000 (18:33 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/profile.php
modules/profile/general.inc.php
templates/profile/general.tpl

index 5e113a4..92a5ae2 100644 (file)
@@ -113,6 +113,7 @@ class Profile implements PlExportable
         'networking'      => 'Messageries…',
         'tels'            => 'Téléphones',
         'edus'            => 'Formations',
+        'main_edus'       => 'Formations à l\'X',
         'promo'           => 'Promotion de sortie',
         'birthdate'       => 'Date de naissance',
         'yourself'        => 'Nom affiché',
index 85c3dd5..6c29940 100644 (file)
@@ -346,6 +346,75 @@ class ProfileSettingEdu implements ProfileSetting
     }
 }
 
+class ProfileSettingMainEdu implements ProfileSetting
+{
+    private $cycles;
+
+    public function __construct()
+    {
+        $eduDegrees = DirEnum::getOptions(DirEnum::EDUDEGREES);
+        $eduDegrees = array_flip($eduDegrees);
+        $this->cycles = array(
+            $eduDegrees[Profile::DEGREE_X] => 'Cycle polytechnicien',
+            $eduDegrees[Profile::DEGREE_M] => 'Cycle master',
+            $eduDegrees[Profile::DEGREE_D] => 'Cycle doctoral'
+        );
+    }
+
+    public function value(ProfilePage $page, $field, $value, &$success)
+    {
+        $success = true;
+        if (is_null($value)) {
+            $value = array();
+            $value = XDB::fetchAllAssoc("SELECT  degreeid, fieldid, promo_year, program
+                                           FROM  profile_education
+                                          WHERE  pid = {?} AND FIND_IN_SET('primary', flags)
+                                       ORDER BY  degreeid",
+                                        $page->pid());
+
+            foreach ($value as &$item) {
+                $item['cycle'] = $this->cycles[$item['degreeid']];
+            }
+        } elseif (!is_array($value)) {
+            $value = array();
+        } else {
+            foreach ($value as $key => $item) {
+                if (!isset($item['degreeid'])) {
+                    unset($value[$key]);
+                }
+            }
+        }
+
+        return $value;
+    }
+
+    public function save(ProfilePage $page, $field, $value)
+    {
+        foreach ($value as $item) {
+            $fieldId = ($item['fieldid'] == 0) ? null : $item['fieldid'];
+            XDB::execute("UPDATE  profile_education
+                             SET  fieldid = {?}, program = {?}
+                           WHERE  pid = {?} AND FIND_IN_SET('primary', flags) AND degreeid = {?}",
+                         $fieldId, $item['program'], $page->pid(), $item['degreeid']);
+        }
+    }
+
+    public function getText($value) {
+        $fieldsList = DirEnum::getOptions(DirEnum::EDUFIELDS);
+        $educations = array();
+        foreach ($value as $item) {
+            $details = array($this->cycles[$item['degreeid']]);
+            if ($education['program']) {
+                $details[] = '« ' . $education['program'] . ' »';
+            }
+            if ($education['fieldid']) {
+                $details[] = $fieldsList[$education['fieldid']];
+            }
+        }
+        return implode(', ', $educations);
+    }
+}
+
 class ProfileSettingEmailDirectory implements ProfileSetting
 {
     public function __construct(){}
@@ -551,6 +620,7 @@ class ProfilePageGeneral extends ProfilePage
         $this->settings['networking'] = new ProfileSettingNetworking();
         $this->settings['tels']   = new ProfileSettingPhones();
         $this->settings['edus']   = new ProfileSettingEdu();
+        $this->settings['main_edus'] = new ProfileSettingMainEdu();
         $this->settings['promo']  = new ProfileSettingPromo();
         $this->watched= array('tels' => true,
                               'networking' => true, 'edus' => true,
index ede21f9..e23aec5 100644 (file)
   </tr>
 </table>
 
+<table class="bicol" style="margin-bottom: 1em" summary="Profil&nbsp;: Formations à l'X">
+  <tr>
+    <th colspan="2">
+      <div class="flags" style="float: left">
+        <input type="checkbox" disabled="disabled" checked="checked" />
+        {icon name="flag_green" title="site public"}
+      </div>
+      Formations à l'École polytechnique
+    </th>
+  </tr>
+  {foreach from=$main_edus key=eduid item=main_edu}
+  {cycle values="impair, pair" assign=class}
+  <tr class="{$class}">
+    <td><span class="titre">Cycle&nbsp;:</span></td>
+    <td>{$main_edu.cycle}</td>
+  </tr>
+  <tr class="{$class}">
+    <td><span class="titre">Promotion&nbsp;:</span></td>
+    <td>{$main_edu.promo_year}</td>
+  </tr>
+  <tr class="{$class}">
+    <td><span class="titre">Domaine de formation&nbsp;:</span></td>
+    <td>
+      <select name="main_edus[{$main_edu.degreeid}][fieldid]">
+        <option value="">&nbsp;</option>
+        {foreach from=$edu_fields item=field}
+        <option value="{$field.id}" {if $field.id eq $main_edu.fieldid}selected="selected"{/if}>{$field.field}</option>
+        {/foreach}
+      </select>
+    </td>
+  </tr>
+  <tr class="{$class}">
+    <td><span class="titre">Description de la formation&nbsp;:</span></td>
+    <td>
+      <input type="text" name="main_edus[{$main_edu.degreeid}][program]" value="{$main_edu.program}" size="30" maxlength="255" />
+      <input type="hidden" name="main_edus[{$main_edu.degreeid}][degreeid]" value="{$main_edu.degreeid}" />
+      <input type="hidden" name="main_edus[{$main_edu.degreeid}][cycle]" value="{$main_edu.cycle}" />
+    </td>
+  </tr>
+  {/foreach}
+</table>
+
 <table class="bicol" style="margin-bottom: 1em" summary="Profil&nbsp;: Formations">
   <tr>
     <th colspan="2">