Skip to content

Commit

Permalink
Working demo at present time - removing factories , mapper...
Browse files Browse the repository at this point in the history
  • Loading branch information
eddymio committed Sep 2, 2017
1 parent 506d582 commit 630b219
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 349 deletions.
Expand Up @@ -35,9 +35,7 @@
],
'service_manager' => array(
'factories' => array(
/* 'Fieldset\Mapper\ProductMapperInterface' => 'Fieldset\Factory\ZendMapperFactory',
'Fieldset\Service\ProductServiceInterface' => 'Fieldset\Service\Factory\ProductServiceFactory'
*/

)
)
];

This file was deleted.

Expand Up @@ -9,26 +9,51 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
//use Fieldset\Service\ProductServiceInterface;

use Fieldset\Service\CategoryManager;
use Fieldset\Service\AttributeManager;

use Fieldset\Form\ProductForm;


class IndexController extends AbstractActionController
{
/* protected $productService;
protected $productForm;
public function __construct(ProductServiceInterface $productService, FormInterface $productForm)
{
$this->productService = $productService;
$this->productForm = $productForm;
}
*/


public function indexAction()
{

$form = new ProductForm();
// Add 3 categories :
$categoryManager = new CategoryManager();

$data['id'] = 1;
$data['title'] = 'Main course';

$categoryManager->addCategory($data);

$data['id'] = 2;
$data['title'] = 'Cake';

$categoryManager->addCategory($data);
$data['id'] = 3;
$data['title'] = 'Aperitif';

$categoryManager->addCategory($data);


// Add 3 attributes :
$attributeManager= new AttributeManager();
$data['id'] = 1;
$data['title'] = 'Color';

$attributeManager->addAttribute($data);

$data['id'] = 2;
$data['title'] = 'Energy';

$attributeManager->addAttribute($data);


$form = new ProductForm('product-form',null,$categoryManager,$attributeManager);

return new ViewModel(
[
Expand Down
52 changes: 49 additions & 3 deletions skeleton-application/module/Fieldset/src/Entity/Item.php
Expand Up @@ -4,15 +4,61 @@
//use RuntimeException;
//use Zend\Db\TableGateway\TableGatewayInterface;

// An item is part of a product - ex : ingredient of a recipe
class Item
{

/**
* @var int
*/
protected $id;

public function __construct()
/**
* @var string
*/
protected $name;

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

/**
* @var object refering attribute
*/
protected $attribute;


// Construct function with values
public function __construct($id = null, $name = null, $description = null , $attribute = null)
{

$this->id = $id;
$this->name = $name;
$this->description = $description;

$this->attribute = $attribute;

}



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

public function getName()
{
return $this->name;
}
public function getDescription()
{
return $this->description;
}
public function getAttribute()
{
return $this->attribute;
}


}

31 changes: 29 additions & 2 deletions skeleton-application/module/Fieldset/src/Entity/Product.php
Expand Up @@ -14,9 +14,36 @@ class Product
protected $title;

/**
* @var string
* @var object refering product category
*/
protected $text;
protected $categ;


// 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()
{
return $this->id;
}

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

public function getCateg()
{
return $this->categ;
}



}

This file was deleted.

27 changes: 22 additions & 5 deletions skeleton-application/module/Fieldset/src/Form/ItemFieldset.php
Expand Up @@ -7,7 +7,7 @@

class ItemFieldset extends Fieldset
{
public function __construct($name = null, $options = array())
public function __construct($name = null, $options = array(), $attributeManager = null)
{

parent::__construct($name, $options);
Expand All @@ -16,8 +16,9 @@ public function __construct($name = null, $options = array())
$this->setObject(new Item());

$this->add(array(
'type' => 'hidden',
'name' => 'id'
'type' => 'number',
'name' => 'id',
'options' => ['Provide a numeric ID']
));

$this->add(array(
Expand All @@ -30,10 +31,26 @@ public function __construct($name = null, $options = array())

$this->add(array(
'type' => 'text',
'name' => 'title',
'name' => 'name',
'options' => array(
'label' => 'Item Title'
'label' => 'Item name'
)
));

// Add "attribute" field
$this->add([
'type' => 'select',
'name' => 'attribute',
'attributes' => [
'id' => 'attribute',
],
'options' => [
'label' => 'Attribute',
'empty_option' => '-- Please select --',
'value_options' => $attributeManager->getAttributes()

],
]);

}
}
68 changes: 63 additions & 5 deletions skeleton-application/module/Fieldset/src/Form/ProductForm.php
Expand Up @@ -2,24 +2,82 @@
namespace Fieldset\Form;

use Zend\Form\Form;
use Fieldset\Form\ItemFieldset;

// One product is defined by a category and list of items
class ProductForm extends Form
{
public function __construct($name = null, $options = array())

/**
* Category manager.
* @var Fieldset\Service\CategoryManager
*/
private $categoryManager = null;

/**
* Attribute manager.
* @var Fieldset\Service\AttributeManager
*/
private $attributeManager = null;


public function __construct($name = null, $options = array(), $categoryManager = null, $attributeManager = null)
{

parent::__construct($name, $options);
parent::__construct($name, $options);

$this->categoryManager= $categoryManager;
$this->attributeManager= $attributeManager;


/* DETAILS about the new product*/
$this->add(array(
'type' => 'number',
'name' => 'id',
'options' => ['Provide a numeric ID']
));


$this->add(array(
'type' => 'text',
'name' => 'title',
'options' => array(
'label' => 'Product Title'
)
));

// Add "category" field
$this->add([
'type' => 'select',
'name' => 'category',
'attributes' => [
'id' => 'category',
],
'options' => [
'label' => 'Category',
'empty_option' => '-- Please select --',
'value_options' => $this->categoryManager->getCategories()

],
]);

// Fieldset for ITEM belonging to product:
/* $this->add(array(
'name' => 'item-fieldset',
'type' => 'Fieldset\Form\ItemFieldset',
'type' => 'ItemFieldset',
'options' => array(
'use_as_base_fieldset' => true
)
'use_as_base_fieldset' => true,
),
));
*/


$items = new ItemFieldset('Item-details',null,$this->attributeManager);
$this->add($items);

// Submit button :
$this->add(array(
'type' => 'submit',
'name' => 'submit',
Expand Down

0 comments on commit 630b219

Please sign in to comment.