partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

SystemNoticeAcknowledgeAction.php (1452B)


      1 <?php
      2 
      3 namespace PartKeepr\CoreBundle\Action;
      4 
      5 use Doctrine\ORM\EntityManager;
      6 use Dunglas\ApiBundle\Action\ActionUtilTrait;
      7 use Dunglas\ApiBundle\Exception\RuntimeException;
      8 use Dunglas\ApiBundle\Model\DataProviderInterface;
      9 use PartKeepr\CoreBundle\Entity\SystemNotice;
     10 use Symfony\Component\HttpFoundation\Request;
     11 
     12 class SystemNoticeAcknowledgeAction
     13 {
     14     use ActionUtilTrait;
     15 
     16     /**
     17      * @var DataProviderInterface
     18      */
     19     private $dataProvider;
     20 
     21     /**
     22      * @var EntityManager
     23      */
     24     private $entityManager;
     25 
     26     public function __construct(
     27         DataProviderInterface $dataProvider,
     28         EntityManager $entityManager
     29     ) {
     30         $this->dataProvider = $dataProvider;
     31         $this->entityManager = $entityManager;
     32     }
     33 
     34     /**
     35      * Sets the acknowledged flag for a system notice.
     36      *
     37      * @param Request $request The request
     38      * @param int     $id      The ID of the system notice
     39      *
     40      * @throws RuntimeException
     41      *
     42      * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
     43      */
     44     public function __invoke(Request $request, $id)
     45     {
     46         list($resourceType) = $this->extractAttributes($request);
     47 
     48         $systemNotice = $this->getItem($this->dataProvider, $resourceType, $id);
     49 
     50         /*
     51          * @var $systemNotice SystemNotice
     52          */
     53         $systemNotice->setAcknowledged();
     54 
     55         $this->entityManager->flush();
     56 
     57         return $systemNotice;
     58     }
     59 }