<?php
namespace Claromentis\Quiz\Permissions;

$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] ?: array()) + array("_38f12d8b8c719a8ce0fc2faefc225" . "f35" => base64_decode("YXJyYXlf" . "bWFw"), "qui" . "z_i" . "d" => base64_decode("cXV" . "pel" . "9pZ" . "A=="), "_aa46d3ae56040972fac37a" . "a9bc87d803" => base64_decode("L3F1a" . "Xo="), "_97f0dd166c14320c43b6fc77c283" . "e27e" => base64_decode("cXVpei5wZXJtaXNzaW9ucy5tY" . "W5hZ2Vfb3du"), "_74c5ab07fa2148370" . "c1d2c55ebdaf3ab" => base64_decode("cXVpei5hZG1p" . "bi5ub19wZXJt" . "cw=="), "_62df08b6ed8667f8174a9" . "6d58970883d" => base64_decode("aW" . "50" . "dm" . "Fs"), "_30deb384dbcd91" . "3f0628cb00c05ed" . "68b" => base64_decode("cXVpei5hZG1pbi5ub19jcmVhdGVfc" . "GVybXM="), "_ce97e83d884f0f0c43" . "662999ffef59ed" => base64_decode("cXVpei5wZXJ" . "taXNzaW9ucy" . "5tYW5hZ2VfY" . "Wxs"), "_0c5123aa744f69" . "bbc0e8b3ea2f6e8" . "47d" => base64_decode("bG1zZw" . "=="), "_261fbffc46a1394955b10c0" . "1bdd96d03" => base64_decode("cXVpei5yZXB" . "vc2l0b3J5Ln" . "F1aXo="), "_ada909094c3f2b48" . "f2ba66bec3334aab" => base64_decode("cXVpei5mYWN" . "hZGUucXVpeg" . "=="), "_3f6d7d23d9702fbd8e06b755c2e7b" . "3e0" => base64_decode("cXVpei5wZXJtaXNzaW9ucy52aWV3X2FsbF9zdGF0aXN0a" . "WNz"));
use Claromentis\Core\Application;
use Claromentis\Core\Acl;
use Claromentis\Core\Http\SymfonyRequest;
use Claromentis\Core\Http\RedirectResponse;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Quiz\Model;






class QuizAdminPermissions
{
    
    
    const CLASS_QUIZ_ADMIN = 130;
    
    
    const PERM_VIEW_ALL_STATISTICS = 0x100;
    const PERM_MANAGE_OWN = 0x10;
    const PERM_MANAGE_ALL = 0x111;
    
    
    
    
    
    
    
