<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Controller\AppBundle\Interact\Compare\Cart;
/**
* Offer cart, to convert back to a cast when needed.
*/
#[ORM\Table(name: 'offerte_cart')]
#[ORM\Entity(repositoryClass: 'App\Repository\OfferteCartRepository')]
class OfferteCart
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
public $id;
/**
* @var string
*/
#[ORM\Column(name: 'cart', type: 'text')]
private $cart;
/**
* @var array
*/
#[ORM\OneToMany(targetEntity: 'App\Entity\OfferteCartRow', mappedBy: 'cart', cascade: ['persist', 'remove'])]
public $processes;
/**
* @var string
*/
#[ORM\Column(name: 'anva_key', type: 'text')]
public $anvaKey;
public function __construct($cart, $processes = []) {
/** @var Cart $cart */
$this->setCart($cart);
$this->processes = $processes;
}
public function setProcesses($processes) {
$this->processes = $processes;
}
public function addProcess($process) {
$this->processes[] = $process;
}
public function setCart($cart) {
$this->cart = serialize($cart);
}
/**
* @return Cart
*/
public function getCart() {
return unserialize($this->cart);
}
public function processContainer($datasource) {
$processes = [];
$loop = $this->processes;
foreach ($loop as $processContainer) {
$processes[] = $processContainer->getProcess();
}
return $this->getCart()->processCartDB($processes, $datasource);
}
public function expireDate()
{
$expireDate = null;
foreach ($this->processes as $row) {
$process = $row->getProcess();
if (!$expireDate || $process->expireDate() < $expireDate) {
$expireDate = $process->expireDate();
}
}
return $expireDate;
}
}