| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright (c) 2017 Francois-Xavier Soubirou. |
||
| 4 | * |
||
| 5 | * This file is part of ci-report. |
||
| 6 | * |
||
| 7 | * ci-report is free software: you can redistribute it and/or modify |
||
| 8 | * it under the terms of the GNU General Public License as published by |
||
| 9 | * the Free Software Foundation, either version 3 of the License, or |
||
| 10 | * (at your option) any later version. |
||
| 11 | * |
||
| 12 | * ci-report is distributed in the hope that it will be useful, |
||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 15 | * GNU General Public License for more details. |
||
| 16 | * |
||
| 17 | * You should have received a copy of the GNU General Public License |
||
| 18 | * along with ci-report. If not, see <http://www.gnu.org/licenses/>. |
||
| 19 | */ |
||
| 20 | declare(strict_types=1); |
||
| 21 | |||
| 22 | namespace App\Controller; |
||
| 23 | |||
| 24 | use App\Entity\Campaign; |
||
| 25 | use App\Entity\Project; |
||
| 26 | use App\Entity\Suite; |
||
| 27 | use App\Entity\Test; |
||
| 28 | use App\Service\DocumentStorageService; |
||
| 29 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity; |
||
| 30 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
||
| 31 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
| 32 | use Symfony\Component\HttpFoundation\BinaryFileResponse; |
||
| 33 | use Symfony\Component\HttpFoundation\Response; |
||
| 34 | use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
||
| 35 | use Symfony\Component\Routing\Annotation\Route; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Suite controller class. |
||
| 39 | * |
||
| 40 | * @category ci-report app |
||
| 41 | * |
||
| 42 | * @author Francois-Xavier Soubirou <[email protected]> |
||
| 43 | * @copyright 2017 Francois-Xavier Soubirou |
||
| 44 | * @license http://www.gnu.org/licenses/ GPLv3 |
||
| 45 | * |
||
| 46 | * @see https://www.ci-report.io |
||
| 47 | */ |
||
| 48 | class SuiteController extends Controller |
||
| 49 | { |
||
| 50 | /** |
||
| 51 | * Index action. |
||
| 52 | * |
||
| 53 | * @param Project $project Project |
||
| 54 | * @param Campaign $campaign Campaign |
||
| 55 | * @param Suite $suite The suite to display |
||
| 56 | * |
||
| 57 | * @return Response A Response instance |
||
| 58 | * |
||
| 59 | * @Route( |
||
| 60 | * "/project/{prefid}/campaign/{crefid}/suite/{srefid}", |
||
| 61 | * requirements={"crefid" = "\d+", "srefid" = "\d+"}, |
||
| 62 | * name="suite-view" |
||
| 63 | * ) |
||
| 64 | * |
||
| 65 | * @ParamConverter("project", options={"mapping": {"prefid": "refid"}}) |
||
| 66 | * @Entity("campaign", expr="repository.findCampaignByProjectRefidAndRefid(prefid, crefid)") |
||
| 67 | * @Entity("suite", expr="repository.findSuiteByProjectRefidCampaignRefidAndRefid(prefid, crefid, srefid)") |
||
| 68 | */ |
||
| 69 | public function indexAction(Project $project, Campaign $campaign, Suite $suite): Response |
||
| 70 | { |
||
| 71 | $prevSuite = $this->getDoctrine() |
||
| 72 | ->getRepository(Suite::class) |
||
| 73 | ->findPrevSuiteByCampaign($campaign, $suite); |
||
| 74 | $nextSuite = $this->getDoctrine() |
||
| 75 | ->getRepository(Suite::class) |
||
| 76 | ->findNextSuiteByCampaign($campaign, $suite); |
||
| 77 | |||
| 78 | $testsList = $this->getDoctrine() |
||
| 79 | ->getRepository(Test::class) |
||
| 80 | ->findTestsBySuite($suite); |
||
| 81 | |||
| 82 | return $this->render( |
||
| 83 | 'suite/view.html.twig', |
||
| 84 | array( |
||
| 85 | 'project' => $project, |
||
| 86 | 'campaign' => $campaign, |
||
| 87 | 'suite' => $suite, |
||
| 88 | 'prevSuite' => $prevSuite, |
||
| 89 | 'nextSuite' => $nextSuite, |
||
| 90 | 'tests' => $testsList, |
||
| 91 | ) |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Download document action. |
||
| 97 | * |
||
| 98 | * @param Project $project Project |
||
| 99 | * @param Campaign $campaign Campaign |
||
| 100 | * @param Suite $suite The suite to display |
||
| 101 | * |
||
| 102 | * @return BinaryFileResponse The file to download |
||
| 103 | * |
||
| 104 | * @Route( |
||
| 105 | * "/project/{prefid}/campaign/{crefid}/suite/{srefid}/doc", |
||
| 106 | * requirements={"crefid" = "\d+", "srefid" = "\d+"}, |
||
| 107 | * name="suite-doc" |
||
| 108 | * ) |
||
| 109 | * |
||
| 110 | * @ParamConverter("project", options={"mapping": {"prefid": "refid"}}) |
||
| 111 | * @Entity("campaign", expr="repository.findCampaignByProjectRefidAndRefid(prefid, crefid)") |
||
| 112 | * @Entity("suite", expr="repository.findSuiteByProjectRefidCampaignRefidAndRefid(prefid, crefid, srefid)") |
||
| 113 | */ |
||
| 114 | public function docAction(Project $project, Campaign $campaign, Suite $suite): BinaryFileResponse |
||
| 115 | { |
||
| 116 | if (null === $suite->getDocumentUid()) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 117 | throw $this->createNotFoundException('The zip document does not exist'); |
||
| 118 | } |
||
| 119 | $docStoreService = $this->get(DocumentStorageService::class); |
||
| 120 | $filePath = $docStoreService->getFullPath( |
||
| 121 | $project, |
||
| 122 | $campaign, |
||
| 123 | $suite->getDocumentUid() |
||
| 124 | ); |
||
| 125 | $response = new BinaryFileResponse($filePath); |
||
| 126 | $response->setContentDisposition( |
||
| 127 | ResponseHeaderBag::DISPOSITION_ATTACHMENT, |
||
| 128 | 'documents.zip' |
||
| 129 | ); |
||
| 130 | $response->headers->set('Content-Type', 'application/zip'); |
||
| 131 | |||
| 132 | return $response; |
||
| 133 | } |
||
| 134 | } |
||
| 135 |