<?php
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/
namespace App\Twig\Extension;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Pimcore\Model\DataObject;
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Symfony\Component\Security\Core\User\UserInterface;
use App\Model\Utility;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use FrontendPermissionToolkitBundle\Service;
class UserExtension extends AbstractExtension
{
/**
* @var Factory
*/
protected $service;
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->service = new Service($eventDispatcher);
}
public function getFunctions()
{
return [
new TwigFunction('allow_user', [$this, 'allowUser']),
];
}
public function allowUser($key){
$allow = false;
if(\Pimcore::getContainer()->get('security.token_storage')->getToken()){
$userObject = \Pimcore::getContainer()->get('security.token_storage')->getToken()->getUser();
if($userObject instanceof \Pimcore\Model\DataObject){
if($this->service->isAllowed($userObject, $key)) {
$allow = true;
}
}
}
return $allow;
}
}