* improved dev fixtures with more diversity, more data, better testcases, user avatars #42 * added customer stats to dashboard, fixed column length for 3 widgets #42 * fixed empty alias - display empty message for new user #42 * unified-ui for "new" toolbar icon #42 * use kimai2_ as database prefix #42 * added customer stats to dashboard, fixed column length for 3 widgets #42 * fix long project/customer names in "currently active" navbar flyout" #42 * added services config for dev environment #42 * added command to run unit tests #42 * added command to run integration tests #42 * added command to run code sniffer #42 * added phpcs and phpunit to composer #42 * created tests directory #42 * fixed code sniffer warnings #42 * added function to switch result type from Pagerfanta to QueryBuilder #42 * dramatically reduced database calls by using custom joined query #42 * added command to install kimai dependencies #42 * added dev:reset command #42
114 lines
3.0 KiB
PHP
114 lines
3.0 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Kimai package.
|
|
*
|
|
* (c) Kevin Papst <kevin@kevinpapst.de>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace AppBundle\Controller;
|
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
/**
|
|
* The abstract base controller.
|
|
*
|
|
* @author Kevin Papst <kevin@kevinpapst.de>
|
|
*/
|
|
abstract class AbstractController extends Controller
|
|
{
|
|
const FLASH_SUCCESS = 'success';
|
|
const FLASH_WARNING = 'warning';
|
|
const FLASH_ERROR = 'error';
|
|
|
|
const DOMAIN_FLASH = 'flashmessages';
|
|
const DOMAIN_ERROR = 'exceptions';
|
|
|
|
const ROLE_ADMIN = 'ROLE_ADMIN';
|
|
|
|
/**
|
|
* @return object|\Symfony\Component\Translation\DataCollectorTranslator|\Symfony\Component\Translation\IdentityTranslator
|
|
*/
|
|
protected function getTranslator()
|
|
{
|
|
return $this->container->get('translator');
|
|
}
|
|
|
|
/**
|
|
* A translated helper for denyAccessUnlessGranted()
|
|
*
|
|
* @param $attributes
|
|
* @param null $subject
|
|
* @param string $translation
|
|
* @param array $parameter
|
|
* @throws AccessDeniedException
|
|
*/
|
|
protected function denyUnlessGranted($attributes, $subject = null, $translation = 'access.denied', $parameter = [])
|
|
{
|
|
$error = $this->getTranslator()->trans($translation, $parameter, self::DOMAIN_ERROR);
|
|
// TODO try & catch and add to audit log?
|
|
$this->denyAccessUnlessGranted($attributes, $subject, $error);
|
|
}
|
|
|
|
/**
|
|
* Adds a "successful" flash message to the stack.
|
|
*
|
|
* @param string $translationKey
|
|
* @param array $parameter
|
|
*/
|
|
protected function flashSuccess($translationKey, $parameter = [])
|
|
{
|
|
if (!empty($parameter)) {
|
|
$translationKey = $this->getTranslator()->trans(
|
|
$translationKey,
|
|
$parameter,
|
|
self::DOMAIN_FLASH
|
|
);
|
|
}
|
|
|
|
$this->addFlash(self::FLASH_SUCCESS, $translationKey);
|
|
}
|
|
|
|
/**
|
|
* Adds a "warning" flash message to the stack.
|
|
*
|
|
* @param $translationKey
|
|
* @param array $parameter
|
|
*/
|
|
protected function flashWarning($translationKey, $parameter = [])
|
|
{
|
|
if (!empty($parameter)) {
|
|
$translationKey = $this->getTranslator()->trans(
|
|
$translationKey,
|
|
$parameter,
|
|
self::DOMAIN_FLASH
|
|
);
|
|
}
|
|
|
|
$this->addFlash(self::FLASH_WARNING, $translationKey);
|
|
}
|
|
|
|
/**
|
|
* Adds a "error" flash message to the stack.
|
|
*
|
|
* @param $translationKey
|
|
* @param array $parameter
|
|
*/
|
|
protected function flashError($translationKey, $parameter = [])
|
|
{
|
|
if (!empty($parameter)) {
|
|
$translationKey = $this->getTranslator()->trans(
|
|
$translationKey,
|
|
$parameter,
|
|
self::DOMAIN_FLASH
|
|
);
|
|
}
|
|
|
|
$this->addFlash(self::FLASH_ERROR, $translationKey);
|
|
}
|
|
}
|