<?php
namespace Claromentis\Design\Model;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"] ?: array()) + array("_a591754a8ddcdbda9c80f1db4d" . "911e14" => base64_decode("aXNfbnVsb" . "A=="), "_9c098e136" . "f02f78824b" . "e9e6ef30ae" . "df6" => base64_decode("dG" . "hl" . "bW" . "Uv"), "_7681c2a2b7e1bdf69" . "c23c6cd64114ad3" => base64_decode("anNvbl9kZ" . "WNvZGU="), "_28fd57f750dbb5ffb3ffad3a8" . "88358a9" => base64_decode("ZGVzY3JpcHRpb2" . "4="), "_d155d43a" . "39de93f85" . "8123c6b6c" . "e31d8a" => base64_decode("cHJlZ19tYX" . "RjaA=="), "pr" . "io" . "ri" . "ty" => base64_decode("cHJpb3" . "JpdHk="), "_aed8da0f19" . "091214b78f8" . "0351048517c" => base64_decode("c3Ryb" . "GVu"), "_7123746" . "53fde8c4" . "8615c6bf" . "1c3f0382" . "b" => base64_decode("YmFzZ" . "V92aQ" . "=="), "_a134f3cd119ce7ca64988" . "8c0926d12aa" => base64_decode("ZGVzaWduLmFkZC5ub190aXRs" . "ZQ=="), "c" . "o" . "d" . "e" => base64_decode("Y29" . "kZQ" . "=="), "_0c5123aa7" . "44f69bbc0e" . "8b3ea2f6e8" . "47d" => base64_decode("bG1z" . "Zw=="), "_ec5506f22f4380697838" . "f5559d75d370" => base64_decode("c3" . "R5" . "bG" . "U="), "_40434e3a21b1e9b323ebc53" . "06a5f9ab6" => base64_decode("ZGVzaWduLnZhbGlkYXRpb24uaW52YWxpZF9ob21lcGFnZ" . "Q=="), "_7f628626dd1d55c71" . "b1fc0932ffd1d2c" => base64_decode("aXNfYXJyYX" . "k="), "_9f3dfe54b" . "03f12e1e3a" . "61cd8ff365" . "f38" => base64_decode("L15bXGRcd" . "11bXGRcd1" . "9dKiQv"), "the" . "me" => base64_decode("dGhlbW" . "U="), "_87daa84e346f6420a3f3426e05d16a7" . "b" => base64_decode("L" . "w" . "=" . "="), "_7aefd482de7885f4293c2926df28" . "c235" => base64_decode("anNv" . "bl9l" . "bmNv" . "ZGU="), "t" . "i" . "t" . "l" . "e" => base64_decode("dGl0bGU" . "="), "_6ce7d901335e" . "bcd423ce22e3a" . "4e6eabe" => base64_decode("VGhlbWUgY29kZSB" . "pcyBpbnZhbGlk"), "_4d707fab93bebb00bbe69e8" . "159697c90" => base64_decode(""), "i" . "d" => base64_decode("aW" . "Q="), "_7c7c9c63e1edfaf2a33ddf2c785e" . "6a4a" => base64_decode("cGFnZXNf" . "dXJsX2lk"), "de" . "fa" . "ul" . "t" => base64_decode("ZGVmYXVs" . "dA=="));
use Claromentis\Core\Acl\Acl;
use Claromentis\Core\Repository\RepositoryItemAbstract;
use Claromentis\Design\Exception\ThemeValidationException;
use Claromentis\Design\Facade\AssetsStorage;
use Claromentis\Design\Style;
use Claromentis\Design\Style\StyleOptionsEditable;
use Claromentis\Design\ThemeAcl;
use Claromentis\Design\View\LayoutSelect;
use ObjectsStorage;











