diff --git a/core/lib/Thelia/Action/Country.php b/core/lib/Thelia/Action/Country.php index 41e1f310e..1fa90b6b9 100644 --- a/core/lib/Thelia/Action/Country.php +++ b/core/lib/Thelia/Action/Country.php @@ -22,11 +22,13 @@ /*************************************************************************************/ namespace Thelia\Action; + use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Country\CountryCreateEvent; use Thelia\Core\Event\Country\CountryDeleteEvent; use Thelia\Core\Event\Country\CountryUpdateEvent; use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\Country as CountryModel; /** @@ -39,6 +41,17 @@ class Country extends BaseAction implements EventSubscriberInterface public function create(CountryCreateEvent $event) { + $country = new CountryModel(); + + $country + ->setIsocode($event->getIsocode()) + ->setIsoalpha2($event->getIsoAlpha2()) + ->setIsoalpha3($event->getIsoAlpha3()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->save(); + + $event->setCountry($country); } diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 87575f59b..a9b3e247d 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -116,6 +116,11 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index aaebec3f9..47208fdb4 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -415,7 +415,7 @@ Thelia\Controller\Admin\CountryController::createAction - + Thelia\Controller\Admin\CountryController::updateAction \d+ diff --git a/core/lib/Thelia/Controller/Admin/CountryController.php b/core/lib/Thelia/Controller/Admin/CountryController.php index d2951d3f2..c63be90b4 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -93,11 +93,20 @@ class CountryController extends AbstractCrudController /** * Hydrate the update form for this object, before passing it to the update template * - * @param unknown $object + * @param \Thelia\Model\Country $object */ protected function hydrateObjectForm($object) { - // TODO: Implement hydrateObjectForm() method. + $data = array( + 'id' => $object->getId(), + 'locale' => $object->getLocale(), + 'title' => $object->getTitle(), + 'isocode' => $object->getIsocode(), + 'isoalpha2' => $object->getIsoalpha2(), + 'isoalpha3' => $object->getIsoalpha3(), + ); + + return new CountryModificationForm($this->getRequest(), 'form', $data); } /** diff --git a/core/lib/Thelia/Form/CountryCreationForm.php b/core/lib/Thelia/Form/CountryCreationForm.php index 1b10ebc07..fe7486852 100644 --- a/core/lib/Thelia/Form/CountryCreationForm.php +++ b/core/lib/Thelia/Form/CountryCreationForm.php @@ -39,11 +39,14 @@ class CountryCreationForm extends BaseForm "for" => "title" ) )) - ->add("area", "text", array( + ->add("locale", "text", array( "constraints" => array( new NotBlank() ), - "label" => Translator::getInstance()->trans("Country area *"), + "label_attr" => array("for" => "locale_create") + )) + ->add("area", "text", array( + "label" => Translator::getInstance()->trans("Country area"), "label_attr" => array( "for" => "area" ) diff --git a/core/lib/Thelia/Form/CountryModificationForm.php b/core/lib/Thelia/Form/CountryModificationForm.php index 687642ed1..68570425b 100644 --- a/core/lib/Thelia/Form/CountryModificationForm.php +++ b/core/lib/Thelia/Form/CountryModificationForm.php @@ -28,6 +28,8 @@ use Thelia\Core\Translation\Translator; class CountryModificationForm extends CountryCreationForm { + use StandardDescriptionFieldsTrait; + protected function buildForm() { parent::buildForm(true); @@ -35,6 +37,9 @@ class CountryModificationForm extends CountryCreationForm $this->formBuilder ->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0))))) ; + + // Add standard description fields, excluding title and locale, which a re defined in parent class + $this->addStandardDescFields(array('title', 'locale')); } public function getName() diff --git a/core/lib/Thelia/Model/Base/Country.php b/core/lib/Thelia/Model/Base/Country.php index fd16e148d..eb8312369 100644 --- a/core/lib/Thelia/Model/Base/Country.php +++ b/core/lib/Thelia/Model/Base/Country.php @@ -1071,6 +1071,10 @@ abstract class Country implements ActiveRecordInterface $modifiedColumns = array(); $index = 0; + $this->modifiedColumns[] = CountryTableMap::ID; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . CountryTableMap::ID . ')'); + } // check the columns in natural order for more readable SQL queries if ($this->isColumnModified(CountryTableMap::ID)) { @@ -1140,6 +1144,13 @@ abstract class Country implements ActiveRecordInterface throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); } + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + $this->setNew(false); } @@ -1439,7 +1450,6 @@ abstract class Country implements ActiveRecordInterface */ public function copyInto($copyObj, $deepCopy = false, $makeNew = true) { - $copyObj->setId($this->getId()); $copyObj->setAreaId($this->getAreaId()); $copyObj->setIsocode($this->getIsocode()); $copyObj->setIsoalpha2($this->getIsoalpha2()); @@ -1475,6 +1485,7 @@ abstract class Country implements ActiveRecordInterface if ($makeNew) { $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value } } diff --git a/core/lib/Thelia/Model/Map/CountryTableMap.php b/core/lib/Thelia/Model/Map/CountryTableMap.php index 519af7176..752f2b34a 100644 --- a/core/lib/Thelia/Model/Map/CountryTableMap.php +++ b/core/lib/Thelia/Model/Map/CountryTableMap.php @@ -167,7 +167,7 @@ class CountryTableMap extends TableMap $this->setPhpName('Country'); $this->setClassName('\\Thelia\\Model\\Country'); $this->setPackage('Thelia.Model'); - $this->setUseIdGenerator(false); + $this->setUseIdGenerator(true); // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('AREA_ID', 'AreaId', 'INTEGER', 'area', 'ID', false, null, null); @@ -466,6 +466,10 @@ class CountryTableMap extends TableMap $criteria = $criteria->buildCriteria(); // build Criteria from Country object } + if ($criteria->containsKey(CountryTableMap::ID) && $criteria->keyContainsValue(CountryTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.CountryTableMap::ID.')'); + } + // Set the correct dbName $query = CountryQuery::create()->mergeWith($criteria); diff --git a/install/thelia.sql b/install/thelia.sql index 9b4ea4880..4371aa4f5 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -93,7 +93,7 @@ DROP TABLE IF EXISTS `country`; CREATE TABLE `country` ( - `id` INTEGER NOT NULL, + `id` INTEGER NOT NULL AUTO_INCREMENT, `area_id` INTEGER, `isocode` VARCHAR(4) NOT NULL, `isoalpha2` VARCHAR(2), diff --git a/local/config/schema.xml b/local/config/schema.xml index 9cd2e481a..65928176e 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -75,7 +75,7 @@ - + diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index bf68db361..21d3819e4 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -71,7 +71,7 @@
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.countries.change"} - + {/loop} @@ -121,7 +121,7 @@ {form_field form=$form field='success_url'} {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} - + {/form_field} {form_field form=$form field='title'} @@ -160,6 +160,12 @@
{/form_field} + {loop type="lang" name="default-lang" default_only="1"} + + {form_field form=$form field='locale'} + + {/form_field} + {/loop} {module_include location='country_create_form'} diff --git a/templates/admin/default/country-edit.html b/templates/admin/default/country-edit.html index fe1a0f240..b5d68e46b 100644 --- a/templates/admin/default/country-edit.html +++ b/templates/admin/default/country-edit.html @@ -92,13 +92,13 @@ {form_field form=$form field='title'}
- +
{/form_field} - {form_field form=$form field='short-description'} + {form_field form=$form field='chapo'}
- +
{/form_field} {form_field form=$form field='description'}