PartKeepr\PartBundle\Action\AddStockAction::__invoke PHP Method

__invoke() public method

Retrieves a collection of resources.
public __invoke ( Request $request, integer $id ) : array | Dunglas\ApiBundle\Model\PaginatorInterface | Traversable
$request Symfony\Component\HttpFoundation\Request The request
$id integer The ID of the part
return array | Dunglas\ApiBundle\Model\PaginatorInterface | Traversable
    public function __invoke(Request $request, $id)
    {
        list($resourceType) = $this->extractAttributes($request);
        $part = $this->getItem($this->dataProvider, $resourceType, $id);
        /*
         * @var $part Part
         */
        $quantity = $request->request->get('quantity');
        $user = $this->userService->getUser();
        $stock = new StockEntry();
        $stock->setUser($user);
        $stock->setStockLevel(intval($quantity));
        if ($request->request->has('price') && $request->request->get('price') !== null) {
            $stock->setPrice(floatval($request->request->get('price')));
        }
        if ($request->request->has('comment') && $request->request->get('comment') !== null) {
            $stock->setComment($request->request->get('comment'));
        }
        $part->addStockLevel($stock);
        $this->registry->getManager()->persist($stock);
        $this->registry->getManager()->flush();
        return $part;
    }