class Theme extends RepositoryItemAbstract implements Style\StorageInterface
{
    public $page_title;
    public $page_url;
    public $permissions = [];
    public $forced_permissions = [];
    
    
    
    
    protected $unsaved_style;
    
    
    
    
    protected $unsaved_thumbnail;
    const THUMBNAIL_NAME = 'screenshot.jpg';
    const DEFAULT_THUMBNAIL_URL = '/intranet/design/images/nothemeimage.png';
    protected $acl_view;
    protected $acl_forced;
    public function __construct($theme_id = 0)
    {
        $this->LoadFromArray([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["i" . "d"] => $theme_id, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["ti" . "tl" . "e"] => $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_4d707fab93bebb0" . "0bbe69e8159697c9" . "0"], $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_28fd57f750dbb5f" . "fb3ffad3a888358a" . "9"] => $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_4d707fab93bebb00bbe69e8159697c9" . "0"], $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["prior" . "ity"] => 0, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_712374653fde8c48615c" . "6bf1c3f0382b"] => $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_4d707fab9" . "3bebb00bbe" . "69e8159697" . "c90"], $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_ec5506f22f438" . "0697838f5559d7" . "5d370"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_4d707fab93bebb00bbe" . "69e8159697c90"], $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_7c7c9c63e1edfaf2a33ddf2c7" . "85e6a4a"] => LayoutSelect::LAYOUT_DEFAULT]);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function InitDbMapping(ObjectsStorage $storage)
    {
        $storage->MapDbTable($this, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["t" . "h" . "e" . "m" . "e"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["i" . "d"]);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["i" . "d"], ObjectsStorage::T_AUTOINCREMENT);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["ti" . "tl" . "e"], ObjectsStorage::T_STRING, 255);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_28fd57f750dbb5ffb3f" . "fad3a888358a9"], ObjectsStorage::T_STRING, 4000);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["priorit" . "y"], ObjectsStorage::T_INT);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_712374653fde8c48615c6" . "bf1c3f0382b"], ObjectsStorage::T_STRING, 128);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_ec5506f22f43806978" . "38f5559d75d370"], ObjectsStorage::T_CLOB);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["cod" . "e"], ObjectsStorage::T_STRING, 128);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_7c7c9c63e1edfaf2a33d" . "df2c785e6a4a"], ObjectsStorage::T_INT);
    }
    public function SetHomepageInfo($title, $url)
    {
        $this->page_title = $title;
        $this->page_url = $url;
    }
    
    
    
    
    
    
    
    public function GetCode() : ?string
    {
        return $this->GetProperty($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["cod" . "e"]);
    }
    public function SetPagesUrlId(int $_7c7c9c63e1edfaf2a33ddf2c785e6a4a)
    {
        if ($_7c7c9c63e1edfaf2a33ddf2c785e6a4a === -1) {
            throw new ThemeValidationException($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_0c5123aa744f69bbc0e8b3ea2f6e" . "847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_40434e3a21b1e9" . "b323ebc5306a5f9" . "ab6"]));
        }
        $this->SetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_7c7c9c63e1edfaf2a33d" . "df2c785e6a4a"], $_7c7c9c63e1edfaf2a33ddf2c785e6a4a);
    }
    public function SetDescription($_715e469f808de3770b824865fc09869b)
    {
        $this->SetProperty($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_28fd57f750dbb5ffb3ffad3a" . "888358a9"], $_715e469f808de3770b824865fc09869b);
    }
    
    
    
    
    
    public function Validate()
    {
        if ($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_aed8da0f19091214b78f80351048517" . "c"]($this->title) === 0) {
            throw new ThemeValidationException($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_0c5123aa744f69" . "bbc0e8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_a134f3cd119" . "ce7ca649888c" . "0926d12aa"]));
        }
        if (empty($this->code)) {
            $this->SetCode($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["them" . "e"] . \CryptUtils::GetRandomStringShort());
        }
        if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_d155d43a39de93f85" . "8123c6b6ce31d8a"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_9f3dfe54" . "b03f12e1e" . "3a61cd8ff" . "365f38"], $this->GetCode())) {
            throw new ThemeValidationException($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_6ce7d9013" . "35ebcd423c" . "e22e3a4e6e" . "abe"]);
        }
    }
    public function SetTitle($title)
    {
        $this->SetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["titl" . "e"], $title);
    }
    public function SetPriority($priority)
    {
        $this->SetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["pr" . "io" . "ri" . "ty"], $priority);
    }
    public function SetStyleData($_84d500397774ffc43285a9279264dd01)
    {
        $_8695ec55135fd1a9bf256143a5a9d8bd = @$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_7aefd482d" . "e7885f4293" . "c2926df28c" . "235"]($_84d500397774ffc43285a9279264dd01);
        $this->SetProperty($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_ec5506f2" . "2f4380697" . "838f5559d" . "75d370"], $_8695ec55135fd1a9bf256143a5a9d8bd);
    }
    public function SetStyle(StyleOptionsEditable $_d1d1a9612601fe4d8601baddf3d108e5 = null)
    {
        $this->unsaved_style = $_d1d1a9612601fe4d8601baddf3d108e5;
    }
    public function SetPermissions($_5630a508eaf62fdbab410362fa17735c)
    {
        $this->permissions = $_5630a508eaf62fdbab410362fa17735c;
    }
    public function SetForcedPermissions($_a8f860f4f895ba3e90034bea63127d5c)
    {
        $this->forced_permissions = $_a8f860f4f895ba3e90034bea63127d5c;
    }
    public function SetBaseVi($_fd1bf86f550cd42b6eb53052641a980a)
    {
        if ($_fd1bf86f550cd42b6eb53052641a980a == $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_4d707fab93bebb00bbe6" . "9e8159697c90"]) {
            $_fd1bf86f550cd42b6eb53052641a980a = null;
        }
        $this->SetProperty($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_712374653fd" . "e8c48615c6bf" . "1c3f0382b"], $_fd1bf86f550cd42b6eb53052641a980a);
    }
    public function IsCustomVi()
    {
        return $this->base_vi != $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_4d707fab93bebb00bbe69e" . "8159697c90"] && $this->base_vi !== $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["def" . "aul" . "t"];
    }
    public function SaveAssets(AssetsStorage $storage)
    {
        if ($this->unsaved_style) {
            $this->unsaved_style->SaveAssets($storage);
            
            
            $_84d500397774ffc43285a9279264dd01 = $this->unsaved_style->GetAllOwn();
            unset($_84d500397774ffc43285a9279264dd01[Style\Option::PAGE_BG_IMAGE]);
            unset($_84d500397774ffc43285a9279264dd01[Style\Option::LOGO_URL]);
            unset($_84d500397774ffc43285a9279264dd01[Style\Option::FAVICON]);
            $this->SetStyleData($_84d500397774ffc43285a9279264dd01);
            $this->unsaved_style = null;
        }
        if ($this->unsaved_thumbnail !== null) {
            if ($this->unsaved_thumbnail === $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_4d707fab93bebb00bbe" . "69e8159697c90"]) {
                $storage->DeleteFile(self::THUMBNAIL_NAME);
            } else {
                $storage->AddFile($this->unsaved_thumbnail, self::THUMBNAIL_NAME);
            }
            $this->unsaved_thumbnail = null;
        }
    }
    public function SaveAcl(ThemeAcl $_11fd0c43f9c6d4cceb91b12c0a8bb755)
    {
        if (!$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_a591754a8ddcdbd" . "a9c80f1db4d911e1" . "4"]($this->acl_view)) {
            $this->acl_view = $_11fd0c43f9c6d4cceb91b12c0a8bb755->SetThemeAcl($this->id, $this->acl_view);
        }
        if (!$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_a591754a8ddcdbda9c80f1db4d911e" . "14"]($this->acl_forced)) {
            $this->acl_forced = $_11fd0c43f9c6d4cceb91b12c0a8bb755->SetForcedThemeAcl($this->id, $this->acl_forced);
        }
    }
    public function DeleteAssets(AssetsStorage $storage)
    {
        $storage->DeleteAll();
    }
    public function GetThumbnailUrl(AssetsStorage $storage, $_b9f3a50ec08fa9ad275e47aaf4ca0c56 = true)
    {
        $url = $storage->GetUrl(self::THUMBNAIL_NAME);
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_a591754a8ddcdbda9c80f1db" . "4d911e14"]($url) && $_b9f3a50ec08fa9ad275e47aaf4ca0c56) {
            $url = self::DEFAULT_THUMBNAIL_URL;
        }
        return $url;
    }
    
    
    
    
    
    
    public function SetThumbnail($_93469c9375390f862eebb779f8b740e4)
    {
        $this->unsaved_thumbnail = $_93469c9375390f862eebb779f8b740e4;
    }
    
    
    
    
    
    
    
    
    public function SetCode(?string $code) : void
    {
        $this->SetProperty($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["cod" . "e"], $code);
    }
    public function SetAclView(Acl $acl)
    {
        $this->acl_view = $acl;
    }
    public function SetAclForced(Acl $acl)
    {
        $this->acl_forced = $acl;
    }
    
    
    
    
    
    
    
    
    
    public function GetProperty($_ce76a91ef2b7be07d7d04e74d4da9b6a)
    {
        $value = parent::GetProperty($_ce76a91ef2b7be07d7d04e74d4da9b6a);
        if ($_ce76a91ef2b7be07d7d04e74d4da9b6a === $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["i" . "d"] || $_ce76a91ef2b7be07d7d04e74d4da9b6a === $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["prio" . "rity"]) {
            $value = (int) $value;
        }
        return $value;
    }
    
    
    
    
    
    public function GetStyleData() : array
    {
        $data = @$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_7681c2a2b7e1bdf69c23c" . "6cd64114ad3"]($this->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_ec5506f" . "22f43806" . "97838f55" . "59d75d37" . "0"]), true);
        if (!$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_7f628626dd1d5" . "5c71b1fc0932ff" . "d1d2c"]($data)) {
            $data = [];
        }
        return $data;
    }
    
    
    
    
    public function GetDirectory() : ?string
    {
        if ($this->GetCode() !== null) {
            return $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_9c098e136f0" . "2f78824be9e6" . "ef30aedf6"] . $this->GetCode() . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_87daa84e3" . "46f6420a3f" . "3426e05d16" . "a7b"];
        }
        return null;
    }
    
    
}