+
+ public function getText($value) {
+ static $pubs = array('public' => 'publique', 'ax' => 'annuaire AX', 'private' => 'privé');
+ $networkings = array();
+ foreach ($value as $network) {
+ $networkings[] = $network['name'] . ' : ' . $network['address'] . ' (affichage ' . $pubs[$network['pub']] . ')';
+ }
+ return implode(', ' , $networkings);
+ }
+}
+
+class ProfileSettingPromo implements ProfileSetting
+{
+ public function __construct(){}
+
+ public function save(ProfilePage $page, $field, $value)
+ {
+ $gradYearNew = $value;
+ if ($page->profile->mainEducation() == 'X') {
+ $gradYearNew += $page->profile->mainEducationDuration();
+ }
+ if (($page->profile->mainEducation() != 'X'
+ && $value == $page->profile->entry_year + $page->profile->mainEducationDuration())
+ || ($page->profile->mainEducation() == 'X' && $value == $page->profile->entry_year)) {
+ XDB::execute('UPDATE profile_display
+ SET promo = {?}
+ WHERE pid = {?}',
+ $page->profile->mainEducation() . strval($value), $page->profile->id());
+ XDB::execute('UPDATE profile_education
+ SET grad_year = {?}
+ WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)',
+ $gradYearNew, $page->profile->id());
+ Platal::page()->trigSuccess('Ton statut « orange » a été supprimé.');
+ } else {
+ $myorange = new OrangeReq(S::user(), $page->profile, $gradYearNew);
+ $myorange->submit();
+ Platal::page()->trigSuccess('Tu pourras changer l\'affichage de ta promotion dès que ta nouvelle promotion aura été validée.');
+ }
+ }
+
+ public function value(ProfilePage $page, $field, $value, &$success)
+ {
+ $entryYear = $page->profile->entry_year;
+ $gradYear = $page->profile->grad_year;
+ $yearpromo = $page->profile->grad_year;
+ if ($page->profile->mainEducation() == 'X') {
+ $yearpromo -= $page->profile->mainEducationDuration();
+ }
+ $success = true;
+ if (is_null($value) || $value == $yearpromo) {
+ if ($gradYear != $entryYear + $page->profile->mainEducationDuration()) {
+ $promoChoice = array();
+ for ($i = $entryYear; $i <= $gradYear - $page->profile->mainEducationDuration(); ++$i) {
+ if ($page->profile->mainEducation() == 'X') {
+ $promoChoice[] = $page->profile->mainEducation() . strval($i);
+ } else {
+ $promoChoice[] = $page->profile->mainEducation() . strval($i + $page->profile->mainEducationDuration());
+ }
+ }
+ Platal::page()->assign('promo_choice', $promoChoice);
+ }
+ return $yearpromo;
+ }
+
+ // If this profile belongs to an X, $promoNew needs to be changed to
+ // the graduation year.
+ $gradYearNew = $value;
+ if ($page->profile->mainEducation() == 'X') {
+ $gradYearNew += $page->profile->mainEducationDuration();
+ }
+
+ if ($value < 1000 || $value > 9999) {
+ Platal::page()->trigError('L\'année de sortie doit être un nombre de quatre chiffres.');
+ $success = false;
+ } elseif ($gradYearNew < $entryYear + $page->profile->mainEducationDuration()) {
+ Platal::page()->trigError('Trop tôt !');
+ $success = false;
+ }
+ return intval($value);
+ }
+
+ public function getText($value) {
+ return $value;
+ }