diff --git a/.buildpath b/.buildpath new file mode 100644 index 0000000..8bcb4b5 --- /dev/null +++ b/.buildpath @@ -0,0 +1,5 @@ + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..eaade81 --- /dev/null +++ b/.project @@ -0,0 +1,29 @@ + + + Tests + + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.dltk.core.scriptbuilder + + + + + + org.eclipse.php.core.PHPNature + org.eclipse.wst.jsdt.core.jsNature + org.eclipse.wst.common.project.facet.core.nature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..4649ef1 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.php.core.prefs b/.settings/org.eclipse.php.core.prefs new file mode 100644 index 0000000..4a77625 --- /dev/null +++ b/.settings/org.eclipse.php.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +include_path=0;/Tests diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..4743dbb --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/skeleton-application/module/Fieldset/src/Entity/Attribute.php b/skeleton-application/module/Fieldset/src/Entity/Attribute.php new file mode 100644 index 0000000..db8476d --- /dev/null +++ b/skeleton-application/module/Fieldset/src/Entity/Attribute.php @@ -0,0 +1,38 @@ +id = $id; + $this->title = $title; + + } + + + public function getId() + { + return $this->id; + } + + public function getTitle() + { + return $this->title; + } + + +} \ No newline at end of file diff --git a/skeleton-application/module/Fieldset/src/Entity/Category.php b/skeleton-application/module/Fieldset/src/Entity/Category.php new file mode 100644 index 0000000..02001b6 --- /dev/null +++ b/skeleton-application/module/Fieldset/src/Entity/Category.php @@ -0,0 +1,38 @@ +id = $id; + $this->title = $title; + + } + + + public function getId() + { + return $this->id; + } + + public function getTitle() + { + return $this->title; + } + + +} \ No newline at end of file diff --git a/skeleton-application/module/Fieldset/src/Entity/Product.php b/skeleton-application/module/Fieldset/src/Entity/Product.php index 48ba810..4b16ccc 100644 --- a/skeleton-application/module/Fieldset/src/Entity/Product.php +++ b/skeleton-application/module/Fieldset/src/Entity/Product.php @@ -19,14 +19,18 @@ class Product protected $categ; + /** + * @var array + */ + protected $items; + // Construct function with values public function __construct($id = null, $title = null, $categ = null) { $this->id = $id; $this->title = $title; $this->categ = $categ; - - } + } public function getId() @@ -44,6 +48,22 @@ public function getCateg() return $this->categ; } + /** + * @param array $items + * @return Product + */ + public function setItems(array $items) + { + $this->items = $items; + return $this; + } + /** + * @return array + */ + public function getItems() + { + return $this->items; + } } \ No newline at end of file diff --git a/skeleton-application/module/Fieldset/src/Form/ItemFieldset.php b/skeleton-application/module/Fieldset/src/Form/ItemFieldset.php index b2d4344..a7edf6e 100644 --- a/skeleton-application/module/Fieldset/src/Form/ItemFieldset.php +++ b/skeleton-application/module/Fieldset/src/Form/ItemFieldset.php @@ -18,7 +18,7 @@ public function __construct($name = null, $options = array(), $attributeManager $this->add(array( 'type' => 'number', 'name' => 'id', - 'options' => ['Provide a numeric ID'] + 'options' => ['label' => 'Provide a numeric ID'] )); $this->add(array( diff --git a/skeleton-application/module/Fieldset/src/Form/ProductForm.php b/skeleton-application/module/Fieldset/src/Form/ProductForm.php index a18b6c0..b33a593 100644 --- a/skeleton-application/module/Fieldset/src/Form/ProductForm.php +++ b/skeleton-application/module/Fieldset/src/Form/ProductForm.php @@ -2,6 +2,7 @@ namespace Fieldset\Form; use Zend\Form\Form; +use Zend\Form\Element; use Fieldset\Form\ItemFieldset; // One product is defined by a category and list of items @@ -34,7 +35,7 @@ public function __construct($name = null, $options = array(), $categoryManager = $this->add(array( 'type' => 'number', 'name' => 'id', - 'options' => ['Provide a numeric ID'] + 'options' => ['label' => 'Provide a numeric ID'] )); @@ -62,20 +63,48 @@ public function __construct($name = null, $options = array(), $categoryManager = ]); // Fieldset for ITEM belonging to product: - /* $this->add(array( - 'name' => 'item-fieldset', - 'type' => 'ItemFieldset', - 'options' => array( - 'use_as_base_fieldset' => true, - ), + $item = new ItemFieldset('Item-details',null,$this->attributeManager); + /* $item->setOptions( + [ + + 'template_placeholder' => '__placeholder__' + ] - )); - + + ); */ - - - $items = new ItemFieldset('Item-details',null,$this->attributeManager); + /* + $items = new Element\Collection('Item-details'); + $items->setTargetElement($item); + + $items->setOptions([ + 'use_as_base_fieldset' => true, + 'should_create_template' => true, + 'allow_add' => true, + 'count' => 2, + ] + ); + + $this->add($items); + */ + // OR : + $this->add(array( + 'type' => 'collection', + 'name' => 'items', + 'options' => array( + + 'should_create_template' => true, + 'allow_add' => true, + 'count' => 2, + 'target_element' => $item, + 'template_placeholder' => '__placeholder__' + ) + )); + + /***CREATE PRODUCT FIELDSET !!! + * https://framework.zend.com/manual/2.4/en/modules/zend.form.collections.html + * ****/ // Submit button : $this->add(array( diff --git a/skeleton-application/module/Fieldset/src/Service/AttributeManager.php b/skeleton-application/module/Fieldset/src/Service/AttributeManager.php new file mode 100644 index 0000000..26f62f6 --- /dev/null +++ b/skeleton-application/module/Fieldset/src/Service/AttributeManager.php @@ -0,0 +1,45 @@ +attributes= $attributes; + } + + /** + * This method adds a new attribute. + */ + + public function addAttribute($data) + { + // Create new category entity. + $this->attributes[]= new Attribute($data['id'],$data['title']); + + } + + /** + * Get the list of attributes + */ + public function getAttributes() { + + $attributes= array(); + + // transform the object into an array for the select form + foreach ($this->attributes as $object) + { + $attributes[$object->getId()] = $object->getTitle(); + } + + return $attributes; + } + +} \ No newline at end of file diff --git a/skeleton-application/module/Fieldset/src/Service/CategoryManager.php b/skeleton-application/module/Fieldset/src/Service/CategoryManager.php new file mode 100644 index 0000000..986b635 --- /dev/null +++ b/skeleton-application/module/Fieldset/src/Service/CategoryManager.php @@ -0,0 +1,45 @@ +categories = $categories; + } + + /** + * This method adds a new category. + */ + + public function addCategory($data) + { + // Create new category entity. + $this->categories[]= new Category($data['id'],$data['title']); + + } + + /** + * Get the list of categories ? + */ + public function getCategories() { + + $categories = array(); + + // transform the object into an array for the select form + foreach ($this->categories as $object) + { + $categories[$object->getId()] = $object->getTitle(); + } + + return $categories; + } + +} \ No newline at end of file diff --git a/skeleton-application/module/Fieldset/view/fieldset/index/index.phtml b/skeleton-application/module/Fieldset/view/fieldset/index/index.phtml index b396dda..6139c4c 100644 --- a/skeleton-application/module/Fieldset/view/fieldset/index/index.phtml +++ b/skeleton-application/module/Fieldset/view/fieldset/index/index.phtml @@ -1,12 +1,91 @@ -

