-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemService.php
50 lines (42 loc) · 1.19 KB
/
ItemService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace AppBundle\Services;
use Doctrine\ORM\EntityManager;
use AppBundle\Entity\State;
use AppBundle\Entity\Item;
use AppBundle\Entity\Forder;
use Symfony\Component\Config\Definition\Exception\Exception;
use AppBundle\Utils\Traits\ServiceDataPersistenceTrait;
class ItemService
{
protected $entityManager;
protected $user;
use ServiceDataPersistenceTrait;
/**
* Item Service constructor.
*
* @param EntityManager $entityManager
* @param $user represents the current user
*/
public function __construct(EntityManager $entityManager, $user)
{
$this->entityManager = $entityManager;
$this->user = $user;
}
/**
* Creates a new item iside an order
*
* @param Item $item
* @param Forder $forder
*
* @throws exception if order state is not active
*/
public function create(Item $item, Forder $forder)
{
if ($forder->getState()->getID() != State::ACTIVE){
throw new Exception("Your Item {$item->getName()} was not add, This order doesn't recieve more items!!");
}
$item->setForder($forder);
$item->setUser($this->user);
$this->save($item);
}
}