Fixes on job edition: sector ids removal, hq simplification.
authorStéphane Jacob <sj@m4x.org>
Thu, 16 Sep 2010 17:48:40 +0000 (19:48 +0200)
committerStéphane Jacob <sj@m4x.org>
Sat, 18 Sep 2010 13:01:54 +0000 (15:01 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
include/validations/entreprises.inc.php
modules/profile/jobs.inc.php
templates/include/form.valid.edit-entreprises.tpl
templates/include/form.valid.entreprises.tpl
templates/profile/jobs.job.tpl
upgrade/1.0.1/08_profile_foreign_keys.sql
upgrade/1.0.1/99_jobs.sql [new file with mode: 0644]
upgrade/1.0.1/README [new file with mode: 0644]

index 19b7a62..e7857f2 100644 (file)
@@ -34,9 +34,9 @@ class EntrReq extends ProfileValidate
     public $NAF_code = null;
     public $AX_code = null;
 
-    public $tel;
-    public $fax;
-    public $address;
+    public $tel = null;
+    public $fax = null;
+    public $address = null;
 
     public $suggestions;
     public $rules = 'Si l\'entreprise est déjà présente sous un autre nom dans la liste des suggestions, remplacer son nom par celui-ci avant de valider. Laisser les autres champs tels quels.';
@@ -101,16 +101,12 @@ class EntrReq extends ProfileValidate
 
     protected function handle_editor()
     {
-        foreach (array('acronym', 'url', 'email', 'NAF_code') as $field) {
+        foreach (array('name', 'acronym', 'url', 'email', 'NAF_code', 'tel', 'fax', 'address') as $field) {
             $this->$field = (Env::t($field) == '' ? null : Env::t($field));
         }
         foreach (array('AX_code', 'holdingid') as $field) {
             $this->$field = (Env::i($field) == 0 ? null : Env::i($field));
         }
-        $this->name = Env::t('name');
-        $this->address['text'] = Env::t('address');
-        $this->tel = Env::t('tel');
-        $this->fax = Env::t('fax');
 
         return true;
     }
@@ -156,7 +152,7 @@ class EntrReq extends ProfileValidate
                                      'type' => 'fixed', 'display' => $this->tel, 'pub' => 'public'));
             $fax   = new Phone(array('link_type' => 'hq', 'link_id' => $jobid, 'id' => 1,
                                      'type' => 'fax', 'display' => $this->fax, 'pub' => 'public'));
-            $address = new Address(array('jobid' => $jobid, 'type' => Address::LINK_COMPANY, 'text' => $this->address['text']));
+            $address = new Address(array('jobid' => $jobid, 'type' => Address::LINK_COMPANY, 'text' => $this->address));
             $phone->save();
             $fax->save();
             $address->format();
index 73aabe5..50510df 100644 (file)
@@ -50,16 +50,6 @@ class ProfileSettingJob implements ProfileSetting
             'jobid'            => '',
             'pub'              => 'private',
             'name'             => '',
-            'hq_acronym'       => '',
-            'hq_url'           => '',
-            'hq_email'         => '',
-            'hq_address'       => $address->toFormArray(),
-            'hq_fixed'         => '',
-            'hq_fax'           => '',
-            'subSubSectorName' => null,
-            'sector'           => '0',
-            'subSector'        => '0',
-            'subSubSector'     => '0',
             'description'      => '',
             'w_url'            => '',
             'w_address'        => $address->toFormArray(),
@@ -91,24 +81,6 @@ class ProfileSettingJob implements ProfileSetting
                 }
             }
         }
