From: Gustavo Martin Morcuende Date: Tue, 15 May 2012 14:04:31 +0000 (+0200) Subject: Every user must have her/his language. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=0192df15a7bf029cf4d4d5dc61496ef838526d42;p=mobi%2F.git Every user must have her/his language. When creating a new account the user must choose her/his language. It is used to show the data from the database in the correct language which was chosen by the user. --- diff --git a/data/sql/schema.sql b/data/sql/schema.sql index 07d89e9..64901b1 100644 --- a/data/sql/schema.sql +++ b/data/sql/schema.sql @@ -18,7 +18,7 @@ CREATE TABLE sf_guard_group (id BIGSERIAL, name VARCHAR(255) UNIQUE, description CREATE TABLE sf_guard_group_permission (group_id BIGINT, permission_id BIGINT, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(group_id, permission_id)); CREATE TABLE sf_guard_permission (id BIGSERIAL, name VARCHAR(255) UNIQUE, description VARCHAR(1000), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(id)); CREATE TABLE sf_guard_remember_key (id BIGSERIAL, user_id BIGINT, remember_key VARCHAR(32), ip_address VARCHAR(50), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(id)); -CREATE TABLE sf_guard_user (id BIGSERIAL, first_name VARCHAR(255), last_name VARCHAR(255), email_address VARCHAR(255) NOT NULL UNIQUE, username VARCHAR(128) NOT NULL UNIQUE, algorithm VARCHAR(128) DEFAULT 'sha1' NOT NULL, salt VARCHAR(128), password VARCHAR(128), is_active BOOLEAN DEFAULT 'true', is_super_admin BOOLEAN DEFAULT 'false', last_login TIMESTAMP, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(id)); +CREATE TABLE sf_guard_user (id BIGSERIAL, first_name VARCHAR(255), last_name VARCHAR(255), email_address VARCHAR(255) NOT NULL UNIQUE, username VARCHAR(128) NOT NULL UNIQUE, algorithm VARCHAR(128) DEFAULT 'sha1' NOT NULL, salt VARCHAR(128), password VARCHAR(128), is_active BOOLEAN DEFAULT 'true', is_super_admin BOOLEAN DEFAULT 'false', last_login TIMESTAMP, language_id BIGINT, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(id)); CREATE TABLE sf_guard_user_group (user_id BIGINT, group_id BIGINT, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(user_id, group_id)); CREATE TABLE sf_guard_user_permission (user_id BIGINT, permission_id BIGINT, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(user_id, permission_id)); CREATE INDEX is_active_idx ON sf_guard_user (is_active); @@ -47,6 +47,7 @@ ALTER TABLE sf_guard_forgot_password ADD CONSTRAINT sf_guard_forgot_password_use ALTER TABLE sf_guard_group_permission ADD CONSTRAINT sf_guard_group_permission_permission_id_sf_guard_permission_id FOREIGN KEY (permission_id) REFERENCES sf_guard_permission(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE; ALTER TABLE sf_guard_group_permission ADD CONSTRAINT sf_guard_group_permission_group_id_sf_guard_group_id FOREIGN KEY (group_id) REFERENCES sf_guard_group(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE; ALTER TABLE sf_guard_remember_key ADD CONSTRAINT sf_guard_remember_key_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE; +ALTER TABLE sf_guard_user ADD CONSTRAINT sf_guard_user_language_id_language_id FOREIGN KEY (language_id) REFERENCES language(id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE; ALTER TABLE sf_guard_user_group ADD CONSTRAINT sf_guard_user_group_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE; ALTER TABLE sf_guard_user_group ADD CONSTRAINT sf_guard_user_group_group_id_sf_guard_group_id FOREIGN KEY (group_id) REFERENCES sf_guard_group(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE; ALTER TABLE sf_guard_user_permission ADD CONSTRAINT sf_guard_user_permission_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE; diff --git a/lib/filter/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserFormFilter.class.php b/lib/filter/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserFormFilter.class.php index c5d1512..865c98c 100644 --- a/lib/filter/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserFormFilter.class.php +++ b/lib/filter/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserFormFilter.class.php @@ -23,6 +23,7 @@ abstract class BasesfGuardUserFormFilter extends BaseFormFilterDoctrine 'is_active' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))), 'is_super_admin' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))), 'last_login' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())), + 'language_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'add_empty' => true)), 'created_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)), 'updated_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)), 'groups_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup')), @@ -40,6 +41,7 @@ abstract class BasesfGuardUserFormFilter extends BaseFormFilterDoctrine 'is_active' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))), 'is_super_admin' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))), 'last_login' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))), + 'language_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Language'), 'column' => 'id')), 'created_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))), 'updated_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))), 'groups_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup', 'required' => false)), @@ -110,6 +112,7 @@ abstract class BasesfGuardUserFormFilter extends BaseFormFilterDoctrine 'is_active' => 'Boolean', 'is_super_admin' => 'Boolean', 'last_login' => 'Date', + 'language_id' => 'ForeignKey', 'created_at' => 'Date', 'updated_at' => 'Date', 'groups_list' => 'ManyKey', diff --git a/lib/form/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserForm.class.php b/lib/form/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserForm.class.php index cf665bb..7e600e2 100644 --- a/lib/form/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserForm.class.php +++ b/lib/form/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserForm.class.php @@ -26,6 +26,7 @@ abstract class BasesfGuardUserForm extends BaseFormDoctrine 'is_active' => new sfWidgetFormInputCheckbox(), 'is_super_admin' => new sfWidgetFormInputCheckbox(), 'last_login' => new sfWidgetFormDateTime(), + 'language_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'add_empty' => true)), 'created_at' => new sfWidgetFormDateTime(), 'updated_at' => new sfWidgetFormDateTime(), 'groups_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup')), @@ -44,6 +45,7 @@ abstract class BasesfGuardUserForm extends BaseFormDoctrine 'is_active' => new sfValidatorBoolean(array('required' => false)), 'is_super_admin' => new sfValidatorBoolean(array('required' => false)), 'last_login' => new sfValidatorDateTime(array('required' => false)), + 'language_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'required' => false)), 'created_at' => new sfValidatorDateTime(), 'updated_at' => new sfValidatorDateTime(), 'groups_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup', 'required' => false)), diff --git a/lib/model/doctrine/base/BaseLanguage.class.php b/lib/model/doctrine/base/BaseLanguage.class.php index 052a150..b0b1562 100644 --- a/lib/model/doctrine/base/BaseLanguage.class.php +++ b/lib/model/doctrine/base/BaseLanguage.class.php @@ -7,6 +7,7 @@ * * @property string $language_name * @property string $code + * @property Doctrine_Collection $sfGuardUser * @property Doctrine_Collection $CompanyDescription * @property Doctrine_Collection $CompanyCategoryDescription * @property Doctrine_Collection $GeneralCategoryDescription @@ -14,12 +15,14 @@ * * @method string getLanguageName() Returns the current record's "language_name" value * @method string getCode() Returns the current record's "code" value + * @method Doctrine_Collection getSfGuardUser() Returns the current record's "sfGuardUser" collection * @method Doctrine_Collection getCompanyDescription() Returns the current record's "CompanyDescription" collection * @method Doctrine_Collection getCompanyCategoryDescription() Returns the current record's "CompanyCategoryDescription" collection * @method Doctrine_Collection getGeneralCategoryDescription() Returns the current record's "GeneralCategoryDescription" collection * @method Doctrine_Collection getAdDescription() Returns the current record's "AdDescription" collection * @method Language setLanguageName() Sets the current record's "language_name" value * @method Language setCode() Sets the current record's "code" value + * @method Language setSfGuardUser() Sets the current record's "sfGuardUser" collection * @method Language setCompanyDescription() Sets the current record's "CompanyDescription" collection * @method Language setCompanyCategoryDescription() Sets the current record's "CompanyCategoryDescription" collection * @method Language setGeneralCategoryDescription() Sets the current record's "GeneralCategoryDescription" collection @@ -52,6 +55,10 @@ abstract class BaseLanguage extends sfDoctrineRecord public function setUp() { parent::setUp(); + $this->hasMany('sfGuardUser', array( + 'local' => 'id', + 'foreign' => 'language_id')); + $this->hasMany('CompanyDescription', array( 'local' => 'id', 'foreign' => 'language_id')); diff --git a/lib/model/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUser.class.php b/lib/model/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUser.class.php index c38549d..bdd48a9 100644 --- a/lib/model/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUser.class.php +++ b/lib/model/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUser.class.php @@ -15,8 +15,10 @@ * @property boolean $is_active * @property boolean $is_super_admin * @property timestamp $last_login + * @property integer $language_id * @property Doctrine_Collection $Groups * @property Doctrine_Collection $Permissions + * @property Language $Language * @property Doctrine_Collection $sfGuardUserPermission * @property Doctrine_Collection $sfGuardUserGroup * @property sfGuardRememberKey $RememberKeys @@ -34,8 +36,10 @@ * @method boolean getIsActive() Returns the current record's "is_active" value * @method boolean getIsSuperAdmin() Returns the current record's "is_super_admin" value * @method timestamp getLastLogin() Returns the current record's "last_login" value + * @method integer getLanguageId() Returns the current record's "language_id" value * @method Doctrine_Collection getGroups() Returns the current record's "Groups" collection * @method Doctrine_Collection getPermissions() Returns the current record's "Permissions" collection + * @method Language getLanguage() Returns the current record's "Language" value * @method Doctrine_Collection getSfGuardUserPermission() Returns the current record's "sfGuardUserPermission" collection * @method Doctrine_Collection getSfGuardUserGroup() Returns the current record's "sfGuardUserGroup" collection * @method sfGuardRememberKey getRememberKeys() Returns the current record's "RememberKeys" value @@ -52,8 +56,10 @@ * @method sfGuardUser setIsActive() Sets the current record's "is_active" value * @method sfGuardUser setIsSuperAdmin() Sets the current record's "is_super_admin" value * @method sfGuardUser setLastLogin() Sets the current record's "last_login" value + * @method sfGuardUser setLanguageId() Sets the current record's "language_id" value * @method sfGuardUser setGroups() Sets the current record's "Groups" collection * @method sfGuardUser setPermissions() Sets the current record's "Permissions" collection + * @method sfGuardUser setLanguage() Sets the current record's "Language" value * @method sfGuardUser setSfGuardUserPermission() Sets the current record's "sfGuardUserPermission" collection * @method sfGuardUser setSfGuardUserGroup() Sets the current record's "sfGuardUserGroup" collection * @method sfGuardUser setRememberKeys() Sets the current record's "RememberKeys" value @@ -116,6 +122,9 @@ abstract class BasesfGuardUser extends sfDoctrineRecord $this->hasColumn('last_login', 'timestamp', null, array( 'type' => 'timestamp', )); + $this->hasColumn('language_id', 'integer', null, array( + 'type' => 'integer', + )); $this->index('is_active_idx', array( @@ -139,6 +148,11 @@ abstract class BasesfGuardUser extends sfDoctrineRecord 'local' => 'user_id', 'foreign' => 'permission_id')); + $this->hasOne('Language', array( + 'local' => 'language_id', + 'foreign' => 'id', + 'onDelete' => 'SET NULL')); + $this->hasMany('sfGuardUserPermission', array( 'local' => 'id', 'foreign' => 'user_id')); diff --git a/plugins/sfDoctrineGuardPlugin/config/doctrine/schema.yml b/plugins/sfDoctrineGuardPlugin/config/doctrine/schema.yml index eff91b9..8937c16 100644 --- a/plugins/sfDoctrineGuardPlugin/config/doctrine/schema.yml +++ b/plugins/sfDoctrineGuardPlugin/config/doctrine/schema.yml @@ -77,6 +77,8 @@ sfGuardUser: default: false last_login: type: timestamp + language_id: + type: integer indexes: is_active_idx: fields: [is_active] @@ -93,6 +95,11 @@ sfGuardUser: foreign: permission_id refClass: sfGuardUserPermission foreignAlias: Users + Language: + class: Language + local: language_id + foreign: id + onDelete: SET NULL sfGuardUserPermission: options: @@ -179,4 +186,4 @@ sfGuardForgotPassword: type: one foreignType: one foreignAlias: ForgotPassword - onDelete: CASCADE \ No newline at end of file + onDelete: CASCADE diff --git a/plugins/sfDoctrineGuardPlugin/data/fixtures/fixtures.yml b/plugins/sfDoctrineGuardPlugin/data/fixtures/fixtures.yml index 0261610..3ce3c0d 100644 --- a/plugins/sfDoctrineGuardPlugin/data/fixtures/fixtures.yml +++ b/plugins/sfDoctrineGuardPlugin/data/fixtures/fixtures.yml @@ -1,5 +1,6 @@ sfGuardUser: ADMIN: + Language: Spanish first_name: Gustavo last_name: Martin email_address: gu.martinm@gmail.com @@ -8,6 +9,7 @@ sfGuardUser: is_super_admin: true is_active: true DIA: + Language: Spanish first_name: Gustavo last_name: Empresa email_address: gu.empresadia@gmail.com @@ -16,6 +18,7 @@ sfGuardUser: is_super_admin: false is_active: true CARREFOUR: + Language: Spanish first_name: Gustavo last_name: Empresa email_address: gu.empresacarrefour@gmail.com @@ -24,6 +27,7 @@ sfGuardUser: is_super_admin: false is_active: true MOBILEADVERTISING: + Language: Spanish first_name: Gustavo last_name: Empresa email_address: gu.empresamobile@gmail.com @@ -32,6 +36,7 @@ sfGuardUser: is_super_admin: false is_active: true NORMAL_USER: + Language: Spanish first_name: Gustavo last_name: Usuario email_address: gu.usuario@gmail.com