Adds address to groups.
authorStéphane Jacob <sj@m4x.org>
Mon, 28 Feb 2011 15:56:58 +0000 (16:56 +0100)
committerStéphane Jacob <sj@m4x.org>
Mon, 28 Feb 2011 15:56:58 +0000 (16:56 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/address.php
classes/group.php
modules/profile/addresses.inc.php
modules/profile/jobs.inc.php
modules/xnetgrp.php
templates/xnetgrp/asso.tpl
templates/xnetgrp/edit.tpl
upgrade/1.1.0/09_addresses.sql [new file with mode: 0644]

index d92ffb9..fc438e5 100644 (file)
  *   - `id` is the id of the job to which we refer (in profile_job)
  *   - `jobid` is set to 0
  *
+ * - for a Group:
+ *  - `type` is set to 'group'
+ *  - `pid` is set to 0
+ *  - `jobid` is set to 0
+ *  - `groupid` is set to the group id
+ *
  * Thus an Address can be linked to a Company, a Profile, or a Job.
  */
 class Address
@@ -48,6 +54,7 @@ class Address
     const LINK_JOB     = 'job';
     const LINK_COMPANY = 'hq';
     const LINK_PROFILE = 'home';
+    const LINK_GROUP   = 'group';
 
     // List of all available postal formattings.
     private static $formattings = array('FRANCE' => 'FR');
@@ -284,6 +291,7 @@ class Address
     // Primary key fields: the quadruplet ($pid, $jobid, $type, $id) defines a unique address.
     public $pid = 0;
     public $jobid = 0;
+    public $groupid = 0;
     public $type = Address::LINK_PROFILE;
     public $id = 0;
 
@@ -723,14 +731,14 @@ class Address
                 Geocoder::getAreaId($this, $area);
             }
 
-            XDB::execute('INSERT IGNORE INTO  profile_addresses (pid, jobid, type, id, flags, accuracy,
+            XDB::execute('INSERT IGNORE INTO  profile_addresses (pid, jobid, groupid, type, id, flags, accuracy,
                                                                  text, postalText, postalCode, localityId,
                                                                  subAdministrativeAreaId, administrativeAreaId,
                                                                  countryId, latitude, longitude, pub, comment,
                                                                  north, south, east, west)
                                       VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?},
-                                               {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
-                         $this->pid, $this->jobid, $this->type, $this->id, $this->flags, $this->accuracy,
+                                               {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
+                         $this->pid, $this->jobid, $this->groupid, $this->type, $this->id, $this->flags, $this->accuracy,
                          $this->text, $this->postalText, $this->postalCode, $this->localityId,
                          $this->subAdministrativeAreaId, $this->administrativeAreaId,
                          $this->countryId, $this->latitude, $this->longitude,
@@ -746,11 +754,11 @@ class Address
     public function delete()
     {
         XDB::execute('DELETE FROM  profile_addresses
-                            WHERE  pid = {?} AND jobid = {?} AND type = {?} AND id = {?}',
-                     $this->pid, $this->jobid, $this->type, $this->id);
+                            WHERE  pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}',
+                     $this->pid, $this->jobid, $this->groupid, $this->type, $this->id);
     }
 
