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.
$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
? $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);
}
$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;
}
protected $name;
protected $image;
protected $image2;
- protected $mapimg;
protected $street;
protected $city;
protected $state;
protected $zip;
protected $phone;
protected $url;
-
+
}
{property[street]} · {property[city]}, {property[state]} {property[zip]} · {property[phone]} · {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>