- XDB::execute("DELETE FROM entreprises
- WHERE uid = {?}",
- S::i('uid'));
- $i = 0;
- foreach ($value as &$job) {
- XDB::execute("INSERT INTO entreprises (uid, entrid, entreprise, secteur, ss_secteur,
- fonction, poste, adr1, adr2, adr3, postcode,
- city, cityid, country, region, regiontxt,
- tel, fax, mobile, email, web,
- pub, adr_pub, tel_pub, email_pub, flags,
- glat, glng)
- VALUES ({?}, {?}, {?}, {?}, {?},
- {?}, {?}, {?}, {?}, {?}, {?},
- {?}, {?}, {?}, {?}, {?},
- {?}, {?}, {?}, {?}, {?},
- {?}, {?}, {?}, {?}, {?},
- {?}, {?})",
- S::i('uid'), $i++, $job['name'], $job['secteur'], $job['ss_secteur'],
- $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'],
- $job['adr']['postcode'],
- $job['adr']['city'], $job['adr']['cityid'], $job['adr']['country'], $job['adr']['region'],
- $job['adr']['regiontxt'],
- $job['tel'], $job['fax'], $job['mobile'], $job['email'], $job['web'],
- $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub'],
- $job['adr']['checked'] ? 'geoloc' : '', $job['adr']['precise_lat'],
- $job['adr']['precise_lon']);
+ XDB::execute("DELETE FROM profile_job
+ WHERE pid = {?}",
+ $page->pid());
+ XDB::execute("DELETE FROM profile_job_term
+ WHERE pid = {?}",
+ $page->pid());
+ Address::deleteAddresses($page->pid(), Address::LINK_JOB);
+ Phone::deletePhones($page->pid(), Phone::LINK_JOB);
+ $terms_values = array();
+ foreach ($value as $id => &$job) {
+ if (isset($job['name']) && $job['name']) {
+ if (isset($job['jobid']) && $job['jobid']) {
+ XDB::execute('INSERT INTO profile_job (pid, id, description, email,
+ url, pub, email_pub, jobid)
+ VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
+ $page->pid(), $id, $job['description'], $job['w_email'],
+ $job['w_url'], $job['pub'], $job['w_email_pub'], $job['jobid']);
+ } else {
+ XDB::execute('INSERT INTO profile_job (pid, id, description, email,
+ url, pub, email_pub)
+ VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})',
+ $page->pid(), $id, $job['description'], $job['w_email'],
+ $job['w_url'], $job['pub'], $job['w_email_pub']);
+ }
+ $address = new Address(array_merge($job['w_address'],
+ array('pid' => $page->pid(),
+ 'id' => $id,
+ 'type' => Address::LINK_JOB)));
+ $address->save();
+ Phone::savePhones($job['w_phone'], $page->pid(), Phone::LINK_JOB, $id);
+ if (isset($job['terms'])) {
+ foreach ($job['terms'] as $term) {
+ $terms_values[] = XDB::format('({?}, {?}, {?}, {?})',
+ $page->pid(), $id, $term['jtid'], "original");
+ }
+ }
+ }
+ }
+ if (count($terms_values) > 0) {
+ XDB::rawExecute('INSERT INTO profile_job_term (pid, jid, jtid, computed)
+ VALUES ' . implode(', ', $terms_values) . '
+ ON DUPLICATE KEY UPDATE computed = VALUES(computed)');
+ }
+ }
+
+ public function getText($value)
+ {
+ $jobs = array();
+ foreach ($value as $id => $job) {
+ $address = Address::formArrayToString(array($job['w_address']));
+ $phones = Phone::formArrayToString($job['w_phone']);
+ // TODO: add jobterms here.
+ $jobs[] = 'Entreprise : ' . $job['name']
+ . ', description : ' . $job['description'] . ', web : ' . $job['w_url']
+ . ', email : ' . $job['w_email']
+ . ($phones ? ', ' . $phones : '') . ($address ? ', ' . $address : '');
+ }
+ return implode(' ; ' , $jobs);
+ }
+}
+
+class ProfileSettingCorps implements ProfileSetting
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $success = true;
+ if (is_null($value)) {
+ $res = XDB::query("SELECT original_corpsid AS original, current_corpsid AS current,
+ rankid AS rank, corps_pub AS pub
+ FROM profile_corps
+ WHERE pid = {?}",
+ $page->pid());
+ return $res->fetchOneAssoc();