From: Gustavo Martin Morcuende Date: Mon, 4 Jun 2012 02:02:39 +0000 (+0200) Subject: Computer making strange noises. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=be6c7c56ee5936d158c7b7ba3e1fe750d9f9aae8;p=mobi%2F.git Computer making strange noises. I AM AFRAID TO LOSE MY WHOLE WORK LOL Fucking Murphy. --- diff --git a/apps/companyfront/config/app.yml b/apps/companyfront/config/app.yml index 2d31786..19eecaf 100644 --- a/apps/companyfront/config/app.yml +++ b/apps/companyfront/config/app.yml @@ -8,6 +8,7 @@ all: 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 diff --git a/apps/companyfront/modules/office/actions/actions.class.php b/apps/companyfront/modules/office/actions/actions.class.php index 6c22438..70d8527 100644 --- a/apps/companyfront/modules/office/actions/actions.class.php +++ b/apps/companyfront/modules/office/actions/actions.class.php @@ -284,4 +284,83 @@ class officeActions extends sfActions 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)); + } } diff --git a/apps/companyfront/modules/office/templates/_formCustomOffice.php b/apps/companyfront/modules/office/templates/_formCustomOffice.php index c887f9e..717f8dd 100644 --- a/apps/companyfront/modules/office/templates/_formCustomOffice.php +++ b/apps/companyfront/modules/office/templates/_formCustomOffice.php @@ -1,6 +1,21 @@ + +
isMultipart() and print 'enctype="multipart/form-data" ' ?>> getObject()->isNew()): ?> @@ -11,6 +26,8 @@ renderGlobalErrors() ?> renderHiddenFields(false) ?> + renderRow(array('class' => 'validate-selection'))?> + renderRow(array('class' => 'validate-selection'))?> renderRow(array('class' => 'validate-selection')) ?> renderRow(array('class' => 'required')) ?> renderRow(array('class' => 'required')) ?> diff --git a/lib/form/doctrine/CityForm.class.php b/lib/form/doctrine/CityForm.class.php index 73a0770..5bd697c 100644 --- a/lib/form/doctrine/CityForm.class.php +++ b/lib/form/doctrine/CityForm.class.php @@ -12,5 +12,10 @@ class CityForm extends BaseCityForm { public function configure() { + unset($this['city_name']); + + $this->widgetSchema['region_id']->setAttribute('disabled', 'disabled'); + + $this->embedRelation('Region'); } } diff --git a/lib/form/doctrine/CountryForm.class.php b/lib/form/doctrine/CountryForm.class.php index 42d326a..04f4d49 100644 --- a/lib/form/doctrine/CountryForm.class.php +++ b/lib/form/doctrine/CountryForm.class.php @@ -12,5 +12,8 @@ class CountryForm extends BaseCountryForm { public function configure() { + unset($this['iso_code_2']); + unset($this['iso_code_3']); + unset($this['country_name']); } } diff --git a/lib/form/doctrine/OfficeForm.class.php b/lib/form/doctrine/OfficeForm.class.php index 4a0b661..cb5417e 100644 --- a/lib/form/doctrine/OfficeForm.class.php +++ b/lib/form/doctrine/OfficeForm.class.php @@ -14,11 +14,24 @@ class OfficeForm extends BaseOfficeForm { $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, @@ -47,6 +60,8 @@ class OfficeForm extends BaseOfficeForm '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 diff --git a/lib/form/doctrine/RegionForm.class.php b/lib/form/doctrine/RegionForm.class.php index 206abe8..5f48455 100644 --- a/lib/form/doctrine/RegionForm.class.php +++ b/lib/form/doctrine/RegionForm.class.php @@ -12,5 +12,8 @@ class RegionForm extends BaseRegionForm { public function configure() { + unset($this['region_name']); + + $this->embedRelation('Country'); } } diff --git a/lib/model/doctrine/CityTable.class.php b/lib/model/doctrine/CityTable.class.php index d985b2d..21b8c98 100644 --- a/lib/model/doctrine/CityTable.class.php +++ b/lib/model/doctrine/CityTable.class.php @@ -30,4 +30,9 @@ class CityTable extends Doctrine_Table return $query; } + + public function getCitiesByRegionIdQuery($regionId) + { + return $this->createQuery('city')->where('city.region_id = ?', $regionId); + } }