I'm building a computer configurator and got four entities.
- Customer(not relevant)
- Computer(id, customer, serial, date, [components])
- ArticleGroup(id, name)
- Article(id, name, price, articleGroup, active)
The attribute [components] of the Computer entity should contain an array like this:
$components = array(
'CPU' => array(
'name' => 'Intel Core i7',
'count' => 1,
'price' => 275),
'Mainboard' => array(
'name' => 'Gigabyte H97-D3H',
'count' => 1,
'price' => 75),
'RAM' => array(
'name' => '4GB DDRIII Kingston Value Ram',
'count' => 4,
'price' => 28),
'SSD' => array(
'name' => '512GB Samsung 850 Pro',
'count' => 1,
'price' => 400)
);
The array key price maybe differs from the price of the article entity.(Because of daily prices for hardware or because i think that this customer gets the cpu for less money)
Now the question I don't know how to create this components array collection.
This is my Computer entity:
<?php
namespace ctcrm\ConfiguratorBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Computer
*
* @ORM\Table()
* @ORM\Entity
*/
class Computer
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
* @Assert\NotBlank()
* @Assert\Length(
* min = 12,
* max = 12,
* minMessage = "no valid serial!",
* maxMessage = "no valid serial!"
* )
* @ORM\Column(name="serial", type="string", length=12)
*/
private $serial;
/**
* @var \DateTime
* @Assert\NotBlank()
* @ORM\Column(name="date", type="date")
*/
private $date;
/**
* @ORM\ManyToOne(targetEntity="Customer")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
* @Assert\NotBlank()
**/
private $customer;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set serial
*
* @param string $serial
* @return Computer
*/
public function setSerial($serial)
{
$this->serial = $serial;
return $this;
}
/**
* Get serial
*
* @return string
*/
public function getSerial()
{
return $this->serial;
}
/**
* Set date
*
* @param \DateTime $date
* @return Computer
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* @return mixed
*/
public function getCustomer()
{
return $this->customer;
}
/**
* @param mixed $customer
*/
public function setCustomer($customer)
{
$this->customer = $customer;
}
}