Accelerates jobterms tree browsing and fixes some leaf problems
[platal.git] / classes / address.php
index aad9fd0..c3c0dea 100644 (file)
@@ -102,25 +102,28 @@ class Address
             }
         }
 
-        if ($this->type == self::LINK_PROFILE) {
-            if (!is_null($this->flags)) {
-                $this->flags = new PlFlagSet($this->flags);
-            } else {
-                static $flags = array('current', 'temporary', 'secondary', 'mail');
-
-                $this->flags = new PlFlagSet();
-                foreach ($flags as $flag) {
-                    if (!is_null($this->$flag) && ($this->$flag == 1 || $this->$flag == 'on')) {
-                        $this->flags->addFlag($flag, 1);
-                        $this->$flag = null;
-                    }
-                    $this->flags->addFlag('cedex', (strpos(strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"),
-                                                                                   array('', "\n"), $this->text)), 'CEDEX')) !== false);
+        if (!is_null($this->flags)) {
+            $this->flags = new PlFlagSet($this->flags);
+        } else {
+            static $flags = array('current', 'temporary', 'secondary', 'mail');
+
+            $this->flags = new PlFlagSet();
+            foreach ($flags as $flag) {
+                if (!is_null($this->$flag) && ($this->$flag == 1 || $this->$flag == 'on')) {
+                    $this->flags->addFlag($flag, 1);
+                    $this->$flag = null;
                 }
+                $this->flags->addFlag('cedex', (strpos(strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"),
+                                                                               array('', "\n"), $this->text)), 'CEDEX')) !== false);
             }
         }
     }
 
+    public function setId($id)
+    {
+        $this->id = $id;
+    }
+
     public function phones()
     {
         return $this->phones;
@@ -135,7 +138,7 @@ class Address
 
     public function hasFlag($flag)
     {
-        return $this->flags->hasFlag($flag);
+        return ($this->flags != null && $this->flags->hasFlag($flag));
     }
 
     public function format(array $format = array())
@@ -150,7 +153,6 @@ class Address
             return true;
         }
 
-        require_once 'geocoding.inc.php';
         if ($format['requireGeocoding'] || $this->changed == 1) {
             $gmapsGeocoder = new GMapsGeocoder();
             $gmapsGeocoder->getGeocodedAddress($this);
@@ -167,6 +169,9 @@ class Address
                 $mailer->send();
             }
         }
+        if ($this->countryId == '') {
+            $this->countryId = null;
+        }
         $this->geocodeChosen = null;
         $this->phones = Phone::formatFormArray($this->phones, $this->error);
         return !$this->error;
@@ -257,7 +262,6 @@ class Address
 
         $this->format();
         if (!$this->isEmpty()) {
-            require_once 'geocoding.inc.php';
             foreach ($areas as $area) {
                 Geocoder::getAreaId($this, $area);
             }
@@ -265,15 +269,15 @@ class Address
             XDB::execute('INSERT INTO  profile_addresses (pid, jobid, type, id, flags, accuracy,
                                                           text, postalText, postalCode, localityId,
                                                           subAdministrativeAreaId, administrativeAreaId,
-                                                          countryId, latitude, longitude, updateTime, pub, comment,
+                                                          countryId, latitude, longitude, pub, comment,
                                                           north, south, east, west)
-                               VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?},
-                                        {?}, {?}, {?}, FROM_UNIXTIME({?}), {?}, {?}, {?}, {?}, {?}, {?})',
+                               VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?},
+                                        {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
                          $this->pid, $this->jobid, $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,
-                         time(), $this->pub, $this->comment,
+                         $this->pub, $this->comment,
                          $this->north, $this->south, $this->east, $this->west);
 
             if ($this->type == self::LINK_PROFILE) {
@@ -282,7 +286,14 @@ class Address
         }
     }
 
-    static public function delete($pid, $type, $jobid = null)
+    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);
+    }
+
+    static public function deleteAddresses($pid, $type, $jobid = null)
     {
         $where = '';
         if (!is_null($pid)) {
@@ -414,7 +425,7 @@ class AddressIterator implements PlIterator
              LEFT JOIN  geoloc_administrativeareas    AS ga ON (ga.id = pa.administrativeAreaId)
              LEFT JOIN  geoloc_subadministrativeareas AS gs ON (gs.id = pa.subAdministrativeAreaId)
              LEFT JOIN  geoloc_countries              AS gc ON (gc.iso_3166_1_a2 = pa.countryId)
-                 WHERE  ' . implode(' AND ', $where) . '
+                 ' . ((count($where) > 0) ? 'WHERE  ' . implode(' AND ', $where) : '') . '
               ORDER BY  pa.pid, pa.jobid, pa.id';
         $this->dbiter = XDB::iterator($sql);
     }