+ foreach ($value as $id => $education) {
+ // XXX: the following condition should be removed once there are no more incomplete educations.
+ if (is_null($education['eduid']) || is_null($education['degreeid'])) {
+ if (is_null($education['eduid']) && is_null($education['degreeid'])) {
+ $educations[$id] = 'formation manquante';
+ } else {
+ $educations[$id] = (is_null($education['eduid']) ? 'université manquante' : $schoolsList[$education['eduid']]) . ', '
+ . (is_null($education['degreeid']) ? 'diplôme manquant' : $degreesList[$education['degreeid']]);
+ }
+ } else {
+ $educations[$id] = $schoolsList[$education['eduid']] . ', ' . $degreesList[$education['degreeid']];
+ }
+
+ $details = array();
+ if ($education['grad_year']) {
+ $details[] = $education['grad_year'];
+ }
+ if ($education['program']) {
+ $details[] = '« ' . $education['program'] . ' »';
+ }
+ if ($education['fieldid']) {
+ $details[] = $fieldsList[$education['fieldid']];
+ }
+ if (count($details)) {
+ $educations[$id] .= ' (' . implode(', ', $details) . ')';
+ }
+ }
+ return implode(', ', $educations);
+ }
+}
+
+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) OR FIND_IN_SET('secondary', flags))
+ ORDER BY NOT FIND_IN_SET('primary', flags), 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) OR FIND_IN_SET('secondary', 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 ($item['program']) {
+ $details[] = '« ' . $item['program'] . ' »';
+ }
+ if ($item['fieldid']) {
+ $details[] = $fieldsList[$item['fieldid']];
+ }