Fixes the alias synchronization query in the gapps cronjob. It was
[platal.git] / classes / address.php
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);