Revision: 24505
Updated Code
at March 2, 2010 17:10 by rccc
Updated Code
class sfWidgetFormGeocoder extends sfWidgetForm { public function configure($options = array(), $attributes = array()) { $this->addOption('address.options', array('style' => 'width:400px')); $this->setOption('default', array( 'address' => '', 'lon' => '1.913899', 'lat' => '47.900486' )); $this->addOption('div.class', 'geocoder-widget'); $this->addOption('map.height', '300px'); $this->addOption('map.width', '500px'); $this->addOption('map.style', ""); $this->addOption('lookup.name', ""); $this->addOption('template.html', ' <div id="{div.id}" class="{div.class}"> {input.search} <input type="submit" value="{input.lookup.name}" id="{input.lookup.id}" /> <br /> {input.lon} {input.lat} <div id="{map.id}" style="width:{map.width};height:{map.height};{map.style}"></div> </div> '); $this->addOption('template.javascript', ' <script type="text/javascript"> (function() { var $submit = document.getElementById("{input.lookup.id}"); var $address = document.getElementById("{input.address.id}"); var $lat = document.getElementById("{input.lat.id}"); var $lon = document.getElementById("{input.lon.id}"); var map = new GMap2(document.getElementById("{map.id}")); var center = new GLatLng( $lat.value||47.900486, $lon.value||1.913899); var marker = new GMarker(center, {draggable: true}); var geocoder = new GClientGeocoder(); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(center, 5); map.addOverlay(marker); setPosition(center); GEvent.addListener(marker, "dragend", function() { var point = marker.getPoint(); map.panTo(point); setPosition(point); }); GEvent.addListener(map, "moveend", function() { var point = map.getCenter() marker.setLatLng(point); setPosition(point); }); $submit.onclick = function(){showAddress($address.value)}; function showAddress() { if(!arguments[0]) return false; var address = arguments[0]; if (geocoder) { geocoder.getLatLng(address, function(point) { if (!point) { alert(address + " not found"); }else{ setPosition(point); map.setCenter(point, 14); } }); } } function setPosition(){ $lat.value = arguments[0].lat(); $lon.value = arguments[0].lng(); } })(); </script> '); } public function getJavascripts() { return array(''); } public function render($name, $value = null, $attributes = array(), $errors = array()) { // define main template variables $template_vars = array( '{div.id}' => $this->generateId($name), '{div.class}' => $this->getOption('div.class'), '{map.id}' => $this->generateId($name.'[map]'), '{map.style}' => $this->getOption('map.style'), '{map.height}' => $this->getOption('map.height'), '{map.width}' => $this->getOption('map.width'), '{input.lookup.id}' => $this->generateId($name.'[lookup]'), '{input.lookup.name}' => $this->getOption('lookup.name'), '{input.address.id}' => $this->generateId($name.'[address]'), '{input.lat.id}' => $this->generateId($name.'[lat]'), '{input.lon.id}' => $this->generateId($name.'[lon]'), ); // v���©rifie si la valeur est valide $value = !is_array($value) ? array() : $value; $value['address'] = isset($value['address']) ? $value['address'] : ''; $value['lon'] = isset($value['long']) ? $value['lon'] : ''; $value['lat'] = isset($value['lat']) ? $value['lat'] : ''; // d���©finit le widget pour le champ adresse $address = new sfWidgetFormInputText(array(), $this->getOption('address.options')); $template_vars['{input.search}'] = $address->render($name.'[address]', $value['address']); // d���©finit les widgets pour les champs : longitude et latitude $hidden = new sfWidgetFormInputText; $template_vars['{input.lon}'] = $hidden->render($name.'[lon', $value['lon']); $template_vars['{input.lat}'] = $hidden->render($name.'[lat]', $value['lat']); // assemble le mod���¨le avec les valeurs return strtr( $this->getOption('template.html').$this->getOption('template.javascript'), $template_vars ); } } class sfValidatorGeocoder extends sfValidatorBase { protected function doClean($value) { if (!is_array($value)) { throw new sfValidatorError($this, 'invalid'); } try { $latitude = new sfValidatorNumber(array( 'min' => -90, 'max' => 90, 'required' => true )); $value['lat'] = $latitude->clean(isset($value['lat']) ? $value['lat'] : null); $longitude = new sfValidatorNumber(array( 'min' => -180, 'max' => 180, 'required' => true )); $value['lon'] = $longitude->clean(isset($value['lon]) ? $value['lon'] : null); $address = new sfValidatorString(array( 'min_length' => 10, 'max_length' => 255, 'required' => true )); $value['address'] = $address->clean(isset($value['address']) ? $value['address'] : null); } catch(sfValidatorError $e) { throw new sfValidatorError($this, 'invalid'); } return $value; } }
Revision: 24504
Updated Code
at March 2, 2010 17:07 by rccc
Updated Code
class sfWidgetFormGeocoder extends sfWidgetForm { public function configure($options = array(), $attributes = array()) { $this->addOption('address.options', array('style' => 'width:400px')); $this->setOption('default', array( 'address' => '', 'lon' => '1.913899', 'lat' => '47.900486' )); $this->addOption('div.class', 'geocoder-widget'); $this->addOption('map.height', '300px'); $this->addOption('map.width', '500px'); $this->addOption('map.style', ""); $this->addOption('lookup.name', ""); $this->addOption('template.html', ' <div id="{div.id}" class="{div.class}"> {input.search} <input type="submit" value="{input.lookup.name}" id="{input.lookup.id}" /> <br /> {input.lon} {input.lat} <div id="{map.id}" style="width:{map.width};height:{map.height};{map.style}"></div> </div> '); $this->addOption('template.javascript', ' <script type="text/javascript"> (function() { var $submit = document.getElementById("{input.lookup.id}"); var $address = document.getElementById("{input.address.id}"); var $lat = document.getElementById("{input.lat.id}"); var $lon = document.getElementById("{input.lon.id}"); var map = new GMap2(document.getElementById("{map.id}")); var center = new GLatLng( $lat.value||47.900486, $lon.value||1.913899); var marker = new GMarker(center, {draggable: true}); var geocoder = new GClientGeocoder(); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(center, 5); map.addOverlay(marker); setPosition(center); GEvent.addListener(marker, "dragend", function() { var point = marker.getPoint(); map.panTo(point); setPosition(point); }); GEvent.addListener(map, "moveend", function() { var point = map.getCenter() marker.setLatLng(point); setPosition(point); }); $submit.onclick = function(){showAddress($address.value)}; function showAddress() { if(!arguments[0]) return false; var address = arguments[0]; if (geocoder) { geocoder.getLatLng(address, function(point) { if (!point) { alert(address + " not found"); }else{ setPosition(point); map.setCenter(point, 14); } }); } } function setPosition(){ $lat.value = arguments[0].lat(); $lon.value = arguments[0].lng(); } })(); </script> '); } public function getJavascripts() { return array(''); } public function render($name, $value = null, $attributes = array(), $errors = array()) { // define main template variables $template_vars = array( '{div.id}' => $this->generateId($name), '{div.class}' => $this->getOption('div.class'), '{map.id}' => $this->generateId($name.'[map]'), '{map.style}' => $this->getOption('map.style'), '{map.height}' => $this->getOption('map.height'), '{map.width}' => $this->getOption('map.width'), '{input.lookup.id}' => $this->generateId($name.'[lookup]'), '{input.lookup.name}' => $this->getOption('lookup.name'), '{input.address.id}' => $this->generateId($name.'[address]'), '{input.lat.id}' => $this->generateId($name.'[lat]'), '{input.lon.id}' => $this->generateId($name.'[lon]'), ); // v�©rifie si la valeur est valide $value = !is_array($value) ? array() : $value; $value['address'] = isset($value['address']) ? $value['address'] : ''; $value['lon'] = isset($value['long']) ? $value['lon'] : ''; $value['lat'] = isset($value['lat']) ? $value['lat'] : ''; // d�©finit le widget pour le champ adresse $address = new sfWidgetFormInputText(array(), $this->getOption('address.options')); $template_vars['{input.search}'] = $address->render($name.'[address]', $value['address']); // d�©finit les widgets pour les champs : longitude et latitude $hidden = new sfWidgetFormInputText; $template_vars['{input.lon}'] = $hidden->render($name.'[lon', $value['lon']); $template_vars['{input.lat}'] = $hidden->render($name.'[lat]', $value['lat']); // assemble le mod�¨le avec les valeurs return strtr( $this->getOption('template.html').$this->getOption('template.javascript'), $template_vars ); } }
Revision: 24503
Updated Code
at March 2, 2010 17:07 by rccc
Updated Code
class sfWidgetFormGeocoder extends sfWidgetForm { public function configure($options = array(), $attributes = array()) { $this->addOption('address.options', array('style' => 'width:400px')); $this->setOption('default', array( 'address' => '', 'lon' => '1.913899', 'lat' => '47.900486' )); $this->addOption('div.class', 'geocoder-widget'); $this->addOption('map.height', '300px'); $this->addOption('map.width', '500px'); $this->addOption('map.style', ""); $this->addOption('lookup.name', ""); $this->addOption('template.html', ' <div id="{div.id}" class="{div.class}"> {input.search} <input type="submit" value="{input.lookup.name}" id="{input.lookup.id}" /> <br /> {input.lon} {input.lat} <div id="{map.id}" style="width:{map.width};height:{map.height};{map.style}"></div> </div> '); $this->addOption('template.javascript', ' <script type="text/javascript"> (function() { var $submit = document.getElementById("{input.lookup.id}"); var $address = document.getElementById("{input.address.id}"); var $lat = document.getElementById("{input.lat.id}"); var $lon = document.getElementById("{input.lon.id}"); var map = new GMap2(document.getElementById("{map.id}")); var center = new GLatLng( $lat.value||47.900486, $lon.value||1.913899); var marker = new GMarker(center, {draggable: true}); var geocoder = new GClientGeocoder(); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(center, 5); map.addOverlay(marker); setPosition(center); GEvent.addListener(marker, "dragend", function() { var point = marker.getPoint(); map.panTo(point); setPosition(point); }); GEvent.addListener(map, "moveend", function() { var point = map.getCenter() marker.setLatLng(point); setPosition(point); }); $submit.onclick = function(){showAddress($address.value)}; function showAddress() { if(!arguments[0]) return false; var address = arguments[0]; if (geocoder) { geocoder.getLatLng(address, function(point) { if (!point) { alert(address + " not found"); }else{ setPosition(point); map.setCenter(point, 14); } }); } } function setPosition(){ $lat.value = arguments[0].lat(); $lon.value = arguments[0].lng(); } })(); </script> '); } public function getJavascripts() { return array(''); } public function render($name, $value = null, $attributes = array(), $errors = array()) { // define main template variables $template_vars = array( '{div.id}' => $this->generateId($name), '{div.class}' => $this->getOption('div.class'), '{map.id}' => $this->generateId($name.'[map]'), '{map.style}' => $this->getOption('map.style'), '{map.height}' => $this->getOption('map.height'), '{map.width}' => $this->getOption('map.width'), '{input.lookup.id}' => $this->generateId($name.'[lookup]'), '{input.lookup.name}' => $this->getOption('lookup.name'), '{input.address.id}' => $this->generateId($name.'[address]'), '{input.lat.id}' => $this->generateId($name.'[lat]'), '{input.lon.id}' => $this->generateId($name.'[lon]'), ); // vérifie si la valeur est valide $value = !is_array($value) ? array() : $value; $value['address'] = isset($value['address']) ? $value['address'] : ''; $value['lon'] = isset($value['long']) ? $value['lon'] : ''; $value['lat'] = isset($value['lat']) ? $value['lat'] : ''; // définit le widget pour le champ adresse $address = new sfWidgetFormInputText(array(), $this->getOption('address.options')); $template_vars['{input.search}'] = $address->render($name.'[address]', $value['address']); // définit les widgets pour les champs : longitude et latitude $hidden = new sfWidgetFormInputText; $template_vars['{input.lon}'] = $hidden->render($name.'[lon', $value['lon']); $template_vars['{input.lat}'] = $hidden->render($name.'[lat]', $value['lat']); // assemble le modèle avec les valeurs return strtr( $this->getOption('template.html').$this->getOption('template.javascript'), $template_vars ); } }
Revision: 24502
Updated Code
at March 2, 2010 17:05 by rccc
Updated Code
class sfWidgetFormGeocoder extends sfWidgetForm { public function configure($options = array(), $attributes = array()) { $this->addOption('address.options', array('style' => 'width:400px')); $this->setOption('default', array( 'address' => '', 'lon' => '1.913899', 'lat' => '47.900486' )); $this->addOption('div.class', 'geocoder-widget'); $this->addOption('map.height', '300px'); $this->addOption('map.width', '500px'); $this->addOption('map.style', ""); $this->addOption('lookup.name', ""); $this->addOption('template.html', ' <div id="{div.id}" class="{div.class}"> {input.search} <input type="submit" value="{input.lookup.name}" id="{input.lookup.id}" /> <br /> {input.lon} {input.lat} <div id="{map.id}" style="width:{map.width};height:{map.height};{map.style}"></div> </div> '); $this->addOption('template.javascript', ' <script type="text/javascript"> (function() { var $submit = document.getElementById("{input.lookup.id}"); var $address = document.getElementById("{input.address.id}"); var $lat = document.getElementById("{input.lat.id}"); var $lon = document.getElementById("{input.lon.id}"); var map = new GMap2(document.getElementById("{map.id}")); var center = new GLatLng( $lat.value||47.900486, $lon.value||1.913899); var marker = new GMarker(center, {draggable: true}); var geocoder = new GClientGeocoder(); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(center, 5); map.addOverlay(marker); setPosition(center); GEvent.addListener(marker, "dragend", function() { var point = marker.getPoint(); map.panTo(point); setPosition(point); }); GEvent.addListener(map, "moveend", function() { var point = map.getCenter() marker.setLatLng(point); setPosition(point); }); $submit.onclick = function(){showAddress($address.value)}; function showAddress() { if(!arguments[0]) return false; var address = arguments[0]; if (geocoder) { geocoder.getLatLng(address, function(point) { if (!point) { alert(address + " not found"); }else{ setPosition(point); map.setCenter(point, 14); } }); } } function setPosition(){ $lat.value = arguments[0].lat(); $lon.value = arguments[0].lng(); } })(); </script> '); } public function getJavascripts() { return array(''); } public function render($name, $value = null, $attributes = array(), $errors = array()) { // define main template variables $template_vars = array( '{div.id}' => $this->generateId($name), '{div.class}' => $this->getOption('div.class'), '{map.id}' => $this->generateId($name.'[map]'), '{map.style}' => $this->getOption('map.style'), '{map.height}' => $this->getOption('map.height'), '{map.width}' => $this->getOption('map.width'), '{input.lookup.id}' => $this->generateId($name.'[lookup]'), '{input.lookup.name}' => $this->getOption('lookup.name'), '{input.address.id}' => $this->generateId($name.'[address]'), '{input.lat.id}' => $this->generateId($name.'[lat]'), '{input.lon.id}' => $this->generateId($name.'[lon]'), ); // vérifie si la valeur est valide $value = !is_array($value) ? array() : $value; $value['address'] = isset($value['address']) ? $value['address'] : ''; $value['lon'] = isset($value['long']) ? $value['lon'] : ''; $value['lat'] = isset($value['lat']) ? $value['lat'] : ''; // définit le widget pour le champ adresse $address = new sfWidgetFormInputText(array(), $this->getOption('address.options')); $template_vars['{input.search}'] = $address->render($name.'[address]', $value['address']); // définit les widgets pour les champs : longitude et latitude $hidden = new sfWidgetFormInputText; $template_vars['{input.lon}'] = $hidden->render($name.'[lon', $value['lon']); $template_vars['{input.lat}'] = $hidden->render($name.'[lat]', $value['lat']); // assemble le modèle avec les valeurs return strtr( $this->getOption('template.html').$this->getOption('template.javascript'), $template_vars ); } }
Revision: 24501
Updated Code
at March 2, 2010 17:05 by rccc
Updated Code
class sfWidgetFormGeocoder extends sfWidgetForm { public function configure($options = array(), $attributes = array()) { $this->addOption('address.options', array('style' => 'width:400px')); $this->setOption('default', array( 'address' => '', 'lon' => '1.913899', 'lat' => '47.900486' )); $this->addOption('div.class', 'geocoder-widget'); $this->addOption('map.height', '300px'); $this->addOption('map.width', '500px'); $this->addOption('map.style', ""); $this->addOption('lookup.name', ""); $this->addOption('template.html', ' <div id="{div.id}" class="{div.class}"> {input.search} <input type="submit" value="{input.lookup.name}" id="{input.lookup.id}" /> <br /> {input.lon} {input.lat} <div id="{map.id}" style="width:{map.width};height:{map.height};{map.style}"></div> </div> '); $this->addOption('template.javascript', ' <script type="text/javascript"> (function() { var $submit = document.getElementById("{input.lookup.id}"); var $address = document.getElementById("{input.address.id}"); var $lat = document.getElementById("{input.lat.id}"); var $lon = document.getElementById("{input.lon.id}"); var map = new GMap2(document.getElementById("{map.id}")); var center = new GLatLng( $lat.value||47.900486, $lon.value||1.913899); var marker = new GMarker(center, {draggable: true}); var geocoder = new GClientGeocoder(); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(center, 5); map.addOverlay(marker); setPosition(center); GEvent.addListener(marker, "dragend", function() { var point = marker.getPoint(); map.panTo(point); setPosition(point); }); GEvent.addListener(map, "moveend", function() { var point = map.getCenter() marker.setLatLng(point); setPosition(point); }); $submit.onclick = function(){showAddress($address.value)}; function showAddress() { if(!arguments[0]) return false; var address = arguments[0]; if (geocoder) { geocoder.getLatLng(address, function(point) { if (!point) { alert(address + " not found"); }else{ setPosition(point); map.setCenter(point, 14); } }); } } function setPosition(){ $lat.value = arguments[0].lat(); $lon.value = arguments[0].lng(); } })(); </script> '); } public function getJavascripts() { return array(''); } public function render($name, $value = null, $attributes = array(), $errors = array()) { // define main template variables $template_vars = array( '{div.id}' => $this->generateId($name), '{div.class}' => $this->getOption('div.class'), '{map.id}' => $this->generateId($name.'[map]'), '{map.style}' => $this->getOption('map.style'), '{map.height}' => $this->getOption('map.height'), '{map.width}' => $this->getOption('map.width'), '{input.lookup.id}' => $this->generateId($name.'[lookup]'), '{input.lookup.name}' => $this->getOption('lookup.name'), '{input.address.id}' => $this->generateId($name.'[address]'), '{input.lat.id}' => $this->generateId($name.'[lat]'), '{input.lon.id}' => $this->generateId($name.'[lon]'), ); // vérifie si la valeur est valide $value = !is_array($value) ? array() : $value; $value['address'] = isset($value['address']) ? $value['address'] : ''; $value['lon'] = isset($value['long']) ? $value['lon'] : ''; $value['lat'] = isset($value['lat']) ? $value['lat'] : ''; // définit le widget pour le champ adresse $address = new sfWidgetFormInputText(array(), $this->getOption('address.options')); $template_vars['{input.search}'] = $address->render($name.'[address]', $value['address']); // définit les widgets pour les champs : longitude et latitude $hidden = new sfWidgetFormInputText; $template_vars['{input.lon}'] = $hidden->render($name.'[lon', $value['lon']); $template_vars['{input.lat}'] = $hidden->render($name.'[lat]', $value['lat']); // assemble le modèle avec les valeurs return strtr( $this->getOption('template.html').$this->getOption('template.javascript'), $template_vars ); } }
Revision: 24500
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 2, 2010 17:01 by rccc
Initial Code
class sfWidgetFormGeocoder extends sfWidgetForm { public function configure($options = array(), $attributes = array()) { $this->addOption('address.options', array('style' => 'width:400px')); $this->setOption('default', array( 'address' => '', 'lon' => '1.913899', 'lat' => '47.900486' )); $this->addOption('div.class', 'geocoder-widget'); $this->addOption('map.height', '300px'); $this->addOption('map.width', '500px'); $this->addOption('map.style', ""); $this->addOption('lookup.name', ""); $this->addOption('template.html', ' <div id="{div.id}" class="{div.class}"> {input.search} <input type="submit" value="{input.lookup.name}" id="{input.lookup.id}" /> <br /> {input.lon} {input.lat} <div id="{map.id}" style="width:{map.width};height:{map.height};{map.style}"></div> </div> '); $this->addOption('template.javascript', ' <script type="text/javascript"> (function() { var $submit = document.getElementById("{input.lookup.id}"); var $address = document.getElementById("{input.address.id}"); var $lat = document.getElementById("{input.lat.id}"); var $lon = document.getElementById("{input.lon.id}"); var map = new GMap2(document.getElementById("{map.id}")); var center = new GLatLng( $lat.value||47.900486, $lon.value||1.913899); var marker = new GMarker(center, {draggable: true}); var geocoder = new GClientGeocoder(); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(center, 5); map.addOverlay(marker); setPosition(center); GEvent.addListener(marker, "dragend", function() { var point = marker.getPoint(); map.panTo(point); setPosition(point); }); GEvent.addListener(map, "moveend", function() { var point = map.getCenter() marker.setLatLng(point); setPosition(point); }); $submit.onclick = function(){showAddress($address.value)}; function showAddress() { if(!arguments[0]) return false; var address = arguments[0]; if (geocoder) { geocoder.getLatLng(address, function(point) { if (!point) { alert(address + " not found"); }else{ setPosition(point); map.setCenter(point, 14); } }); } } function setPosition(){ $lat.value = arguments[0].lat(); $lon.value = arguments[0].lng(); } })(); </script> '); } public function getJavascripts() { return array(''); } public function render($name, $value = null, $attributes = array(), $errors = array()) { // define main template variables $template_vars = array( '{div.id}' => $this->generateId($name), '{div.class}' => $this->getOption('div.class'), '{map.id}' => $this->generateId($name.'[map]'), '{map.style}' => $this->getOption('map.style'), '{map.height}' => $this->getOption('map.height'), '{map.width}' => $this->getOption('map.width'), '{input.lookup.id}' => $this->generateId($name.'[lookup]'), '{input.lookup.name}' => $this->getOption('lookup.name'), '{input.address.id}' => $this->generateId($name.'[address]'), '{input.lat.id}' => $this->generateId($name.'[lat]'), '{input.lon.id}' => $this->generateId($name.'[lon]'), ); // vérifie si la valeur est valide $value = !is_array($value) ? array() : $value; $value['address'] = isset($value['address']) ? $value['address'] : ''; $value['lon'] = isset($value['long']) ? $value['lon'] : ''; $value['lat'] = isset($value['lat']) ? $value['lat'] : ''; // définit le widget pour le champ adresse $address = new sfWidgetFormInputText(array(), $this->getOption('address.options')); $template_vars['{input.search}'] = $address->render($name.'[address]', $value['address']); // définit les widgets pour les champs : longitude et latitude $hidden = new sfWidgetFormInputText; $template_vars['{input.lon}'] = $hidden->render($name.'[lon', $value['lon']); $template_vars['{input.lat}'] = $hidden->render($name.'[lat]', $value['lat']); // assemble le modèle avec les valeurs return strtr( $this->getOption('template.html').$this->getOption('template.javascript'), $template_vars ); } }
Initial URL
Initial Description
i use this link : http://www.symfony-project.org/more-with-symfony/1_4/fr/05-Custom-Widgets-and-Validators , but this one is lighest and don't require jquery
Initial Title
sfWidgetFormGeocoder / sfValidatorGeocoder
Initial Tags
Initial Language
PHP