-        if (!$job['subSubSectorName']) {
-            $res = XDB::query("SELECT  name
-                                 FROM  profile_job_subsubsector_enum
-                                WHERE  id = {?}",
-                              $job['subSubSector']);
-            $job['subSubSectorName'] = $res->fetchOneCell();
-        } else {
-            $res = XDB::query("SELECT  sectorid, subsectorid, id
-                                 FROM  profile_job_subsubsector_enum
-                                WHERE  name = {?}",
-                              $job['subSubSectorName']);
-            if ($res->numRows() != 1) {
-                $success = false;
-                $job['sector_error'] = true;
-            } else {
-                list($job['sector'], $job['subSector'], $job['subSubSector']) = $res->fetchOneRow();
-            }
-        }
         if (count($job['terms'])) {
             $termsid = array();
             foreach ($job['terms'] as $term) {
@@ -168,7 +140,7 @@ class ProfileSettingJob implements ProfileSetting
                 $job['tmp_name'] = $entreprise[$entr_val]->name;
                 ++$entr_val;
             } else if ($job['name'] == '') {
-                if ($job['subSubSectorName'] == '' && $job['description'] == '' && $job['w_url'] == ''
+                if ($job['description'] == '' && $job['w_url'] == ''
                     && $job['w_address']['text'] == '' && $job['w_email'] == ''
                     && count($job['w_phone']) == 1 && $job['w_phone']['tel'] == '') {
                     array_splice($value, $key, 1);
@@ -187,11 +159,6 @@ class ProfileSettingJob implements ProfileSetting
                 }
                 array_splice($value, $key, 1);
             }
-            foreach (array('sectorid', 'subsectorid', 'subsubsectorid') as $key) {
-                if ($job[$key] == 0) {
-                    $job[$key] = null;
-                }
-            }
         }
         foreach ($value as $key => &$job) {
             $address = new Address($job['w_address']);
@@ -216,17 +183,13 @@ class ProfileSettingJob implements ProfileSetting
         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, sectorid, subsectorid,
-                                                            subsubsectorid, email, url, pub, email_pub, jobid)
-                                       VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
-                                 $page->pid(), $id, $job['description'], $job['sector'], $job['subSector'],
-                                 $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub'], $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, sectorid, subsectorid,
-                                                            subsubsectorid, email, url, pub, email_pub)
-                                       VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
-                                 $page->pid(), $id, $job['description'], $job['sector'], $job['subSector'],
-                                 $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub']);
+                    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();
@@ -249,7 +212,8 @@ class ProfileSettingJob implements ProfileSetting
         foreach ($value as $id => $job) {
             $address = Address::formArrayToString($job['w_address']);
             $phones = Phone::formArrayToString($job['w_phone']);
-            $jobs[] = 'Entreprise : ' . $job['name'] . ', secteur : ' . $job['subSubSectorName']
+            // TODO: add jobterms here.
+            $jobs[] = 'Entreprise : ' . $job['name']
                     . ', description : ' . $job['description'] . ', web : ' . $job['w_url']
                     . ', email : ' . $job['w_email']
                     . ($phones ? ', ' . $phones : '') . ($address ? ', ' . $address : '');
@@ -317,41 +281,28 @@ class ProfileSettingJobs extends ProfilePage
         }
 
         // Build the jobs tree
