<?php
namespace Claromentis\Quiz\Permissions;

$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] ?: array()) + array("_3f6d7d23d9702fbd8e06b755c2e7b3" . "e0" => base64_decode("cXVpei5wZXJtaXNzaW" . "9ucy52aWV3X2FsbF9z" . "dGF0aXN0aWNz"), "_30deb384dbcd91" . "3f0628cb00c05ed" . "68b" => base64_decode("cXVpei5hZG1pbi5ub19jcmVhdGVfcGVy" . "bXM="), "_aa46d3ae56040972fac37aa9" . "bc87d803" => base64_decode("L3F1aX" . "o="), "_ada909094c3f" . "2b48f2ba66bec" . "3334aab" => base64_decode("cXVpei5mYWNhZG" . "UucXVpeg=="), "qui" . "z_i" . "d" => base64_decode("cXV" . "pel" . "9pZ" . "A=="), "_ce97e83d884f0f0c436" . "62999ffef59ed" => base64_decode("cXVpei5wZXJtaXNzaW9ucy5tYW5" . "hZ2VfYWxs"), "_0c5123aa744f69bbc0e8b3ea2f6e847" . "d" => base64_decode("bG" . "1z" . "Zw" . "=="), "_38f12d8b8c719a8ce0fc2fa" . "efc225f35" => base64_decode("YXJyYXlfbW" . "Fw"), "_74c5ab07fa214" . "8370c1d2c55ebd" . "af3ab" => base64_decode("cXVpei5hZG1pbi5ub" . "19wZXJtcw=="), "_261fbffc46a1394955b10c01bdd9" . "6d03" => base64_decode("cXVpei5yZXBvc" . "2l0b3J5LnF1aX" . "o="), "_62df08b6ed8667f8174a96d58970883" . "d" => base64_decode("aW50dm" . "Fs"), "_97f0dd166c14320c43b6fc" . "77c283e27e" => base64_decode("cXVpei5wZXJtaXNzaW9ucy5tYW5" . "hZ2Vfb3du"));
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["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0c5123aa744f69" . "bbc0e8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_3f6d7d23d9702fbd8" . "e06b755c2e7b3e0"]), 1), static::PERM_MANAGE_OWN => array($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d"]($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_97f0dd166c14320" . "c43b6fc77c283e27" . "e"]), 1), static::PERM_MANAGE_ALL => array($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_0c5123aa744f69" . "bbc0e8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_ce97e83d884f0f0c4366299" . "9ffef59ed"]), 1));
    }
    
    
    
    
    
    
    
    
    public static function GetUsersWhoCan(Acl\AclRepository $_8652ba33e6ffeba02459fa9cbb320851, $_a48eb1db4f6ab2c82fb9db687c5f4a32)
    {
        $acl = $_8652ba33e6ffeba02459fa9cbb320851->Get(static::CLASS_QUIZ_ADMIN, 1);
        return $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_38f12d8b8c719a8ce0fc2faefc225f" . "35"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_62df08b6ed8667f" . "8174a96d58970883" . "d"], $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["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["qu" . "iz" . "_i" . "d"])) {
            $quiz_id = $request->attributes->get($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["quiz" . "_id"]);
        }
        
        
        if (!$quiz_id) {
            
            
            if (static::CanCreate($_6eb6fcb92c942851e079f8ec5fb80324->acl, $_6eb6fcb92c942851e079f8ec5fb80324->security)) {
                return null;
            } else {
                return RedirectResponse::httpRedirect($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_aa46d3a" . "e5604097" . "2fac37aa" . "9bc87d80" . "3"], $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0c5123aa744f69bbc" . "0e8b3ea2f6e847d"]($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_30deb384dbcd9" . "13f0628cb00c05" . "ed68b"]));
            }
        }
        
        
        
        
        
        $_864ec8f1fa467c206b6bb2b9c0f308bf = $_6eb6fcb92c942851e079f8ec5fb80324[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_261fbffc46" . "a1394955b10" . "c01bdd96d03"]];
        $_876ca2097b275e704d71e00d36b3e7c5 = $_6eb6fcb92c942851e079f8ec5fb80324[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_ada909094c" . "3f2b48f2ba6" . "6bec3334aab"]];
        $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["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_aa46d3ae" . "56040972f" . "ac37aa9bc" . "87d803"], $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_0c5123aa744f69bbc0e8b3ea" . "2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_74c5ab07fa2148370c1d" . "2c55ebdaf3ab"]), true);
    }
}