-    static public function deleteAddresses($pid, $type, $jobid = null, $deletePrivate = true)
+    static public function deleteAddresses($pid, $type, $jobid = null, $groupid = null, $deletePrivate = true)
     {
         $where = '';
         if (!is_null($pid)) {
@@ -759,6 +767,9 @@ class Address
         if (!is_null($jobid)) {
             $where = XDB::format(' AND jobid = {?}', $jobid);
         }
+        if (!is_null($groupid)) {
+            $where = XDB::format(' AND groupid = {?}', $groupid);
+        }
         XDB::execute('DELETE FROM  profile_addresses
                             WHERE  type = {?}' . $where . (($deletePrivate) ? '' : ' AND pub IN (\'public\', \'ax\')'),
                      $type);
index 477bcf9..c79b0d3 100644 (file)
@@ -117,13 +117,14 @@ class Group
         $res = XDB::query('SELECT  a.*, d.nom AS domnom,
                                    FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc,
                                    FIND_IN_SET(\'notif_unsub\', a.flags) AS notif_unsub,
-                                   (nls.id IS NOT NULL) AS has_nl,
+                                   (nls.id IS NOT NULL) AS has_nl, ad.text AS address,
                                    p.display_tel AS phone, f.display_tel AS fax
                              FROM  groups AS a
                         LEFT JOIN  group_dom  AS d ON d.id = a.dom
                         LEFT JOIN  newsletters AS nls ON (nls.group_id = a.id)
                         LEFT JOIN  profile_phones AS p ON (p.link_type = \'group\' AND p.link_id = a.id AND p.tel_id = 0)
                         LEFT JOIN  profile_phones AS f ON (f.link_type = \'group\' AND f.link_id = a.id AND f.tel_id = 1)
+                        LEFT JOIN  profile_addresses AS ad ON (ad.type = \'group\' AND ad.groupid = a.id)
                             WHERE  ' . $where);
         if ($res->numRows() != 1) {
             if ($can_be_shortname && (is_int($id) || ctype_digit($id))) {
index c563c7e..2961f1e 100644 (file)
@@ -46,7 +46,7 @@ class ProfileSettingAddresses implements ProfileSetting
         $deletePrivate = S::user()->isMe($page->owner) || S::admin();
 
         Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS, null, $deletePrivate);
-        Address::deleteAddresses($page->pid(), Address::LINK_PROFILE, null, $deletePrivate);
+        Address::deleteAddresses($page->pid(), Address::LINK_PROFILE, null, null, $deletePrivate);
         Address::saveFromArray($value, $page->pid(), Address::LINK_PROFILE, null, $deletePrivate);
         if (S::user()->isMe($page->owner) && count($value) > 1) {
             Platal::page()->trigWarning('Attention, tu as plusieurs adresses sur ton profil. Pense à supprimer celles qui sont obsolètes.');
index 7a325bf..ea6d5ed 100644 (file)
@@ -265,7 +265,7 @@ class ProfileSettingJob implements ProfileSetting
                         LEFT JOIN  profile_job_term AS pjt ON (pj.pid = pjt.pid AND pj.id = pjt.jid)
                             WHERE  pj.pid = {?}' . (($deletePrivate) ? '' : ' AND pj.pub IN (\'public\', \'ax\')'),
                      $page->pid());
-        Address::deleteAddresses($page->pid(), Address::LINK_JOB, null, $deletePrivate);
+        Address::deleteAddresses($page->pid(), Address::LINK_JOB, null, null, $deletePrivate);
         Phone::deletePhones($page->pid(), Phone::LINK_JOB, null, $deletePrivate);
         $terms_values = array();
         foreach ($value as $id => &$job) {
index e863912..b38b9e4 100644 (file)
@@ -238,6 +238,9 @@ class XnetGrpModule extends PLModule
                                      'type' => 'fax', 'display' => Post::v('fax'), 'pub' => 'public'));
             $phone->save();
             $fax->save();
+            Address::deleteAddresses(null, Address::LINK_GROUP, null, $globals->asso('id'));
+            $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address::LINK_GROUP, 'text' => Post::v('address')));
+            $address->save();
 
             if ($_FILES['logo']['name']) {
                 $upload = PlUpload::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true);
index 9714d14..5043faf 100644 (file)
   </tr>
   {/if}
 
+  {if $asso->address}
+  <tr>
+    <td class="titre">Adresse&nbsp;:</td>
+    <td>{$asso->address}</td>
+  </tr>
+  {/if}
+
   {if !$is_member && $is_logged && $asso->inscriptible && $xnet_type != 'promotions'}
   <tr>
     <td class="titre">
index 668896d..5af8cda 100644 (file)
         <input type="text" maxlength="28" name="fax" value="{$asso->fax}" />
       </td>
     </tr>
+    <tr>
+      <td class="titre">Adresse</td>
+      <td>
+        <textarea name="address" cols="30" rows="4">{$asso->address}</textarea>
+      </td>
+    </tr>
 
     <tr>
       <td class="titre">
diff --git a/upgrade/1.1.0/09_addresses.sql b/upgrade/1.1.0/09_addresses.sql
new file mode 100644 (file)
index 0000000..8f753cb
--- /dev/null
@@ -0,0 +1,51 @@
+DROP TABLE IF EXISTS tmp_profile_addresses;
+CREATE TEMPORARY TABLE tmp_profile_addresses LIKE profile_addresses;
+INSERT INTO tmp_profile_addresses SELECT * FROM profile_addresses;
+DROP TABLE profile_addresses;
+CREATE TABLE profile_addresses (
+  pid int(11) unsigned NOT NULL DEFAULT '0',
+  jobid int(6) unsigned NOT NULL DEFAULT '0',
+  groupid SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0,
+  type enum('home','job','hq','group') NOT NULL DEFAULT 'home',
+  id tinyint(3) unsigned NOT NULL DEFAULT '0',
+  flags set('current','temporary','secondary','mail','cedex','deliveryIssue') DEFAULT NULL,
+  accuracy tinyint(1) unsigned NOT NULL DEFAULT '0',
+  text text NOT NULL,
+  postalText text NOT NULL,
+  postalCode varchar(255) DEFAULT NULL,
+  localityId bigint(20) unsigned DEFAULT NULL,
+  subAdministrativeAreaId int(11) unsigned DEFAULT NULL,
+  administrativeAreaId int(11) unsigned DEFAULT NULL,
+  countryId char(2) DEFAULT NULL,
+  latitude float(10,7) DEFAULT NULL,
+  longitude float(10,7) DEFAULT NULL,
+  north float(10,7) DEFAULT NULL,
+  south float(10,7) DEFAULT NULL,
+  east float(10,7) DEFAULT NULL,
+  west float(10,7) DEFAULT NULL,
+  pub enum('public','ax','private') NOT NULL DEFAULT 'private',
+  comment varchar(255) DEFAULT NULL,
+  PRIMARY KEY (pid,jobid,groupid,type,id),
+  KEY pid (pid),
+  KEY jobid (jobid),
+  KEY type (type),
+  KEY adrid (id),
+  KEY localityId (localityId),
+  KEY administrativeAreaId (administrativeAreaId),
+  KEY subAdministrativeAreaId (subAdministrativeAreaId),
+  KEY countryId (countryId),
+  CONSTRAINT profile_addresses_ibfk_1 FOREIGN KEY (localityId) REFERENCES geoloc_localities (id) ON DELETE CASCADE ON UPDATE CASCADE,
+  CONSTRAINT profile_addresses_ibfk_2 FOREIGN KEY (subAdministrativeAreaId) REFERENCES geoloc_subadministrativeareas (id) ON DELETE CASCADE ON UPDATE CASCADE,
+  CONSTRAINT profile_addresses_ibfk_3 FOREIGN KEY (administrativeAreaId) REFERENCES geoloc_administrativeareas (id) ON DELETE CASCADE ON UPDATE CASCADE,
+  CONSTRAINT profile_addresses_ibfk_4 FOREIGN KEY (countryId) REFERENCES geoloc_countries (iso_3166_1_a2) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+INSERT INTO  profile_addresses (pid, jobid, groupid, type, id, flags, accuracy, text, postalText,
+             postalCode, localityId, subAdministrativeAreaId, administrativeAreaId, countryId,
+             latitude, longitude, north, south, east, west, pub, comment)
+     SELECT  pid, jobid, 0, type, id, flags, accuracy, text, postalText,
+             postalCode, localityId, subAdministrativeAreaId, administrativeAreaId, countryId,
+             latitude, longitude, north, south, east, west, pub, comment
+       FROM  tmp_profile_addresses;
+DROP TABLE IF EXISTS tmp_profile_addresses;
+
+-- vim:set syntax=mysql: