From: Stéphane Jacob Date: Mon, 30 May 2011 13:42:38 +0000 (+0200) Subject: Introduces secondary education. X-Git-Tag: xorg/1.1.2~65 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=fb052bdeb13817b3dda3f7443fe7b2717b7413ca;p=platal.git Introduces secondary education. Diploma from our university cannot be added by hand anymore. Only data from the university will be included. Signed-off-by: Stéphane Jacob --- diff --git a/include/education.func.inc.php b/include/education.func.inc.php index 9c7ab44..cb25855 100644 --- a/include/education.func.inc.php +++ b/include/education.func.inc.php @@ -28,8 +28,9 @@ function education_options($current = 0) LEFT JOIN geoloc_countries AS gc ON (e.country = gc.iso_3166_1_a2) WHERE EXISTS (SELECT * FROM profile_education_degree AS d - WHERE e.id = d.eduid) - ORDER BY gc.country, e.name"); + WHERE e.id = d.eduid) AND e.name != {?} + ORDER BY gc.country, e.name", + Profile::EDU_X); $country = ""; while ($arr_edu = $res->next()) { if ($arr_edu["country"] != $country) { diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 08b09ca..6eef643 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -198,7 +198,7 @@ class ProfileSettingEdu implements ProfileSetting $value = array(); $value = XDB::fetchAllAssoc("SELECT eduid, degreeid, fieldid, grad_year, program FROM profile_education - WHERE pid = {?} AND !FIND_IN_SET('primary', flags) + WHERE pid = {?} AND !(FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags)) ORDER BY id", $page->pid()); } else if (!is_array($value)) { @@ -229,10 +229,11 @@ class ProfileSettingEdu implements ProfileSetting public function save(ProfilePage $page, $field, $value) { XDB::execute("DELETE FROM profile_education - WHERE pid = {?} AND !FIND_IN_SET('primary', flags)", + WHERE pid = {?} AND !(FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags))", $page->pid()); + $schoolsList = DirEnum::getOptions(DirEnum::EDUSCHOOLS); foreach ($value as $eduid=>&$edu) { - if ($edu['eduid'] != '') { + if ($edu['eduid'] != '' && $schoolsList[$edu['eduid']] != Profile::EDU_X) { $fieldId = ($edu['fieldid'] == 0) ? null : $edu['fieldid']; XDB::execute("INSERT INTO profile_education SET id = {?}, pid = {?}, eduid = {?}, degreeid = {?}, @@ -301,8 +302,8 @@ class ProfileSettingMainEdu implements ProfileSetting $value = array(); $value = XDB::fetchAllAssoc("SELECT degreeid, fieldid, promo_year, program FROM profile_education - WHERE pid = {?} AND FIND_IN_SET('primary', flags) - ORDER BY degreeid", + 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) { @@ -327,7 +328,7 @@ class ProfileSettingMainEdu implements ProfileSetting $fieldId = ($item['fieldid'] == 0) ? null : $item['fieldid']; XDB::execute("UPDATE profile_education SET fieldid = {?}, program = {?} - WHERE pid = {?} AND FIND_IN_SET('primary', flags) AND degreeid = {?}", + WHERE pid = {?} AND (FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags)) AND degreeid = {?}", $fieldId, $item['program'], $page->pid(), $item['degreeid']); } } diff --git a/upgrade/1.1.2/04_education.sql b/upgrade/1.1.2/04_education.sql new file mode 100644 index 0000000..9249af7 --- /dev/null +++ b/upgrade/1.1.2/04_education.sql @@ -0,0 +1,57 @@ +-- Adds secondary education. + +ALTER TABLE profile_education MODIFY COLUMN flags SET('primary', 'secondary', 'completed') NOT NULL DEFAULT ''; + + UPDATE profile_education AS pe +INNER JOIN profile_education_enum AS pen ON (pe.eduid = pen.id) + SET pe.flags = IF(pe.flags = '', 'secondary', 'secondary,completed') + WHERE pen.abbreviation = 'X' AND NOT FIND_IN_SET('primary', flags); + +-- Updates secondary education details. + +UPDATE profile_education + SET degreeid = 33 + WHERE FIND_IN_SET('secondary', flags) AND (degreeid = 4 OR degreeid = 6); + +UPDATE profile_education + SET degreeid = 5 + WHERE FIND_IN_SET('secondary', flags) AND degreeid IS NULL; + +UPDATE profile_education + SET promo_year = grad_year + WHERE FIND_IN_SET('secondary', flags); + +-- Removes duplicates. + DELETE e1 + FROM profile_education AS e1 +INNER JOIN profile_education AS e2 ON (e1.pid = e2.pid AND e1.degreeid = e2.degreeid AND e1.id < e2.id + AND FIND_IN_SET('secondary', e1.flags) AND FIND_IN_SET('secondary', e2.flags)) + WHERE e1.fieldid IS NULL AND e1.program IS NULL; + DELETE e1 + FROM profile_education AS e1 +INNER JOIN profile_education AS e2 ON (e1.pid = e2.pid AND e1.degreeid = e2.degreeid AND e1.id > e2.id + AND FIND_IN_SET('secondary', e1.flags) AND FIND_IN_SET('secondary', e2.flags)) + WHERE e1.fieldid IS NULL AND e1.program IS NULL; + +-- Updates secondary education ids. + UPDATE profile_education AS e1 +LEFT JOIN profile_education AS e2 ON (e1.pid = e2.pid AND e1.degreeid = e2.degreeid AND e1.id != e2.id AND FIND_IN_SET('secondary', e2.flags)) + SET e1.id = 101 + WHERE FIND_IN_SET('secondary', e1.flags) AND e1.degreeid = 33 AND e2.pid IS NULL; + + UPDATE profile_education AS e1 +INNER JOIN profile_education AS e2 ON (e1.pid = e2.pid AND e1.degreeid = e2.degreeid AND e1.id > e2.id) + SET e1.id = 101, e2.id = 102 + WHERE FIND_IN_SET('secondary', e1.flags) AND FIND_IN_SET('secondary', e2.flags) AND e1.degreeid = 33; + + UPDATE profile_education AS e1 +LEFT JOIN profile_education AS e2 ON (e1.pid = e2.pid AND e2.degreeid = 33 AND FIND_IN_SET('secondary', e2.flags)) + SET e1.id = 101 + WHERE FIND_IN_SET('secondary', e1.flags) AND e1.degreeid = 5 AND e2.pid IS NULL; + + UPDATE profile_education AS e1 +INNER JOIN profile_education AS e2 ON (e1.pid = e2.pid AND e2.degreeid = 33) + SET e1.id = 102 + WHERE FIND_IN_SET('secondary', e1.flags) AND FIND_IN_SET('secondary', e2.flags) AND e1.degreeid = 5; + +-- vim:set syntax=mysql: