update the map images
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 15 Jul 2014 14:54:19 +0000 (10:54 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 15 Jul 2014 14:58:16 +0000 (10:58 -0400)
take out the mapimg field from the Property class.
remove the mapimage from the controller in admin
use curl to fetch the map image if it is not in the Maps directory.
Saving the image as prop-{propertyId}.png
Saving the current property images for the maps in the
Toolkit/Property/Maps directory.

Toolkit/Property/Controller.php
Toolkit/Property/Display.php
Toolkit/Property/Maps/prop-1.png [new file with mode: 0644]
Toolkit/Property/Maps/prop-2.png [new file with mode: 0644]
Toolkit/Property/Maps/prop-3.png [new file with mode: 0644]
Toolkit/Property/Maps/prop-4.png [new file with mode: 0644]
Toolkit/Property/Maps/prop-5.png [new file with mode: 0644]
Toolkit/Property/Maps/prop-6.png [new file with mode: 0644]
Toolkit/Property/Models/Property.php
templates/template.html

index 4435dc6..6b14c43 100644 (file)
@@ -98,15 +98,6 @@ class Controller
             $file2Uploaded = $is->imageUpload('image2');
         }
         $posted = $this->getFilteredPostData();
-        $mapimgurl='http://maps.googleapis.com/maps/api/staticmap?size=400x300&zoom=13&maptype=roadmap&markers=size:mid%7Ccolor:red%7C';
-        $address = $posted['street'].','.$posted['city'].','.$posted['state'];
-        
-        $mapimgurl .= urlencode($address);
-        
-        $mapimg = $is->imageUpload($mapimgurl);
-        var_dump($mapimg);exit;
-        $posted['mapimg'] = $mapimg;
-        
         $posted['image']
             = ($file1Uploaded)
             ? $file1Uploaded
@@ -116,10 +107,9 @@ class Controller
             ? $file2Uploaded
             : $posted['oldimg2'];
         unset($posted['oldimg1'], $posted['oldimg2']);
-        
+
         $mapper = new \Property\Models\Property();
         $property = $mapper->createByValues($posted);
-        //echo '<pre>' .print_r($property,true). '</pre>'; exit;
         $property->save($this->dbh);
     }
 
index bc676ac..e485d30 100644 (file)
@@ -57,9 +57,27 @@ class Toolkit_Property_Display
                 $dbh,
                 $propertyId
             );
-            return ($property)
+            $property = ($property)
                 ? $property->getPropertiesAsArray()
                 : false;
+            $mapImageName = "prop-{$propertyId}.png";
+            if (file_exists(BASE . 'Toolkit/Property/Maps/' . $mapImageName)) {
+                $property['mapimg'] = $mapImageName;
+            } else {
+                $ch = curl_init();
+                $mapUrl  = 'http://maps.googleapis.com/maps/api/staticmap?size=400x300&zoom=13&maptype=roadmap&markers=size:mid%7Ccolor:red%7C';
+                $mapUrl .= urlencode($property['street'].','.$property['city'].','.$property['state']);
+                curl_setopt($ch, CURLOPT_URL, $mapUrl);
+                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+                curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
+                $res = curl_exec($ch);
+                curl_close($ch);
+                $saveFile = fopen(BASE . 'Toolkit/Property/Maps/' . $mapImageName, 'w');
+                fwrite($saveFile, $res);
+                fclose($saveFile);
+                $property['mapimg'] = $mapImageName;
+            }
+            return $property;
         } else {
             return false;
         }
diff --git a/Toolkit/Property/Maps/prop-1.png b/Toolkit/Property/Maps/prop-1.png
new file mode 100644 (file)
index 0000000..27158d4
Binary files /dev/null and b/Toolkit/Property/Maps/prop-1.png differ
diff --git a/Toolkit/Property/Maps/prop-2.png b/Toolkit/Property/Maps/prop-2.png
new file mode 100644 (file)
index 0000000..6bb5f4e
Binary files /dev/null and b/Toolkit/Property/Maps/prop-2.png differ
diff --git a/Toolkit/Property/Maps/prop-3.png b/Toolkit/Property/Maps/prop-3.png
new file mode 100644 (file)
index 0000000..4ad5046
Binary files /dev/null and b/Toolkit/Property/Maps/prop-3.png differ
diff --git a/Toolkit/Property/Maps/prop-4.png b/Toolkit/Property/Maps/prop-4.png
new file mode 100644 (file)
index 0000000..6798806
Binary files /dev/null and b/Toolkit/Property/Maps/prop-4.png differ
diff --git a/Toolkit/Property/Maps/prop-5.png b/Toolkit/Property/Maps/prop-5.png
new file mode 100644 (file)
index 0000000..3c9442b
Binary files /dev/null and b/Toolkit/Property/Maps/prop-5.png differ
diff --git a/Toolkit/Property/Maps/prop-6.png b/Toolkit/Property/Maps/prop-6.png
new file mode 100644 (file)
index 0000000..073b387
Binary files /dev/null and b/Toolkit/Property/Maps/prop-6.png differ
index 3e4ec1a..27561ce 100644 (file)
@@ -36,13 +36,12 @@ class Property extends \Toolkit_Table
     protected $name;
     protected $image;
     protected $image2;
-    protected $mapimg;
     protected $street;
     protected $city;
     protected $state;
     protected $zip;
     protected $phone;
     protected $url;
-    
+
 
 }
index 5f7ba35..7661df1 100644 (file)
@@ -40,7 +40,7 @@
                     {property[street]} &middot; {property[city]}, {property[state]} {property[zip]} &middot; {property[phone]} &middot; {property[url]}
                 </address>
                 <div id="googlemap">
-                    <img src="{propImageStyle:h}{property[mapimg]:h}">
+                    <img src="{mediaBaseURL:h}Toolkit/Property/Maps/{property[mapimg]:h}">
                 </div>
                 <div id="photoGallery">
                 </div>
     </div>
 {bottomScripts:h}
 </body>
-</html>
\ No newline at end of file
+</html>