* Profile:
- #1381: Adds levels to medals -JAC
+ - #1446: Adds field for sports and hobbies -JAC
- #1535: Moves and displays skills with mentoring informations -JAC
* XnetGrp:
$('#networking_' + i).find("[name='networking[" + i + "][name]']").val($('#networking_' + i).find('select option:selected').text());
}
+// Hobby {{{1
+
+function addHobby()
+{
+ var i = 0;
+ while ($('#hobby_' + i).length != 0) {
+ ++i;
+ }
+ var html = '<tr id="hobby_' + i + '">'
+ + ' <td colspan="2">'
+ + ' <div style="float: left; width: 200px;">'
+ + ' <span class="flags">'
+ + ' <input type="checkbox" name="hobbies[' + i + '][pub]"/>'
+ + ' <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
+ + ' </span> '
+ + ' <select name="hobbies[' + i + '][type]">'
+ + ' <option value="Sport">Sport</option>'
+ + ' <option value="Loisir">Loisir</option>'
+ + ' <option value="Hobby">Hobby</option>'
+ + ' </select>'
+ + ' </div>'
+ + ' <div style="float: left">'
+ + ' <input type="text" name="hobbies[' + i + '][text]" value="" size="30"/>'
+ + ' <a href="javascript:removeHobby(' + i + ')">'
+ + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
+ + ' </a>'
+ + ' </div>'
+ + ' </td>'
+ + '</tr>';
+
+ $('#hobby').before(html);
+}
+
+function removeHobby(id)
+{
+ $('#hobby_' + id).remove();
+}
+
// Addresses {{{1
function toggleAddress(id, val)
$educations = array();
foreach ($value as $item) {
$details = array($this->cycles[$item['degreeid']]);
- if ($education['program']) {
- $details[] = '« ' . $education['program'] . ' »';
+ if ($item['program']) {
+ $details[] = '« ' . $item['program'] . ' »';
}
- if ($education['fieldid']) {
- $details[] = $fieldsList[$education['fieldid']];
+ if ($item['fieldid']) {
+ $details[] = $fieldsList[$item['fieldid']];
}
}
return implode(', ', $educations);
}
}
+class ProfileSettingHobby implements ProfileSetting
+{
+ private $pub;
+ static private $type = array('Sport', 'Loisir', 'Hobby');
+
+ public function __construct()
+ {
+ $this->pub = new ProfileSettingPub();
+ }
+
+ public function value(ProfilePage $page, $field, $value, &$success)
+ {
+ if (is_null($value)) {
+ $value = XDB::fetchAllAssoc('SELECT type, text, pub
+ FROM profile_hobby
+ WHERE pid = {?}',
+ $page->pid());
+ }
+ if (!is_array($value)) {
+ return array();
+ }
+ $success = true;
+ foreach($value as $i => &$hobby) {
+ $hobby['text'] = trim($hobby['text']);
+ if (!$hobby['text'] ||!in_array($hobby['type'], self::$type)) {
+ unset($value[$i]);
+ } else {
+ if (!isset($hobby['pub'])) {
+ $hobby['pub'] = 'private';
+ }
+ $s = true;
+ $hobby['pub'] = $this->pub->value($page, 'pub', $hobby['pub'], $s);
+ $success = $success && $s;
+ }
+ }
+ return $value;
+ }
+
+ public function save(ProfilePage $page, $field, $value)
+ {
+ XDB::execute('DELETE FROM profile_hobby
+ WHERE pid = {?}',
+ $page->pid());
+ if (!count($value)) {
+ return;
+ }
+ foreach ($value as $id => $hobby) {
+ XDB::execute("INSERT INTO profile_hobby (pid, id, type, text, pub)
+ VALUES ({?}, {?}, {?}, {?}, {?})",
+ $page->pid(), $id, $hobby['type'], $hobby['text'], $hobby['pub']);
+ }
+ }
+
+ public function getText($value) {
+ static $pubs = array('public' => 'publique', 'private' => 'privé');
+ $hobbies = array();
+ foreach (self::$type as $type) {
+ $hobbies[$type] = array();
+ }
+ foreach ($value as $hobby) {
+ $hobbies[$hobby['type']][] = $hobby['text'] . ' (affichage ' . $pubs[$hobby['pub']] . ')';
+ }
+ $text = array();
+ foreach (self::$type as $type) {
+ if (!empty($hobbies[$type])) {
+ $text[] = $hobbies[$type] . ' : ' . implode(', ' , $hobbies[$type]);
+ }
+ }
+ return implode(', ' , $text);
+ }
+}
+
+
class ProfileSettingPromo implements ProfileSetting
{
public function __construct(){}
$this->settings['edus'] = new ProfileSettingEdu();
$this->settings['main_edus'] = new ProfileSettingMainEdu();
$this->settings['promo'] = new ProfileSettingPromo();
+ $this->settings['hobbies'] = new ProfileSettingHobby();
$this->watched = array('tels' => true,
'networking' => true, 'edus' => true,
'nationality1' => true, 'nationality2' => true,
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2011 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+{if !hasPerm('directory_private') && ($hobby.pub eq 'private') && !empty($hobby.text|smarty:nodefaults)}
+{assign var=hiddenhobby value=true}
+{else}
+{assign var=hiddenhobby value=false}
+{/if}
+
+<tr id="hobby_{$i}">
+ <td colspan="2">
+ <div style="float: left; width: 200px;">
+ <span class="flags">
+ <label>
+ <input type="checkbox" {if $hobby.pub neq 'private'}checked="checked"{/if}
+ {if $hiddenhobby} disabled="disabled"{/if} name="hobbies[{$i}][pub]" />
+ {icon name="flag_green" title="site public"}
+ </label>
+ </span>
+ <input type="hidden" name="hobbies[{$i}][type]" value="{$hobby.type}" />
+ <span>{$hobby.type}</span>
+ </div>
+ <div style="float: left">
+ {if $hiddenhobby}
+ <input type="hidden" name="hobbies[{$i}][text]" value="{$hobby.text}" />
+ (masqué)
+ {else}
+ <input type="text" name="hobbies[{$i}][text]" value="{$hobby.text}" size="30" />
+ {/if}
+ <a href="javascript:removeHobby({$i})">
+ {icon name=cross title="Supprimer cet élément"}
+ </a>
+ </div>
+ </td>
+</tr>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
</div>
</td>
</tr>
+ <tr>
+ <td colspan="2">
+ <span class="titre">Sports, loisirs, hobbies…</span>
+ </td>
+ </tr>
+ {foreach from=$hobbies item=hobby key=id}
+ {include file="profile/general.hobby.tpl" hobby=$hobby i=$id}
+ {/foreach}
+ <tr id="hobby">
+ <td colspan="2">
+ <div id="hobby_add" class="center">
+ <a href="javascript:addHobby();">
+ {icon name=add title="Ajouter un hobby"} Ajouter un hobby
+ </a>
+ </div>
+ </td>
+ </tr>
<tr class="pair">
<td>
<div>
--- /dev/null
+CREATE TABLE profile_hobby (
+ pid INT(11) UNSIGNED NOT NULL DEFAULT 0,
+ id TINYINT(3) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'number of the hobby for the user',
+ type ENUM('Sport', 'Loisir', 'Hobby') NOT NULL DEFAULT 'Hobby',
+ text VARCHAR(255) NOT NULL DEFAULT '',
+ pub ENUM('hidden','private','ax','public') NOT NULL DEFAULT 'private',
+ PRIMARY KEY (pid, id),
+ KEY pid (pid),
+ CONSTRAINT FOREIGN KEY (pid) REFERENCES profiles (pid) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+-- vim:set syntax=mysql: