From: Stéphane Jacob Date: Mon, 26 Sep 2011 12:32:16 +0000 (+0200) Subject: Adds field for sports and hobbies (Closes #1446). X-Git-Tag: xorg/1.1.4~130 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=8fcfc71f92d6f96e97c46413af0382d8a2e5cc1e;p=platal.git Adds field for sports and hobbies (Closes #1446). Signed-off-by: Stéphane Jacob --- diff --git a/ChangeLog b/ChangeLog index eafa66a..38da5fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,7 @@ Bug/Wish: * 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: diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index b8b1c2c..6858861 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -261,6 +261,44 @@ function updateNetworking(i) $('#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 = '' + + ' ' + + '
' + + ' ' + + ' ' + + ' site public' + + '  ' + + ' ' + + '
' + + '
' + + ' ' + + ' ' + + ' cross' + + ' ' + + '
' + + ' ' + + ''; + + $('#hobby').before(html); +} + +function removeHobby(id) +{ + $('#hobby_' + id).remove(); +} + // Addresses {{{1 function toggleAddress(id, val) diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 4bae6dd..cafddee 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -338,11 +338,11 @@ class ProfileSettingMainEdu implements ProfileSetting $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); @@ -460,6 +460,79 @@ class ProfileSettingNetworking implements ProfileSetting } } +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(){} @@ -557,6 +630,7 @@ class ProfilePageGeneral extends ProfilePage $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, diff --git a/templates/profile/general.hobby.tpl b/templates/profile/general.hobby.tpl new file mode 100644 index 0000000..6767329 --- /dev/null +++ b/templates/profile/general.hobby.tpl @@ -0,0 +1,56 @@ +{**************************************************************************} +{* *} +{* 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} + + + +
+ + +   + + {$hobby.type} +
+
+ {if $hiddenhobby} + + (masqué) + {else} + + {/if} + + {icon name=cross title="Supprimer cet élément"} + +
+ + + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/profile/general.tpl b/templates/profile/general.tpl index 52278ea..316ef39 100644 --- a/templates/profile/general.tpl +++ b/templates/profile/general.tpl @@ -366,6 +366,23 @@ + + + Sports, loisirs, hobbies… + + + {foreach from=$hobbies item=hobby key=id} + {include file="profile/general.hobby.tpl" hobby=$hobby i=$id} + {/foreach} + + + + +
diff --git a/upgrade/1.1.4/06_hobby.sql b/upgrade/1.1.4/06_hobby.sql new file mode 100644 index 0000000..0370f7b --- /dev/null +++ b/upgrade/1.1.4/06_hobby.sql @@ -0,0 +1,12 @@ +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: