From 080632c746766c83d9d34388961398816925e0da Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 28 Feb 2011 22:05:51 +0100 Subject: [PATCH] Enable a DeltaTen module and profile page. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/profile.php | 62 +++++- classes/xorg.php | 2 +- configs/platal.ini | 9 + modules/deltaten.php | 95 +++++++++ modules/profile.php | 6 +- modules/profile/deltaten.inc.php | 67 +++++++ modules/profile/page.inc.php | 1 + templates/deltaten/index.tpl | 424 +++++++++++++++++++++++++++++++++++++++ templates/profile/deltaten.tpl | 59 ++++++ templates/skin/common.menu.tpl | 6 + upgrade/1.1.0/10_deltaten.sql | 7 + 11 files changed, 727 insertions(+), 11 deletions(-) create mode 100644 modules/deltaten.php create mode 100644 modules/profile/deltaten.inc.php create mode 100644 templates/deltaten/index.tpl create mode 100644 templates/profile/deltaten.tpl create mode 100644 upgrade/1.1.0/10_deltaten.sql diff --git a/classes/profile.php b/classes/profile.php index e63bfe5..177155a 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -109,10 +109,11 @@ class Profile implements PlExportable const FETCH_PHONES = 0x000100; const FETCH_JOB_TERMS = 0x000200; const FETCH_MENTOR_TERMS = 0x000400; + const FETCH_DELTATEN = 0x000800; const FETCH_MINIFICHES = 0x00012D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_NETWORKING | FETCH_PHONES - const FETCH_ALL = 0x0007FF; // OR of FETCH_* + const FETCH_ALL = 0x000FFF; // OR of FETCH_* static public $descriptions = array( 'search_names' => 'Noms', @@ -144,7 +145,8 @@ class Profile implements PlExportable 'langues' => 'Langues', 'expertise' => 'Expertises (mentoring)', 'terms' => 'Compétences (mentoring)', - 'countries' => 'Pays (mentoring)' + 'countries' => 'Pays (mentoring)', + 'deltaten' => 'Opération N N-10', ); private $fetched_fields = 0x000000; @@ -421,8 +423,8 @@ class Profile implements PlExportable /** * Clears a profile. - * *always deletes in: profile_addresses, profile_binets, profile_job, - * profile_langskills, profile_mentor, profile_networking, + * *always deletes in: profile_addresses, profile_binets, profile_deltaten, + * profile_job, profile_langskills, profile_mentor, profile_networking, * profile_phones, profile_skills, watch_profile * *always keeps in: profile_corps, profile_display, profile_education, * profile_medals, profile_name, profile_photos, search_name @@ -433,7 +435,8 @@ class Profile implements PlExportable $tables = array( 'profile_job', 'profile_langskills', 'profile_mentor', 'profile_networking', 'profile_skills', 'watch_profile', - 'profile_phones', 'profile_addresses', 'profile_binets'); + 'profile_phones', 'profile_addresses', 'profile_binets', + 'profile_deltaten'); foreach ($tables as $t) { XDB::execute('DELETE FROM ' . $t . ' @@ -804,6 +807,44 @@ class Profile implements PlExportable } } + /** DeltaTen + */ + + /** Find out whether this profile may take part to the "DeltaTen" operation. + * @param $role Which role to select ('young' or 'old') + * @return Boolean: whether it is enabled. + */ + const DELTATEN_YOUNG = 'young'; + const DELTATEN_OLD = 'old'; + public function isDeltaTenEnabled($role) + { + global $globals; + switch ($role) { + case self::DELTATEN_YOUNG: + return ($this->mainGrade() == UserFilter::GRADE_ING && $this->yearpromo() >= $globals->deltaten->first_promo_young); + case self::DELTATEN_OLD: + // Roughly compute the current promo in second year on the campus: + // Promo 2010 is in second year between 09/2011 and 08/2012 => use 2012. + // DeltaTen program begins around January of the second year. + $promo_on_platal = ((int) date('Y')) - 2; + return ($this->mainGrade() == UserFilter::GRADE_ING && $this->yearpromo() >= $globals->deltaten->first_promo_young - 10 && $this->yearpromo() <= $promo_on_platal - 10); + default: + Platal::assert(false, "Invalid DeltaTen role $role"); + } + } + + /** Retrieve the "Deltaten" message of the user. + * Returns "null" if the message is empty or the user is not taking part to the + * DeltaTen operation. + */ + public function getDeltatenMessage() + { + if ($this->isDeltaTenEnabled(self::DELTATEN_OLD)) { + return $this->deltaten_message; + } else { + return null; + } + } /* Binets */ @@ -907,16 +948,17 @@ class Profile implements PlExportable pe.entry_year, pe.grad_year, pe.promo_year, pe.program, pe.fieldid, IF ({?}, pse.text, NULL) AS section, pn_f.name AS firstname, pn_l.name AS lastname, - IF( {?}, pn_n.name, NULL) AS nickname, - IF(pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_ordinary, - IF(pn_ul.name IS NULL, pn_l.name, pn_ul.name) AS lastname_ordinary, + IF ({?}, pn_n.name, NULL) AS nickname, + IF (pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_ordinary, + IF (pn_ul.name IS NULL, pn_l.name, pn_ul.name) AS lastname_ordinary, pd.yourself, pd.promo, pd.short_name, pd.public_name AS full_name, pd.directory_name, pd.public_name, pd.private_name, - IF(pp.pub IN {?}, pp.display_tel, NULL) AS mobile, + IF (pp.pub IN {?}, pp.display_tel, NULL) AS mobile, (ph.pub IN {?} AND ph.attach IS NOT NULL) AS has_photo, ph.x AS photo_width, ph.y AS photo_height, p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old, pm.expertise AS mentor_expertise, + IF ({?}, pdt.message, NULL) AS deltaten_message, ap.uid AS owner_id FROM profiles AS p INNER JOIN profile_display AS pd ON (pd.pid = p.pid) @@ -935,6 +977,7 @@ class Profile implements PlExportable LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\') LEFT JOIN profile_photos AS ph ON (ph.pid = p.pid) LEFT JOIN profile_mentor AS pm ON (pm.pid = p.pid) + LEFT JOIN profile_deltaten AS pdt ON (pdt.pid = p.pid) LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms)) WHERE p.pid IN {?} GROUP BY p.pid @@ -945,6 +988,7 @@ class Profile implements PlExportable $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // nickname $visibility->levels(), // mobile $visibility->levels(), // photo + $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // deltaten_message $pids ); return new ProfileIterator($it, $pids, $fields, $visibility); diff --git a/classes/xorg.php b/classes/xorg.php index bdd1e85..3930d7e 100644 --- a/classes/xorg.php +++ b/classes/xorg.php @@ -28,7 +28,7 @@ class Xorg extends Platal 'profile', 'register', 'search', 'stats', 'admin', 'newsletter', 'axletter', 'epletter', 'bandeau', 'survey', 'fusionax', 'gadgets', 'googleapps', 'poison', - 'openid', 'reminder', 'api', 'urlshortener'); + 'openid', 'reminder', 'api', 'urlshortener', 'deltaten'); } public function find_hook() diff --git a/configs/platal.ini b/configs/platal.ini index a057415..ebdb03a 100644 --- a/configs/platal.ini +++ b/configs/platal.ini @@ -208,6 +208,15 @@ event_forum = "" event_reply = "" +; The deltaten section contains parameters used to handle the "N N-10" +; operation. +[Deltaten] + +; $globals->deltaten->first_promo_young +; First promo to take part to the "N N-10" operation as the "young" promo +first_promo_young = 2007 + + ; The geocoder section contains parameters used to perform the geocoding ; and the formatting of user addresses. [Geocoder] diff --git a/modules/deltaten.php b/modules/deltaten.php new file mode 100644 index 0000000..5695382 --- /dev/null +++ b/modules/deltaten.php @@ -0,0 +1,95 @@ + $this->make_hook('index', AUTH_COOKIE), + 'deltaten' => $this->make_hook('index', AUTH_COOKIE), + ); + } + + /** Check whether a given user is in a "DeltaTen" promo. + * This is based on "has a profile, is an X, and is in a young enough promo". + */ + protected function isDeltaTenEnabled(User $user, $role) + { + if (!$user->hasProfile()) { + return false; + } + return $user->profile()->isDeltaTenEnabled($role); + } + + function handler_index($page, $action='', $subaction='') + { + global $globals; + if (!$this->isDeltaTenEnabled(S::user(), Profile::DELTATEN_YOUNG)) { + $page->killError("Ta promotion ne participe pas à l'opération N N-10."); + } + + if ($this->isDeltaTenEnabled(S::user(), Profile::DELTATEN_OLD)) { + $profile = S::user()->profile(); + if ($profile->getDeltatenMessage()) { + $page->trigSuccess("Tu participes bien à l'opération N N-10 en tant qu'ancien."); + } else { + $page->trigWarning("Tu ne participes pas encore à l'opération N N-10 en tant qu'ancien."); + } + } + $page->setTitle("Opération N N-10"); + $page->assign('deltaten_promo_old', S::user()->profile()->yearpromo() - 10); + $wp = new PlWikiPage('Docs.Deltaten'); + $wp->buildCache(); + + require_once 'ufbuilder.inc.php'; + $ufb = new UFB_DeltaTenSearch(); + if (!$ufb->isEmpty()) { + require_once 'userset.inc.php'; + $ufc = $ufb->getUFC(); + if (!$ufc instanceof PFC_And) { + $ufc = new PFC_And($ufc); + } + $ufc->addChild(new UFC_DeltaTen()); + $ufc->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, S::user()->profile()->yearpromo() - 10)); + + $set = new ProfileSet($ufc); + $set->addMod('minifiche', 'Opération N N-10'); + $set->apply('deltaten/search', $page, $action, $subaction); + $nb_tot = $set->count(); + if ($nb_tot > $globals->search->private_max) { + $page->assign('formulaire', 1); + $page->trigError('Recherche trop générale.'); + $page->assign('plset_count', 0); + } else if ($nb_tot == 0) { + $page->assign('formulaire', 1); + $page->trigError("Il n'existe personne correspondant à ces critères dans la base."); + } + } + $page->changeTpl('deltaten/index.tpl'); + } +} + + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/modules/profile.php b/modules/profile.php index 9416557..b45d510 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -39,6 +39,7 @@ class ProfileModule extends PLModule 'profile/networking' => $this->make_hook('networking', AUTH_PUBLIC), 'profile/ajax/job' => $this->make_hook('ajax_job', AUTH_COOKIE, 'user', NO_AUTH), 'profile/ajax/skill' => $this->make_hook('ajax_skill', AUTH_COOKIE, 'user', NO_AUTH), + 'profile/ajax/deltaten' => $this->make_hook('ajax_deltaten', AUTH_COOKIE, 'user', NO_AUTH), 'profile/ajax/searchname' => $this->make_hook('ajax_searchname', AUTH_COOKIE, 'user', NO_AUTH), 'profile/ajax/buildnames' => $this->make_hook('ajax_buildnames', AUTH_COOKIE, 'user', NO_AUTH), 'profile/ajax/tree/jobterms' => $this->make_hook('ajax_tree_job_terms', AUTH_COOKIE, 'user', NO_AUTH), @@ -312,7 +313,7 @@ class ProfileModule extends PLModule { global $globals; - if (in_array($hrpid, array('general', 'adresses', 'emploi', 'poly', 'deco', 'skill', 'mentor'))) { + if (in_array($hrpid, array('general', 'adresses', 'emploi', 'poly', 'deco', 'skill', 'mentor', 'deltaten'))) { $aux = $opened_tab; $opened_tab = $hrpid; $hrpid = $aux; @@ -347,6 +348,9 @@ class ProfileModule extends PLModule $wiz->addPage('ProfilePageSkills', 'Compétences diverses', 'skill'); $wiz->addPage('ProfilePageMentor', 'Mentoring', 'mentor'); } + if (S::user()->checkPerms(User::PERM_DIRECTORY_PRIVATE) && $profile->isDeltatenEnabled(Profile::DELTATEN_OLD)) { + $wiz->addPage('ProfilePageDeltaten', 'Opération N N-10', 'deltaten'); + } $wiz->apply($page, 'profile/edit/' . $profile->hrid(), $opened_tab, $mode); if (!$profile->birthdate) { diff --git a/modules/profile/deltaten.inc.php b/modules/profile/deltaten.inc.php new file mode 100644 index 0000000..31ad0db --- /dev/null +++ b/modules/profile/deltaten.inc.php @@ -0,0 +1,67 @@ +settings['message'] = null; + } + + protected function _fetchData() + { + $res = XDB::query('SELECT message + FROM profile_deltaten + WHERE pid = {?}', + $this->pid()); + $this->values['message'] = $res->fetchOneCell(); + } + + protected function _saveData() + { + if ($this->changed['message']) { + $message = trim($this->values['message']); + if (empty($message)) { + XDB::execute('DELETE FROM profile_deltaten + WHERE pid = {?}', + $this->pid()); + $this->values['message'] = null; + } else { + XDB::execute('INSERT INTO profile_deltaten (pid, message) + VALUES ({?}, {?}) + ON DUPLICATE KEY UPDATE message = VALUES(message)', + $this->pid(), $message); + $this->values['message'] = $message; + } + } + } + + public function _prepare(PlPage $page, $id) + { + $page->assign('hrpid', $this->profile->hrpid); + } +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 2bc4c52..242733f 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -437,6 +437,7 @@ require_once dirname(__FILE__) . '/decos.inc.php'; require_once dirname(__FILE__) . '/jobs.inc.php'; require_once dirname(__FILE__) . '/skills.inc.php'; require_once dirname(__FILE__) . '/mentor.inc.php'; +require_once dirname(__FILE__) . '/deltaten.inc.php'; // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/templates/deltaten/index.tpl b/templates/deltaten/index.tpl new file mode 100644 index 0000000..375449a --- /dev/null +++ b/templates/deltaten/index.tpl @@ -0,0 +1,424 @@ +{**************************************************************************} +{* *} +{* 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 $plset_count} +{include core=plset.tpl} +{else} +{include wiki=Docs.Deltaten} +{/if} + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {if hasPerm('directory_private')} + + + + + {/if} + + + + + {if hasPerm('directory_private')} + + + + + {/if} + + + + + + + + + + + + + + + + + + + + + + +
+ Opération N N-10 +
+ Cette recherche est effectuée uniquement au sein des membres de la promotion {$deltaten_promo_old} participant à l'opération N N-10. +
Géographie
Ville ou code postal
Pays + + + {icon name="table" title="Tous les pays"} +
Région, province, état… + +
Département, comté… + +
+ +
Activité
Entreprise
Description
Mots-clefs + + + {icon name="table" title="Tous les mots-clefs"} +
Divers
Sexe + + + + + + +
+ + + + + +
+
Nationalité + + + {icon name="table" title="Toutes les nationalités"} +
Binet + + + {icon name="table" title="Tous les binets"} +
Groupe X + + + {icon name="table" title="Tous les groupes X"} +
Section + + + {icon name="table" title="Toutes les sections"} +
Formation
Formation + + + {icon name="table" title="Toutes les formations"} +
Diplôme + +
Opération N N-10
+ Message spécifique (recherche texte) : + + +
+ +
+
+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/profile/deltaten.tpl b/templates/profile/deltaten.tpl new file mode 100644 index 0000000..275ea31 --- /dev/null +++ b/templates/profile/deltaten.tpl @@ -0,0 +1,59 @@ +{**************************************************************************} +{* *} +{* 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 *} +{* *} +{**************************************************************************} + + + + + + + + + + + + + + +
+
+ + {icon name="flag_red" title="privé"} +
+ Expériences et expertises que tu acceptes de faire partager à la promotion N+10 : +
+

