Skip to content

Commit

Permalink
Import from symfony SVN
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 15, 2010
0 parents commit c8b928c
Show file tree
Hide file tree
Showing 19 changed files with 591 additions and 0 deletions.
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2010 Thibault Duplessis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
8 changes: 8 additions & 0 deletions README.markdown
@@ -0,0 +1,8 @@
dmGoogleMapPlugin allows to display configurable google maps.
It packages a Diem front widget, and adds a _map() helper.
The plugin is fully extensible. Only works with [Diem 5.0](http://diem-project.org/) installed.

Documentation
-------------

See the online documentation : [Diem Google Map plugin documentation](http://diem-project.org/plugins/dmgooglemapplugin)
10 changes: 10 additions & 0 deletions config/dm/assets.yml
@@ -0,0 +1,10 @@
js:

dmGoogleMapPlugin:

api: http://maps.google.com/maps/api/js?sensor=false

widgetShowForm: widget/showForm

launcher: launcher
dmGoogleMap: dmGoogleMap
18 changes: 18 additions & 0 deletions config/dm/services.yml
@@ -0,0 +1,18 @@
parameters:

google_map_tag.class: dmGoogleMapTag
google_map_tag.options: []

google_map_helper.class: dmGoogleMapHelper

services:

google_map_tag:
class: %google_map_tag.class%
shared: false
arguments: [ %google_map_tag.options% ]

google_map_helper:
class: %google_map_helper.class%
shared: true
arguments: [ @context ]
5 changes: 5 additions & 0 deletions config/dm/widget_types.yml
@@ -0,0 +1,5 @@
dmWidgetGoogleMap:

show:
cache: false
public_name: Google Map
115 changes: 115 additions & 0 deletions lib/dmWidget/dmWidgetGoogleMapShowForm.php
@@ -0,0 +1,115 @@
<?php

class dmWidgetGoogleMapShowForm extends dmWidgetPluginForm
{

public function configure()
{
$this->widgetSchema['address'] = new sfWidgetFormInputText();
$this->validatorSchema['address'] = new sfValidatorString();
$this->widgetSchema['address']->setLabel('Search a place');

$this->widgetSchema['mapTypeId'] = new sfWidgetFormSelect(array(
'choices' => dmArray::valueToKey($this->getMapTypeIds())
));
$this->validatorSchema['mapTypeId'] = new sfValidatorChoice(array(
'choices' => $this->getMapTypeIds()
));
$this->widgetSchema['mapTypeId']->setLabel('Map type');

$this->widgetSchema['zoom'] = new sfWidgetFormSelect(array(
'choices' => dmArray::valueToKey($this->getZooms())
));
$this->validatorSchema['zoom'] = new sfValidatorChoice(array(
'choices' => $this->getZooms()
));

$this->widgetSchema['navigationControl'] = new sfWidgetFormInputCheckbox();
$this->validatorSchema['navigationControl'] = new sfValidatorBoolean();
$this->widgetSchema['navigationControl']->setLabel('Navigation');

$this->widgetSchema['mapTypeControl'] = new sfWidgetFormInputCheckbox();
$this->validatorSchema['mapTypeControl'] = new sfValidatorBoolean();
$this->widgetSchema['mapTypeControl']->setLabel('Map type');

$this->widgetSchema['scaleControl'] = new sfWidgetFormInputCheckbox();
$this->validatorSchema['scaleControl'] = new sfValidatorBoolean();
$this->widgetSchema['scaleControl']->setLabel('Scale');

$this->widgetSchema['width'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['width'] = new dmValidatorCssSize(array(
'required' => false
));

$this->widgetSchema['height'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['height'] = new dmValidatorCssSize(array(
'required' => false
));

$this->widgetSchema['splash'] = new sfWidgetFormInputText();
$this->validatorSchema['splash'] = new sfValidatorString(array(
'required' => false
));
$this->widgetSchema->setHelp('splash', 'Display a message while the map is loading');

if(!$this->getDefault('width'))
{
$this->setDefault('width', '100%');
}
if(!$this->getDefault('height'))
{
$this->setDefault('height', '300px');
}
if(!$this->getDefault('mapTypeId'))
{
$this->setDefault('mapTypeId', 'hybrid');
}
if(!$this->getDefault('zoom'))
{
$this->setDefault('zoom', '14');
}

parent::configure();
}

protected function getMapTypeIds()
{
return array('roadmap', 'satellite', 'hybrid', 'terrain');
}

protected function getZooms()
{
return range(2, 20);
}

public function getStylesheets()
{
return array(
'lib.ui-tabs'
);
}

public function getJavascripts()
{
return array(
'lib.ui-tabs',
'core.tabForm',
'dmGoogleMapPlugin.widgetShowForm'
);
}

protected function renderContent($attributes)
{
return $this->getHelper()->renderPartial('dmWidgetGoogleMap', 'showForm', array(
'form' => $this,
'baseTabId' => 'dm_widget_google_map_'.$this->dmWidget->get('id')
));
}

public function getWidgetValues()
{
$values = parent::getWidgetValues();

return $values;
}
}
53 changes: 53 additions & 0 deletions lib/dmWidget/dmWidgetGoogleMapShowView.php
@@ -0,0 +1,53 @@
<?php

class dmWidgetGoogleMapShowView extends dmWidgetPluginView
{

public function configure()
{
parent::configure();

$this->addRequiredVar(array(
'address',
'mapTypeId',
'zoom',
'navigationControl',
'mapTypeControl',
'scaleControl',
'width',
'height'));
}

protected function doRender()
{
$vars = $this->getViewVars();

$map = $this->getService('google_map_helper')->map()
->address($vars['address'])
->mapTypeId($vars['mapTypeId'])
->zoom($vars['zoom'])
->style(sprintf(
'width: %s; height: %s;',
dmArray::get($vars, 'width', '100%'),
dmArray::get($vars, 'height', '300px')
))
->navigationControl($vars['navigationControl'])
->mapTypeControl($vars['mapTypeControl'])
->scaleControl($vars['scaleControl'])
->splash($vars['splash']);

$this
->addJavascript($map->getJavascripts())
->addStylesheet($map->getStylesheets());

return $map;
}

protected function doRenderForIndex()
{
$vars = $this->getViewVars();

return $vars['address'];
}

}
17 changes: 17 additions & 0 deletions lib/helper/DmGoogleMapHelper.php
@@ -0,0 +1,17 @@
<?php

/*
* Get a dmGoogleMapTag instance
*/
function _map()
{
return sfContext::getInstance()->get('google_map_helper')->map();
}

/*
* Alternative to £map
*/
function £map()
{
return _map();
}
55 changes: 55 additions & 0 deletions lib/view/dmGoogleMapHelper.php
@@ -0,0 +1,55 @@
<?php

class dmGoogleMapHelper extends dmConfigurable
{
protected
$context;

public function __construct(dmContext $context, array $options = array())
{
$this->context = $context;

$this->initialize($options);
}

public function initialize(array $options)
{
$this->configure($options);
}

/*
* Get a dmGoogleMapTag instance
*/
public function map()
{
$map = $this->context->get('google_map_tag');

$response = $this->context->getResponse();

foreach($map->getStylesheets() as $stylesheet)
{
$response->addStylesheet($stylesheet);
}

foreach($map->getJavascripts() as $javascript)
{
$response->addJavascript($javascript);
}

/*
* Async loading won't work
* as the api itself uses async loading
*/
if(!$this->context->getRequest()->isXmlHttpRequest())
{
$response->addJavascript('dmGoogleMapPlugin.api');
}

return $map;
}

public function £map()
{
return $this->map();
}
}

0 comments on commit c8b928c

Please sign in to comment.