max_categories_on_pager: 3
default_picture_directory: /home/gustavo/symfonyreloaded/mobiads/web/uploads/images/
default_language: eng # Everything must exist at least with this language
+ default_country: Spain
sf_guard_plugin:
remember_key_expiration_age: 2592000 # 30 days in seconds
return $orderBy;
}
+
+ public function executeChosencountry($request)
+ {
+ $countryId = $request->getParameter('countryId');
+
+ //Never trust data coming from user
+ if (!isset($countryId))
+ {
+ //Incorrect data from user. Using default value.
+ $country = CountryTable::getInstance()->findOnebyCountryName(sfConfig::get('app_default_country'));
+ }
+ else
+ {
+ $country = CountryTable::getInstance()->findOneById($countryId);
+ if (!isset($country))
+ {
+ //Incorrect data from user. Using default value.
+ $country = CountryTable::getInstance()->findOnebyCountryName(sfConfig::get('app_default_country'));
+ }
+ }
+
+ $regionsJSON = array();
+ //Retrieve Doctrine_Collection
+ $regions = RegionTable::getInstance()->findByCountryId($country->getId());
+ //Using Doctrine_Collection_Iterator
+ $iterator = $regions->getIterator();
+ while ($region = $iterator->current())
+ {
+ $regionsJSON[$region->getId()] = $region->getRegionName();
+ $iterator->next();
+ }
+
+
+ //set content type HTTP field with the right value (we are going to use a JSON response)
+ $this->getResponse()->setContentType('application/json');
+
+ //Bypass completely the view layer and set the response code directly from this action.
+ //In this way the user may know if the data were updated
+ return $this->renderText(json_encode($regionsJSON));
+ }
+
+ public function executeChosencountry($request)
+ {
+ $regionId = $request->getParameter('regionId');
+
+ //Never trust data coming from user
+ if (!isset($regionId))
+ {
+ //Incorrect data from user. Using default value.
+ $country = RegionTable::getInstance()->findOnebyCountryName(sfConfig::get('app_default_country'));
+ }
+ else
+ {
+ $country = CountryTable::getInstance()->findOneById($countryId);
+ if (!isset($country))
+ {
+ //Incorrect data from user. Using default value.
+ $country = CountryTable::getInstance()->findOnebyCountryName(sfConfig::get('app_default_country'));
+ }
+ }
+
+ $regionsJSON = array();
+ //Retrieve Doctrine_Collection
+ $regions = RegionTable::getInstance()->findByCountryId($country->getId());
+ //Using Doctrine_Collection_Iterator
+ $iterator = $regions->getIterator();
+ while ($region = $iterator->current())
+ {
+ $regionsJSON[$region->getId()] = $region->getRegionName();
+ $iterator->next();
+ }
+
+ //set content type HTTP field with the right value (we are going to use a JSON response)
+ $this->getResponse()->setContentType('application/json');
+
+ //Bypass completely the view layer and set the response code directly from this action.
+ //In this way the user may know if the data were updated
+ return $this->renderText(json_encode($regionsJSON));
+ }
}
<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>
+<script type="text/javascript">
+ $(document).ready(function(){
+ $('#office_City_Region_country_id').change(function() {
+ $.post('<?php echo url_for('office/chosencountry') ?>', { 'countryId': $(this).val() },
+ function(data){
+ $('#office_City_region_id').empty();
+ $('#office_City_region_id').removeAttr('disabled');
+ $.each(data, function(value, key) {
+ $('#office_City_region_id').append($("<option></option>").attr("value", value).text(key));
+ });
+ }, "json");
+ });
+ });
+</script>
+
<form action="<?php echo url_for('office/'.($form->getObject()->isNew() ? 'create' : 'update').'?page='.$page.'&sort='.$sort.(!$form->getObject()->isNew() ? '&id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<tbody>
<?php echo $form->renderGlobalErrors() ?>
<?php echo $form->renderHiddenFields(false) ?>
+ <?php echo $form['City']['Region']['country_id']->renderRow(array('class' => 'validate-selection'))?>
+ <?php echo $form['City']['region_id']->renderRow(array('class' => 'validate-selection'))?>
<?php echo $form['city_id']->renderRow(array('class' => 'validate-selection')) ?>
<?php echo $form['office_street_address']->renderRow(array('class' => 'required')) ?>
<?php echo $form['office_zip']->renderRow(array('class' => 'required')) ?>
{
public function configure()
{
+ unset($this['city_name']);
+
+ $this->widgetSchema['region_id']->setAttribute('disabled', 'disabled');
+
+ $this->embedRelation('Region');
}
}
{
public function configure()
{
+ unset($this['iso_code_2']);
+ unset($this['iso_code_3']);
+ unset($this['country_name']);
}
}
{
$this->useFields(array('city_id', 'office_street_address', 'office_zip'));
-
+ if($this->isNew())
+ {
+ $country = CountryTable::getInstance()->findOnebyCountryName(sfConfig::get('app_default_country'));
+ $region = RegionTable::getInstance()->findOneByCountryId($country->getId());
+ $query = CityTable::getInstance()->getCitiesByRegionIdQuery($region->getId());
+ }
$this->widgetSchema['longitude'] = new sfWidgetFormInputFloat();
$this->widgetSchema['latitude'] = new sfWidgetFormInputFloat();
+ $this->widgetSchema['city_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('City'),
+ 'add_empty' => true,
+ 'query' => $query));
+
+
+ $this->widgetSchema['city_id']->setAttribute('disabled', 'disabled');
+
+
$this->validatorSchema['longitude'] = new sfValidatorNumber(array('max' => 180,
'min' => -180,
'office_street_address' => 'Address: ',
'office_zip' => 'ZIP:',));
+ $this->embedRelation('City');
+
//In the future the companies could pay for improvements in their accounts (premium accounts)
//1 premium company could avoid to other companies on the same GPS point. This validator should check if that GPS point is being used by
{
public function configure()
{
+ unset($this['region_name']);
+
+ $this->embedRelation('Country');
}
}
return $query;
}
+
+ public function getCitiesByRegionIdQuery($regionId)
+ {
+ return $this->createQuery('city')->where('city.region_id = ?', $regionId);
+ }
}