sfEntityAttributeValuePlugin
1.0.6stable
for and Doctrine
MIT
The sfEntityAttributeValuePlugin is a symfony plugin that allows use of the Entity-Attribute-Value
data-model as a doctrine behavior.
This plugin provides a way to easily create dynamic fields with jQuery Form Builder Plugin
and bind then to a specific object (DB line) of your model. It also allow you
to fill in these fields from other models that have a ManyToOne relation with
the first one. And finally, these stored EAV can be exploited in edit/read mode.
Developers
| Name |
Status |
Email |
Ali hichem |
lead |
moc.liam <<ta>> mehcih.ila
|
License
Copyright (c) 2011 Ali hichem
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.
Changelog for release 1.0.6 - 19/07/2011
- add Unit Tests
- update readme
- translate script comment
Other releases
Release 1.0.6 - 19/07/2011
- add Unit Tests
- update readme
- translate script comment
sfEntityAttributeValuePlugin
The sfEntityAttributeValuePlugin is a symfony plugin that allows use of the Entity-Attribute-Value
data-model as a doctrine behavior.
This plugin provides a way to easily create dynamic fields with jQuery Form Builder Plugin
and bind then to a specific object (DB line) of your model. It also allow you
to fill in these fields from other models that have a ManyToOne relation with
the first one. And finally, these stored EAV can be exploited in edit/read mode.
Installation
Install the plugin (via a package)
$ symfony plugin:install sfEntityAttributeValuePlugin
or (via a Svn checkout)
$ svn co http://svn.symfony-project.com/plugins/sfEntityAttributeValuePlugin plugins/sfEntityAttributeValuePlugin
Activate the plugin in your project configuration file (in config/ProjectConfiguration.class.php).
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
//...
$this->enablePlugins('sfEntityAttributeValuePlugin');
}
}
Apply the EAV behavior to your model in your schema file config/doctrine/schema.yml , ie:
Assume that we want to bind dynamic fields to each object of a model called "ParentModel" and then
insert data in these fields from a 'ChildModel' who is related as ManyToOne to the "ParentModel", the schema
will contain config like this:
ParentModel:
actAs:
EavBehavior:
mode: create
columns:
...
ChildModel:
actAs:
EavBehavior:
mode: insert
parent_resource: ParentModel
columns:
parent_model_id: { type: integer }
...
relations:
ParentModel: { local: parent_model_id, foreign: id }
Build Eav models and create tables :
$ symfony doctrine:build --all
alternatively you could build the models, the sql, then run the sql manually
Build (or update) the global resource file to affect unique id for all your models
$ symfony eav:init-config
Important note: this task will create/update the file resources.yml that hold the
models ids, do not change manually this files, this may damage your EAV structure!
Activate the "eav" module in the settings.yml:
all:
.settings:
enabled_modules: [ default, eav ]
publish assets
$ symfony plugin:publish-assets
Clear your cache
$ symfony cc
Add the sfWidgetFormEav as a widgetSchema in all forms that have the EavBehavior. The sfEntityAttributeValuePlugin
is enough smart to render the widget in create or insert mode.
# lib/form/doctrine/ParentModelForm.php
class ParentModelForm extends BaseParentModelForm
{
public function configure()
{
$this->widgetSchema['eav'] = new sfWidgetFormEav($this);
}
}
# lib/form/doctrine/ChildModelForm.php
class ChildModelForm extends BaseChildModelForm
{
public function configure()
{
$this->widgetSchema['eav'] = new sfWidgetFormEav($this);
}
}
Add the widget "eav" in the form partial
# _form.php
echo $form['eav']-> renderRow();
(future improvements)
Ajax eav child binder: when editing a child entity, eav structure will be updated via Ajax.
Smart EAV tables cleaner: to clean obsolete data from eav tables.
Required Field support
Sortable EAV