    public static function GetDialog(Acl\AclRepository $acl)
    {
        $acl = $acl->Get(static::CLASS_QUIZ_ADMIN, 1);
        $_199355a18b7f1825de748a3bdea73bdb = new Acl\CommonPermsDialog($acl);
        $_199355a18b7f1825de748a3bdea73bdb->SetAllPermValues(static::GetDialogValues());
        return $_199355a18b7f1825de748a3bdea73bdb;
    }
    
    
    
    
    
    
    public static function GetDialogValues()
    {
        return array(static::PERM_VIEW_ALL_STATISTICS => array($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_0c5123aa744f69bbc0e8b3e" . "a2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_3f6d7d23d9702fbd8e06b755c2" . "e7b3e0"]), 1), static::PERM_MANAGE_OWN => array($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_0c5123aa744f69bbc0e8b3" . "ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_97f0dd166c14320c43b6f" . "c77c283e27e"]), 1), static::PERM_MANAGE_ALL => array($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_0c5123aa744f69bbc0e8b3ea" . "2f6e847d"]($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_ce97e83d884f0f0c43662999ffef5" . "9ed"]), 1));
    }
    
    
    
    
    
    
    
    
    public static function GetUsersWhoCan(Acl\AclRepository $_8652ba33e6ffeba02459fa9cbb320851, $_a48eb1db4f6ab2c82fb9db687c5f4a32)
    {
        $acl = $_8652ba33e6ffeba02459fa9cbb320851->Get(static::CLASS_QUIZ_ADMIN, 1);
        return $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_38f12d8" . "b8c719a8" . "ce0fc2fa" . "efc225f3" . "5"]($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_62df08b6ed8667f8174a96d5897" . "0883d"], $acl->GetIndividualsList($_a48eb1db4f6ab2c82fb9db687c5f4a32));
    }
    
    
    
    
    
    
    
    
    public static function CanCreate(Acl\AclRepository $_8652ba33e6ffeba02459fa9cbb320851, SecurityContext $context)
    {
        $acl = $_8652ba33e6ffeba02459fa9cbb320851->Get(static::CLASS_QUIZ_ADMIN, 1);
        
        
        return $acl->Permits($context, static::PERM_MANAGE_OWN) || $acl->Permits($context, static::PERM_MANAGE_ALL);
    }
    
    
    
    
    
    
    
    
    public static function CanManageOwn(Acl\AclRepository $_8652ba33e6ffeba02459fa9cbb320851, SecurityContext $context)
    {
        $acl = $_8652ba33e6ffeba02459fa9cbb320851->Get(static::CLASS_QUIZ_ADMIN, 1);
        return $acl->Permits($context, static::PERM_MANAGE_OWN);
    }
    
    
    
    
    
    
    
    
    public static function CanManageAll(Acl\AclRepository $_8652ba33e6ffeba02459fa9cbb320851, SecurityContext $context)
    {
        $acl = $_8652ba33e6ffeba02459fa9cbb320851->Get(static::CLASS_QUIZ_ADMIN, 1);
        return $acl->Permits($context, static::PERM_MANAGE_ALL);
    }
    
    
    
    
    
    
    
    
    public static function CanViewAllStatistics(Acl\AclRepository $_8652ba33e6ffeba02459fa9cbb320851, SecurityContext $context)
    {
        
        
        if (static::CanManageAll($_8652ba33e6ffeba02459fa9cbb320851, $context)) {
            return true;
        }
        $acl = $_8652ba33e6ffeba02459fa9cbb320851->Get(static::CLASS_QUIZ_ADMIN, 1);
        return $acl->Permits($context, static::PERM_VIEW_ALL_STATISTICS);
    }
    
    
    
    
    
    
    
    
    public static function CanViewAll(Acl\AclRepository $_8652ba33e6ffeba02459fa9cbb320851, SecurityContext $context)
    {
        return static::CanManageAll($_8652ba33e6ffeba02459fa9cbb320851, $context) || static::CanViewAllStatistics($_8652ba33e6ffeba02459fa9cbb320851, $context);
    }
    
    
    
    
    
    
    
    
    public static function CanAttemptAll(Acl\AclRepository $_8652ba33e6ffeba02459fa9cbb320851, SecurityContext $context)
    {
        return static::CanManageAll($_8652ba33e6ffeba02459fa9cbb320851, $context);
    }
    
    
    
    
    
    
    
    public static function BeforeHook(SymfonyRequest $request, Application $_6eb6fcb92c942851e079f8ec5fb80324)
    {
        
        
        if (static::CanManageAll($_6eb6fcb92c942851e079f8ec5fb80324->acl, $_6eb6fcb92c942851e079f8ec5fb80324->security)) {
            return null;
        }
        $quiz_id = 0;
        
        
        if ($request->attributes->has($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["qu" . "iz" . "_i" . "d"])) {
            $quiz_id = $request->attributes->get($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["quiz_i" . "d"]);
        }
        
        
        if (!$quiz_id) {
            
            
            if (static::CanCreate($_6eb6fcb92c942851e079f8ec5fb80324->acl, $_6eb6fcb92c942851e079f8ec5fb80324->security)) {
                return null;
            } else {
                return RedirectResponse::httpRedirect($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_aa46d3ae56040972fac3" . "7aa9bc87d803"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_0c5123aa744f69bbc0e8b3ea" . "2f6e847d"]($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_30deb384dbcd913f0628cb00" . "c05ed68b"]));
            }
        }
        
        
        
        
        
        $_864ec8f1fa467c206b6bb2b9c0f308bf = $_6eb6fcb92c942851e079f8ec5fb80324[$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_261fbffc46a1394955b10c01bdd96" . "d03"]];
        $_876ca2097b275e704d71e00d36b3e7c5 = $_6eb6fcb92c942851e079f8ec5fb80324[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_ada909094c3f2b4" . "8f2ba66bec3334aa" . "b"]];
        $quiz = $_864ec8f1fa467c206b6bb2b9c0f308bf->GetOrNew($quiz_id);
        $quiz->SetQuestions($_876ca2097b275e704d71e00d36b3e7c5->GetQuestionsForQuiz($quiz));
        $_238d2e692acf9c393aea4c12eda04a3d = QuizPermissions::CanManage($_6eb6fcb92c942851e079f8ec5fb80324->acl, $_6eb6fcb92c942851e079f8ec5fb80324->security, $quiz);
        
        
        if ($_238d2e692acf9c393aea4c12eda04a3d) {
            return null;
        }
        return RedirectResponse::httpRedirect($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_aa46d3ae56040" . "972fac37aa9bc8" . "7d803"], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d"]($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_74c5ab07fa2148370c" . "1d2c55ebdaf3ab"]), true);
    }
}