Moving to GitHub.
[platal.git] / classes / geocoder.php
index f404304..30d6fbd 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2011 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -33,14 +33,14 @@ abstract class Geocoder {
     // geocoded data and returns the corresponding id.
     static public function getComponentId(array $component)
     {
-        $where_types = array();
+        $where = '';
         foreach ($component['types'] as $type) {
-            $where_types[] = XDB::format('FIND_IN_SET({?}, types)', $type);
+            $where .= XDB::format(' AND FIND_IN_SET({?}, types)', $type);
         }
 
         $id = XDB::fetchOneCell('SELECT  id
                                    FROM  profile_addresses_components_enum
-                                  WHERE  short_name = {?} AND long_name = {?} AND ' . implode(' AND ', $where_types),
+                                  WHERE  short_name = {?} AND long_name = {?}' . $where,
                                 $component['short_name'], $component['long_name']);
         if (is_null($id)) {
             XDB::execute('INSERT INTO  profile_addresses_components_enum (short_name, long_name, types)
@@ -73,7 +73,21 @@ abstract class Geocoder {
         }
         return $firstLines;
     }
+
+    // Returns the number of non geocoded addresses for a profile.
+    static public function countNonGeocoded($pid)
+    {
+        $count = XDB::fetchOneCell('SELECT  COUNT(*)
+                                      FROM  profile_addresses AS pa
+                                     WHERE  pid = {?} AND type = \'home\'
+                                            AND NOT EXISTS (SELECT  *
+                                                              FROM  profile_addresses_components AS pc
+                                                             WHERE  pa.pid = pc.pid AND pa.jobid = pc.jobid AND pa.groupid = pc.groupid
+                                                                    AND pa.type = pc.type AND pa.id = pc.id)',
+                                   $pid);
+        return $count;
+    }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>