+ Si tu acceptes de participer à l'opération N N-10 pour que les camarades de la promotion plus jeune de 10 ans puisse profiter de ton expérience, il te suffit de remplir un message ci-dessous. + Cette démarche est complémentaire du « Mentoring », pour lequel tu trouveras plus de détails dans l'onglet dédié. +

+ +

+ Tu peux par exemple donner des conseils sur le choix de carrière, sur ton expérience, … +

+
+ +
+ Une fois que tu as saisi ton message, il suffit d'enregistrer les modifications en cliquant sur le bouton ci-dessous + pour apparaître dans la base de recherche "N N-10". +
+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} + diff --git a/templates/skin/common.menu.tpl b/templates/skin/common.menu.tpl index d5eda4f..ebc782b 100644 --- a/templates/skin/common.menu.tpl +++ b/templates/skin/common.menu.tpl @@ -86,6 +86,12 @@ {/if} +{if hasPerm('directory_private') && $smarty.session.user->hasProfile()} + {assign var='profile' value=$smarty.session.user->profile()} + {if $profile->isDeltaTenEnabled(#Profile::DELTATEN_YOUNG#)} + + {/if} +{/if} diff --git a/upgrade/1.1.0/10_deltaten.sql b/upgrade/1.1.0/10_deltaten.sql new file mode 100644 index 0000000..c26f3c8 --- /dev/null +++ b/upgrade/1.1.0/10_deltaten.sql @@ -0,0 +1,7 @@ +DROP TABLE IF EXISTS profile_deltaten; +CREATE TABLE `profile_deltaten` ( + `pid` int(11) unsigned NOT NULL DEFAULT '0', + `message` text NOT NULL, + PRIMARY KEY (`pid`), + CONSTRAINT FOREIGN KEY (`pid`) REFERENCES `profiles` (`pid`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 -- 2.1.4