IndexController::indexAction()

form; +// now replacing formCollection : +// echo $this->formCollection($form); - $form->prepare(); + + $form->get('id')->setAttributes([ + 'class'=>'form-control', + 'placeholder'=>'01' + ]); + + $form->get('title')->setAttributes([ + 'class'=>'form-control', + 'placeholder'=>'Type a title' + ]); + + $form->get('category')->setAttributes([ + 'class'=>'form-control', + 'rows'=>2 + ]); + + $collection = $form->get('items'); + + $form->get('submit')->setAttributes(['class'=>'btn btn-primary']); + ?> - echo $this->form()->openTag($form); +

IndexController::indexAction()

- echo $this->formCollection($form); +

+ Click on the button to add new rows from fieldset +

+ form()->openTag($form); ?> +
+
- echo $this->form()->closeTag(); + +
+ formLabel($form->get('id')); ?> + formElement($form->get('id')); ?> + formElementErrors($form->get('id')); ?> +
+ +
+ formLabel($form->get('title')); ?> + formElement($form->get('title')); ?> + formElementErrors($form->get('title')); ?> +
+ +
+ formLabel($form->get('category')); ?> + formElement($form->get('category')); ?> + formElementErrors($form->get('category')); ?> +
+
+
+

+ Add row +

+ + + + + + + + + + + +
IDNAMEDESCRIPTIONATTRIBUTE
+ formCollection($collection);?> + + + formElement($form->get('submit')); ?> + form()->closeTag(); ?> + + + +$( "#add" ).click(function() { + +//var newElement = 'formElement($fieldset->get('id')); ?>'; +//newElement+= 'formElement($fieldset->get('name')); ?>'; +//newElement+= 'formElement($fieldset->get('description')); ?>'; +//newElement+= 'formElement($fieldset->get('attribute')); ?>'; + +//$( "#fieldset" ).append( $(newElement) ); + +}); + +*/