54 lines
974 B
PHP
54 lines
974 B
PHP
<?php
|
|
|
|
namespace AppBundle\Model;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
|
|
/**
|
|
* Class Cart
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
class Cart
|
|
{
|
|
protected $prestations = [];
|
|
|
|
protected $session;
|
|
|
|
public function __construct(Session $session)
|
|
{
|
|
$this->session = $session;
|
|
|
|
$sessionCart = $this->session->get('cart');
|
|
|
|
if ($sessionCart !== null) {
|
|
$this->setPrestations($sessionCart->getPrestations());
|
|
}
|
|
}
|
|
|
|
public function addPrestation($id)
|
|
{
|
|
if (!in_array($id, $this->prestations)) {
|
|
$this->prestations[] = $id;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPrestations()
|
|
{
|
|
return $this->prestations;
|
|
}
|
|
|
|
public function setPrestations(array $prestations)
|
|
{
|
|
$this->prestations = $prestations;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
$this->session->set('cart', $this);
|
|
}
|
|
}
|