-        $res = XDB::iterRow("SELECT  j.id, j.jobid, je.name, j.sectorid, j.subsectorid, j.subsubsectorid,
-                                     s.name, j.description, j.email, j.email_pub, j.url, j.pub,
-                                     je.acronym, je.url, je.email
-                               FROM  profile_job                   AS j
-                          LEFT JOIN  profile_job_enum              AS je ON (j.jobid = je.id)
-                          LEFT JOIN  profile_job_subsubsector_enum AS s  ON (s.id = j.subsubsectorid)
+        $res = XDB::iterRow('SELECT  j.id, j.jobid, je.name, j.description, j.email, j.email_pub,
+                                     j.url, j.pub
+                               FROM  profile_job      AS j
+                          LEFT JOIN  profile_job_enum AS je ON (j.jobid = je.id)
                               WHERE  j.pid = {?}
-                           ORDER BY  j.id",
+                           ORDER BY  j.id',
                             $this->pid());
         $this->values['jobs'] = array();
 
         $compagnies = array();
         if ($res->numRows() > 0) {
-            while (list($id, $jobid, $name, $sector, $subSector, $subSubSector,
-                        $subSubSectorName, $description, $w_email, $w_emailPub, $w_url, $pub,
-                        $hq_acronym, $hq_url, $hq_email,
-                        $w_subAdministrativeAreaId, $w_administrativeAreaId, $w_countryId,
-                       ) = $res->next()) {
+            while (list($id, $jobid, $name, $description, $w_email, $w_emailPub, $w_url, $pub) = $res->next()) {
                 $compagnies[] = $jobid;
                 $this->values['jobs'][] = array(
                     'id'               => $id,
                     'jobid'            => $jobid,
                     'name'             => $name,
-                    'sector'           => $sector,
-                    'subSector'        => $subSector,
-                    'subSubSector'     => $subSubSector,
-                    'subSubSectorName' => $subSubSectorName,
                     'description'      => $description,
                     'pub'              => $pub,
                     'w_email'          => $w_email,
                     'w_email_pub'      => $w_emailPub,
                     'w_url'            => $w_url,
-                    'hq_acronym'       => $hq_acronym,
-                    'hq_url'           => $hq_url,
-                    'hq_email'         => $hq_email,
                 );
             }
 
@@ -359,10 +310,6 @@ class ProfileSettingJobs extends ProfilePage
             while ($address = $it->next()) {
                 $this->values['jobs'][$address->jobid]['w_address'] = $address->toFormArray();
             }
-            $it = Address::iterate(array(), array(Address::LINK_COMPANY), $companies);
-            while ($address = $it->next()) {
-                $this->values['jobs'][$address->jobId()]['h_address'] = $address->toFormArray();
-            }
             $it = Phone::iterate(array($this->pid()), array(Phone::LINK_JOB));
             while ($phone = $it->next()) {
                 $this->values['jobs'][$phone->linkId()]['w_phone'][$phone->id()] = $phone->toFormArray();
@@ -393,27 +340,18 @@ class ProfileSettingJobs extends ProfilePage
                 $job['terms'][] = $term;
             }
 
+            $phone = new Phone();
+            $address = new Address();
             foreach ($this->values['jobs'] as $id => &$job) {
-                $phone = new Phone();
-                $address = new Address();
                 if (!isset($job['w_phone'])) {
                     $job['w_phone'] = array(0 => $phone->toFormArray());
                 }
                 if (!isset($job['w_address'])) {
                     $job['w_address'] = $address->toFormArray();
                 }
-                if (!isset($job['h_address'])) {
-                    $job['h_address'] = $address->toFormArray();
-                }
             }
 
             $job['w_email_new'] = '';
-            if (!isset($job['hq_fixed'])) {
-                $job['hq_fixed'] = '';
-            }
-            if (!isset($job['hq_fax'])) {
-                $job['hq_fax'] = '';
-            }
             if (!isset($job['w_email_pub'])) {
                 $job['w_email_pub'] = 'private';
             }
@@ -439,10 +377,6 @@ class ProfileSettingJobs extends ProfilePage
         require_once 'emails.combobox.inc.php';
         fill_email_combobox($page, $this->owner);
 
-        $res = XDB::query("SELECT  id, name AS label
-                             FROM  profile_job_sector_enum");
-        $page->assign('sectors', $res->fetchAllAssoc());
-
         $res = XDB::iterator("SELECT  id, name
                                 FROM  profile_corps_enum
                             ORDER BY  id = 1 DESC, name");
index 7b59719..2efe011 100644 (file)
@@ -35,7 +35,7 @@
 <strong>Code AX&nbsp;:</strong>
 <input type="text" name="AX_code" size="25" maxlength="200" value="{$valid->AX_code}" /><br />
 <strong>Adresse&nbsp;:</strong>
-<textarea cols="30" rows="4" name="address">{$valid->address.text}</textarea><br />
+<textarea cols="30" rows="4" name="address">{$valid->address}</textarea><br />
 <strong>Téléphone&nbsp;:</strong>
 <input type="text" name="tel" size="25" maxlength="200" value="{$valid->tel}" /><br />
 <strong>Fax&nbsp;:</strong>
index 855ade8..78d2c60 100644 (file)
@@ -55,7 +55,7 @@
 </tr>
 <tr class="pair">
   <td class="titre">Adresse&nbsp;:</td>
-  <td>{$valid->address.text}</td>
+  <td>{$valid->address}</td>
 </tr>
 <tr class="pair">
   <td class="titre">Téléphone&nbsp;:</td>
index 08570ce..6cd21d5 100644 (file)
         <a href="javascript:addEntreprise({$i})">clique ici</a> et complète les informations la concernant.</small>
       </td>
     </tr>
-    {/if}
     <tr class="{$entreprise}" style="display: none">
       <td class="titre">Acronyme</td>
       <td>
-        <input type="text" size="35" maxlength="255" {if $job.acronym_error}class="error"{/if}
-               name="{$jobpref}[hq_acronym]" value="{$job.hq_acronym}" />
+        <input type="text" size="35" maxlength="255" name="{$jobpref}[hq_acronym]" />
       </td>
     </tr>
     <tr class="{$entreprise}" style="display: none">
       <td class="titre">Page web</td>
       <td>
-        <input type="text" size="35" maxlength="255" {if $job.hq_url}class="error"{/if}
-               name="{$jobpref}[hq_url]" value="{$job.hq_url}" />
+        <input type="text" size="35" maxlength="255" name="{$jobpref}[hq_url]" />
       </td>
     </tr>
     <tr class="{$entreprise}" style="display: none">
       <td class="titre">Email de contact</td>
       <td>
-        <input type="text" maxlength="60" {if $job.hq_email_error}class="error"{/if}
-               name="{$jobpref}[hq_email]" value="{$job.hq_email}" />
+        <input type="text" maxlength="60" name="{$jobpref}[hq_email]" />
       </td>
     </tr>
     <tr class="{$entreprise}" style="display: none">
-      <td colspan="2">
-        <div style="float: left">
-          <div class="titre">Adresse du siège</div>
-          <div style="margin-top: 20px; clear: both">
-            {include file="geoloc/form.address.tpl" prefname="`$jobpref`[hq_address]"
-                     prefid="`$jobid`_address" address=$job.hq_address}
-          </div>
-        </div>
+      <td class="titre">Adresse du siège</td>
+      <td>
+        <textarea name="{$jobpref}[hq_address]" cols="30" rows="4"></textarea>
       </td>
     </tr>
     <tr class="{$entreprise}" style="display: none">
       <td class="titre">Téléphone</td>
       <td>
-        <input type="text" maxlength="28" {if $job.hq_tel_error}class="error"{/if}
-               name="{$jobpref}[hq_fixed]" value="{$job.hq_fixed}" />
+        <input type="text" maxlength="28" name="{$jobpref}[hq_fixed]" />
       </td>
     </tr>
     <tr class="{$entreprise}" style="display: none">
       <td class="titre">Fax</td>
       <td>
-        <input type="text" maxlength="28" {if $job.hq_fax_error}class="error"{/if}
-               name="{$jobpref}[hq_fax]" value="{$job.hq_fax}" />
+        <input type="text" maxlength="28" name="{$jobpref}[hq_fax]" />
       </td>
     </tr>
+    {/if}
 
     <tr class="pair">
       <td colspan="2" class="center" style="font-style: italic">Ta place dans l'entreprise</td>
       <td colspan="2" class="term_tree">
       </td>
     </tr>
-    <tr class="pair {$sector}" style="display: none">
-      <td class="titre" rowspan="4">Secteur&nbsp;d'activité</td>
-      <td>
-        <select name="{$jobpref}[sector]" onchange="updateJobSector({$i}, ''); emptyJobSubSector({$i}); emptyJobAlternates({$i});">
-          <option value="0">&nbsp;</option>
-          {foreach from=$sectors item=item}
-          <option value="{$item.id}" {if $item.id eq $job.sector}selected="selected"{/if}>
-            {$item.label}
-          </option>
-          {/foreach}
-        </select>
-      </td>
-    </tr>
-    <tr class="pair {$sector}" style="display: none">
-      <td id="{$jobid}_subSector">
-        <input type="hidden" name="{$jobpref}[subSector]" value="{$job.subSector|default:0}" />
-      </td>
-    </tr>
-    <tr class="pair {$sector}" style="display: none">
-      <td id="{$jobid}_subSubSector">
-        <input type="hidden" name="{$jobpref}[subSubSector]" value="{$job.subSubSector|default:0}" />
-      </td>
-    </tr>
-    <tr class="pair {$sector}" style="display: none">
-      <td id="{$jobid}_alternates">
-      </td>
-    </tr>
     <tr class="pair">
       <td class="titre">Description</td>
       <td>
index 350adfb..5b2cd06 100644 (file)
@@ -16,9 +16,6 @@ ALTER TABLE profile_education_enum MODIFY COLUMN country CHAR(2) DEFAULT 'FR';
 ALTER TABLE profile_education_degree MODIFY COLUMN eduid INT(11) UNSIGNED DEFAULT 0;
 ALTER TABLE profile_education_degree MODIFY COLUMN degreeid INT(11) UNSIGNED DEFAULT 0;
 ALTER TABLE profile_job MODIFY COLUMN jobid INT(6) UNSIGNED DEFAULT NULL;
-ALTER TABLE profile_job MODIFY COLUMN sectorid TINYINT(2) UNSIGNED DEFAULT NULL;
-ALTER TABLE profile_job MODIFY COLUMN subsectorid SMALLINT(3) UNSIGNED DEFAULT NULL;
-ALTER TABLE profile_job MODIFY COLUMN subsubsectorid SMALLINT(3) UNSIGNED DEFAULT NULL;
 
 -- Prepares table having ids set to 0.
 DELETE FROM profile_mentor_country WHERE country = 'YU' OR country = '00';
@@ -31,9 +28,6 @@ UPDATE profile_education SET degreeid = NULL WHERE degreeid = 0;
 UPDATE profile_education SET fieldid = NULL WHERE fieldid = 0;
 UPDATE profile_education_enum SET country = NULL WHERE country = '';
 UPDATE profile_job SET jobid = NULL WHERE jobid = 0;
-UPDATE profile_job SET sectorid = NULL WHERE sectorid = 0;
-UPDATE profile_job SET subsectorid = NULL WHERE subsectorid = 0;
-UPDATE profile_job SET subsubsectorid = NULL WHERE subsubsectorid = 0;
 UPDATE profile_job_enum SET holdingid = NULL WHERE holdingid = 0;
 
 -- Adds missing data in foreign tables.
@@ -63,18 +57,10 @@ ALTER TABLE profile_education_enum ADD FOREIGN KEY (country) REFERENCES geoloc_c
 ALTER TABLE profile_education_degree ADD FOREIGN KEY (eduid) REFERENCES profile_education_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
 ALTER TABLE profile_education_degree ADD FOREIGN KEY (degreeid) REFERENCES profile_education_degree_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
 ALTER TABLE profile_job ADD FOREIGN KEY (jobid) REFERENCES profile_job_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
-ALTER TABLE profile_job ADD FOREIGN KEY (sectorid) REFERENCES profile_job_sector_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
-ALTER TABLE profile_job ADD FOREIGN KEY (subsectorid) REFERENCES profile_job_subsector_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
-ALTER TABLE profile_job ADD FOREIGN KEY (subsubsectorid) REFERENCES profile_job_subsubsector_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
-ALTER TABLE profile_job_alternates ADD FOREIGN KEY (subsubsectorid) REFERENCES profile_job_subsubsector_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
 ALTER TABLE profile_job_enum ADD FOREIGN KEY (holdingid) REFERENCES profile_job_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
-ALTER TABLE profile_job_subsector_enum ADD FOREIGN KEY (sectorid) REFERENCES profile_job_sector_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
-ALTER TABLE profile_job_subsubsector_enum ADD FOREIGN KEY (sectorid) REFERENCES profile_job_sector_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
-ALTER TABLE profile_job_subsubsector_enum ADD FOREIGN KEY (subsectorid) REFERENCES profile_job_subsector_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
 ALTER TABLE profile_langskills ADD FOREIGN KEY (lid) REFERENCES profile_langskill_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
 ALTER TABLE profile_medal_grade_enum ADD FOREIGN KEY (mid) REFERENCES profile_medal_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
 ALTER TABLE profile_mentor_country ADD FOREIGN KEY (country) REFERENCES geoloc_countries (iso_3166_1_a2) ON DELETE CASCADE ON UPDATE CASCADE;
-ALTER TABLE profile_mentor_sector ADD FOREIGN KEY (sectorid) REFERENCES profile_job_sector_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
 ALTER TABLE profile_skills ADD FOREIGN KEY (cid) REFERENCES profile_skill_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
 ALTER TABLE profile_name ADD FOREIGN KEY (typeid) REFERENCES profile_name_enum (id) ON DELETE CASCADE ON UPDATE CASCADE;
 ALTER TABLE profile_networking ADD FOREIGN KEY (nwid) REFERENCES profile_networking_enum (nwid) ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/upgrade/1.0.1/99_jobs.sql b/upgrade/1.0.1/99_jobs.sql
new file mode 100644 (file)
index 0000000..73e4791
--- /dev/null
@@ -0,0 +1,5 @@
+ALTER TABLE profile_job_enum DROP COLUMN sectorid;
+ALTER TABLE profile_job_enum DROP COLUMN subsectorid;
+ALTER TABLE profile_job_enum DROP COLUMN subsubsectorid;
+
+-- vim:set syntax=mysql:
diff --git a/upgrade/1.0.1/README b/upgrade/1.0.1/README
new file mode 100644 (file)
index 0000000..80846c3
--- /dev/null
@@ -0,0 +1 @@
+99_jobs.sql must be run after php scripts.