Skip to content

Commit

Permalink
playing with fieldset
Browse files Browse the repository at this point in the history
  • Loading branch information
eddymio authored and Eddy committed Sep 3, 2017
1 parent 630b219 commit 904d0ce
Show file tree
Hide file tree
Showing 15 changed files with 376 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .buildpath
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="src" path=""/>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
</buildpath>
29 changes: 29 additions & 0 deletions .project
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.dltk.core.scriptbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
16 changes: 16 additions & 0 deletions .settings/.jsdtscope
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="">
<attributes>
<attribute name="provider" value="org.eclipse.wst.jsdt.web.core.internal.project.ModuleSourcePathProvider"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.php.core.prefs
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
include_path=0;/Tests
7 changes: 7 additions & 0 deletions .settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="php.component"/>
<fixed facet="php.core.component"/>
<installed facet="php.core.component" version="1"/>
<installed facet="php.component" version="7.1"/>
</faceted-project>
1 change: 1 addition & 0 deletions .settings/org.eclipse.wst.jsdt.ui.superType.container
@@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
1 change: 1 addition & 0 deletions .settings/org.eclipse.wst.jsdt.ui.superType.name
@@ -0,0 +1 @@
Window
38 changes: 38 additions & 0 deletions skeleton-application/module/Fieldset/src/Entity/Attribute.php
@@ -0,0 +1,38 @@
<?php
namespace Fieldset\Entity;

// entity to store attributes of items - ex : ingredient is having a certain color...
class Attribute
{
/**
* @var int
*/
protected $id;

/**
* @var string
*/
protected $title;


// Construct function with values
public function __construct($id = null, $title = null)
{
$this->id = $id;
$this->title = $title;

}


public function getId()
{
return $this->id;
}

public function getTitle()
{
return $this->title;
}


}
38 changes: 38 additions & 0 deletions skeleton-application/module/Fieldset/src/Entity/Category.php
@@ -0,0 +1,38 @@
<?php
namespace Fieldset\Entity;

// entity to store categories of products
class Category
{
/**
* @var int
*/
protected $id;

/**
* @var string
*/
protected $title;


// Construct function with values
public function __construct($id = null, $title = null)
{
$this->id = $id;
$this->title = $title;

}


public function getId()
{
return $this->id;
}

public function getTitle()
{
return $this->title;
}


}
24 changes: 22 additions & 2 deletions skeleton-application/module/Fieldset/src/Entity/Product.php
Expand Up @@ -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()
Expand All @@ -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;
}

}
Expand Up @@ -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(
Expand Down
53 changes: 41 additions & 12 deletions skeleton-application/module/Fieldset/src/Form/ProductForm.php
Expand Up @@ -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
Expand Down Expand Up @@ -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']
));


Expand Down Expand Up @@ -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(
Expand Down
@@ -0,0 +1,45 @@
<?php
namespace Fieldset\Service;

use Fieldset\Entity\Attribute;
/**
* This service is responsible for adding/retrieving attributes
*/
class AttributeManager
{

protected $attributes = array();

public function __construct($attributes= null)
{
$this->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;
}

}
@@ -0,0 +1,45 @@
<?php
namespace Fieldset\Service;

use Fieldset\Entity\Category;
/**
* This service is responsible for adding/editing categories
*/
class CategoryManager
{

protected $categories = array();

public function __construct($categories = null)
{
$this->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;
}

}

0 comments on commit 904d0ce

Please sign in to comment.