src/Controller/HomepageController.php line 85

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
  4.  *
  5.  * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU Affero General Public License as published
  9.  * by the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program 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 Affero General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Affero General Public License
  18.  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  19.  */
  20. declare(strict_types=1);
  21. /**
  22.  * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
  23.  *
  24.  * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
  25.  *
  26.  * This program is free software; you can redistribute it and/or
  27.  * modify it under the terms of the GNU General Public License
  28.  * as published by the Free Software Foundation; either version 2
  29.  * of the License, or (at your option) any later version.
  30.  *
  31.  * This program is distributed in the hope that it will be useful,
  32.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  34.  * GNU General Public License for more details.
  35.  *
  36.  * You should have received a copy of the GNU General Public License
  37.  * along with this program; if not, write to the Free Software
  38.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  39.  */
  40. namespace App\Controller;
  41. use App\DataTables\LogDataTable;
  42. use App\Services\GitVersionInfo;
  43. use const DIRECTORY_SEPARATOR;
  44. use Omines\DataTablesBundle\DataTableFactory;
  45. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  46. use Symfony\Component\HttpFoundation\Request;
  47. use Symfony\Component\HttpFoundation\Response;
  48. use Symfony\Component\HttpKernel\KernelInterface;
  49. use Symfony\Component\Routing\Annotation\Route;
  50. use Symfony\Contracts\Cache\CacheInterface;
  51. class HomepageController extends AbstractController
  52. {
  53.     protected $cache;
  54.     protected $kernel;
  55.     protected $dataTable;
  56.     public function __construct(CacheInterface $cacheKernelInterface $kernelDataTableFactory $dataTable)
  57.     {
  58.         $this->cache $cache;
  59.         $this->kernel $kernel;
  60.         $this->dataTable $dataTable;
  61.     }
  62.     public function getBanner(): string
  63.     {
  64.         $banner $this->getParameter('partdb.banner');
  65.         if (empty($banner)) {
  66.             $banner_path $this->kernel->getProjectDir()
  67.                 .DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'banner.md';
  68.             return file_get_contents($banner_path);
  69.         }
  70.         return $banner;
  71.     }
  72.     /**
  73.      * @Route("/", name="homepage")
  74.      */
  75.     public function homepage(Request $requestGitVersionInfo $versionInfo): Response
  76.     {
  77.         if ($this->isGranted('@tools.lastActivity')) {
  78.             $table $this->dataTable->createFromType(
  79.                 LogDataTable::class,
  80.                 [
  81.                     'mode' => 'last_activity',
  82.                 ],
  83.                 ['pageLength' => 10]
  84.             )
  85.                 ->handleRequest($request);
  86.             if ($table->isCallback()) {
  87.                 return $table->getResponse();
  88.             }
  89.         } else {
  90.             $table null;
  91.         }
  92.         return $this->render('homepage.html.twig', [
  93.             'banner' => $this->getBanner(),
  94.             'git_branch' => $versionInfo->getGitBranchName(),
  95.             'git_commit' => $versionInfo->getGitCommitHash(),
  96.             'datatable' => $table,
  97.         ]);
  98.     }
  99. }