<?php
namespace Claromentis\Blog\Comments;

$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] ?: array()) + array("_f784524629d9404cd" . "62ba9e1475d3bc3" => base64_decode("b2Jq" . "ZWN0" . "X25h" . "bWU="), "_2457e28fb4d91b5f7528008953d9" . "56b5" => base64_decode("YmxvZy5jb21tb24uYmx" . "vZw=="), "_c927258" . "f5322288" . "a992c77b" . "e40ae0b5" . "3" => base64_decode("dX" . "Js"), "_e06da3ffba" . "2e84b8e6f94" . "bd2d6ca3c52" => base64_decode("Y3JlYXRlX2lud" . "GVybmFsX2xpbm" . "s="), "_48a68e7cee9866c9a73" . "3099222c3ab9c" => base64_decode("L2" . "Js" . "b2" . "c="), "_8dabb06efc95df4cff" . "7c4afe91857b53" => base64_decode("bm" . "Ft" . "ZQ" . "=="), "_c7b86566" . "f5835e34c" . "8ef0cf3b3" . "6b6046" => base64_decode("L2" . "Js" . "b2" . "cv"), "_a591754a8ddcdbda" . "9c80f1db4d911e14" => base64_decode("aXNfbnVsbA" . "=="), "_87daa84e346f6420a3f3426e05d16a" . "7b" => base64_decode("L" . "w" . "=" . "="), "_0c5123aa744f69bbc0e8b3ea2f6e8" . "47d" => base64_decode("bG1zZ" . "w=="));
use Claromentis\Comments\CommentableInterface;
use Claromentis\Comments\CommentLocationInterface;
use Claromentis\Comments\CommentsRepository;
use Claromentis\Comments\Model\Comment;
use Claromentis\Comments\Notification\Notification;
use Claromentis\Comments\SupportedOptions;
use Claromentis\Comments\Rights;
use Claromentis\Core\Security\SecurityContext;
use BlogPost;
use Claromentis\Core\Services;




class CommentableBlog implements CommentableInterface, CommentLocationInterface
{
    private $blog_id;
    
    
    
    
    private $blog_post;
    
    
    
    
    
    
    public static function CreateFromObject(BlogPost $_d46d6e01a4991a0a517398cada804774)
    {
        $_68ffaaa31e3ba49ed9d6159fbee9f043 = new static();
        $_68ffaaa31e3ba49ed9d6159fbee9f043->blog_post = $_d46d6e01a4991a0a517398cada804774;
        $_68ffaaa31e3ba49ed9d6159fbee9f043->blog_id = $_d46d6e01a4991a0a517398cada804774->GetId();
        return $_68ffaaa31e3ba49ed9d6159fbee9f043;
    }
    public static function DeleteFromObject(BlogPost $_d46d6e01a4991a0a517398cada804774)
    {
        $_5e1e8bdeb7dc6725dab2802927e4f193 = self::CreateFromObject($_d46d6e01a4991a0a517398cada804774);
        
        
        $_d494fa2121915ac5ef3cbbab4c40bef2 = Services::I()->{CommentsRepository::class};
        $_d494fa2121915ac5ef3cbbab4c40bef2->DeleteAllForObject($_5e1e8bdeb7dc6725dab2802927e4f193);
    }
    
    
    
    
    
    
    
    
    
    public function Load($_0ea4e32b57963ac0cb3057e03e9aef64, $_4a033bdf0ce701c6255d5238633ab2d0 = array())
    {
        $this->blog_id = $_0ea4e32b57963ac0cb3057e03e9aef64;
        $this->blog_post = null;
    }
    
    
    
    
    
    
    public function GetAggregationObject()
    {
        if ($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_a591754a8ddcdb" . "da9c80f1db4d911" . "e14"]($this->blog_post)) {
            $this->blog_post = new BlogPost($this->blog_id);
        }
        return $this->blog_post;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UserHasPermission(SecurityContext $context, $_a18f3f2e515f9b634cee4e5fbdcdb572, Comment $_e8d840684607f6c2bbef523090642168 = null)
    {
        
        
        $_d46d6e01a4991a0a517398cada804774 = $this->GetAggregationObject();
        if (!$_d46d6e01a4991a0a517398cada804774->UserHasPermission(PERM_VIEW)) {
            return false;
        }
        if ($_a18f3f2e515f9b634cee4e5fbdcdb572 != Rights::PERM_VIEW && !$_d46d6e01a4991a0a517398cada804774->IsCommentingEnabled()) {
            return false;
        }
        if (($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_EDIT) == Rights::PERM_EDIT || ($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_DELETE) == Rights::PERM_DELETE) {
            if (!$_d46d6e01a4991a0a517398cada804774->UserHasPermission(PERM_APPROVE)) {
                if ($_e8d840684607f6c2bbef523090642168 && (int) $_e8d840684607f6c2bbef523090642168->user_id !== $context->GetUserId()) {
                    return false;
                }
            }
        }
        if ($_e8d840684607f6c2bbef523090642168 && ($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_DELETE) == Rights::PERM_DELETE && $_e8d840684607f6c2bbef523090642168->HasReplies()) {
            return false;
        }
        return true;
    }
    
    
    
    
    
    
    
    public function GetOptions()
    {
        return [SupportedOptions::REPLIES => true, SupportedOptions::LIKES => true, SupportedOptions::ATTACHMENTS => true];
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Notify(Comment $_e8d840684607f6c2bbef523090642168, Notification $_0dfb4a13f8c551dff0f061eebc847961)
    {
        $_0dfb4a13f8c551dff0f061eebc847961->type = \IMessage::TYPE_BLOG;
        $_d46d6e01a4991a0a517398cada804774 = $this->GetAggregationObject();
        $_0dfb4a13f8c551dff0f061eebc847961->AddTemplateValues([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_f784524629d9404cd62ba9e1475d" . "3bc3"] => $_d46d6e01a4991a0a517398cada804774->GetTitle()]);
        $_0dfb4a13f8c551dff0f061eebc847961->Send();
    }
    public function GetBreadcrumbs(int $_2d876b122533fac9677b16ea6c640aa6)
    {
        $_d46d6e01a4991a0a517398cada804774 = $_d46d6e01a4991a0a517398cada804774 = new BlogPost($_2d876b122533fac9677b16ea6c640aa6);
        return [[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_8dabb06efc95df4cff7c4afe91857b5" . "3"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_0c5123aa744f69" . "bbc0e8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_2457e28fb4d91b5f75" . "28008953d956b5"]), $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_c927258f5" . "322288a992" . "c77be40ae0" . "b53"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_e06da3ffba" . "2e84b8e6f94" . "bd2d6ca3c52"]($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_48a68e7cee9866c9a73309922" . "2c3ab9c"])], [$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_8dabb06ef" . "c95df4cff7" . "c4afe91857" . "b53"] => $_d46d6e01a4991a0a517398cada804774->GetTitle(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_c927258f5322288a992c77be40a" . "e0b53"] => $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_e06da3ffba2e" . "84b8e6f94bd2d" . "6ca3c52"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_c7b86566f5835e34c8ef0cf" . "3b36b6046"] . $_d46d6e01a4991a0a517398cada804774->channel_id . $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_87daa84e346f6420a3f3426e05d16a7" . "b"] . $_d46d6e01a4991a0a517398cada804774->id)]];
    }
}