2020-04-24 22:10:49 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
|
2020-04-26 18:59:49 +02:00
|
|
|
use App\Services\LabelSystem\BarcodeParser;
|
|
|
|
use Doctrine\ORM\EntityNotFoundException;
|
2020-04-24 22:10:49 +02:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/scan")
|
|
|
|
* @package App\Controller
|
|
|
|
*/
|
|
|
|
class ScanController extends AbstractController
|
|
|
|
{
|
2020-04-26 18:59:49 +02:00
|
|
|
protected $barcodeParser;
|
|
|
|
|
|
|
|
public function __construct(BarcodeParser $barcodeParser)
|
|
|
|
{
|
|
|
|
$this->barcodeParser = $barcodeParser;
|
|
|
|
}
|
|
|
|
|
2020-04-24 22:10:49 +02:00
|
|
|
/**
|
2020-04-26 18:59:49 +02:00
|
|
|
* The route definition for this action is done in routes.yaml, as it does not use the _locale prefix as the other routes
|
2020-04-24 22:10:49 +02:00
|
|
|
* @param string $type
|
|
|
|
* @param int $id
|
|
|
|
*/
|
|
|
|
public function scanQRCode(string $type, int $id)
|
|
|
|
{
|
2020-04-26 18:59:49 +02:00
|
|
|
try {
|
|
|
|
$this->addFlash('success', 'scan.qr_success');
|
|
|
|
return $this->redirect($this->barcodeParser->getQRRedirectTarget($type, $id));
|
|
|
|
} catch (EntityNotFoundException $exception) {
|
|
|
|
$this->addFlash('success', 'scan.qr_not_found');
|
|
|
|
return $this->redirectToRoute('homepage');
|
|
|
|
}
|
2020-04-24 22:10:49 +02:00
|
|
|
}
|
|
|
|
}
|