<?php
namespace Claromentis\News\Comments;

$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] ?: array()) + array("_559824e0ac2e0" . "f7e96c810473f7" . "8f5fe" => base64_decode("L25" . "ld3" . "Mv"), "_d0c05b93b1b39" . "30a232616bd5f5" . "73345" => base64_decode("bWVudS5hcH" . "AubmV3cw=="), "_0c5123aa744" . "f69bbc0e8b3e" . "a2f6e847d" => base64_decode("bG1" . "zZw" . "=="), "_6e1e715e87d93" . "e333725ce6b91b" . "c6b09" => base64_decode("L25ld3M" . "="), "_e06da3ffba2e" . "84b8e6f94bd2d" . "6ca3c52" => base64_decode("Y3JlYXRlX2ludGVybmFsX2xpb" . "ms="), "na" . "me" => base64_decode("bmFt" . "ZQ=="), "ur" . "l" => base64_decode("dX" . "Js"), "_f784524629d9404cd62ba9e" . "1475d3bc3" => base64_decode("b2JqZW" . "N0X25h" . "bWU="), "_a591754" . "a8ddcdbd" . "a9c80f1d" . "b4d911e1" . "4" => base64_decode("aXN" . "fbn" . "Vsb" . "A=="));
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\Core\DAL;
use Claromentis\Comments\Rights;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Core\Services;
use NewsItem;
use NewsItemBase;






class CommentableNews implements CommentableInterface, CommentLocationInterface
{
    private $news_id;
    
    
    
    
    private $news_item;
    
    
    
    
    
    
    public static function CreateFromObject(NewsItem $_60378eae7533ef2a18e2cf710db06291)
    {
        $_68ffaaa31e3ba49ed9d6159fbee9f043 = new static();
        $_68ffaaa31e3ba49ed9d6159fbee9f043->news_item = $_60378eae7533ef2a18e2cf710db06291;
        $_68ffaaa31e3ba49ed9d6159fbee9f043->news_id = $_60378eae7533ef2a18e2cf710db06291->GetId();
        return $_68ffaaa31e3ba49ed9d6159fbee9f043;
    }
    public static function DeleteFromObject(NewsItem $_60378eae7533ef2a18e2cf710db06291)
    {
        $_5e1e8bdeb7dc6725dab2802927e4f193 = self::CreateFromObject($_60378eae7533ef2a18e2cf710db06291);
        
        
        $_d494fa2121915ac5ef3cbbab4c40bef2 = Services::I()->{CommentsRepository::class};
        $_d494fa2121915ac5ef3cbbab4c40bef2->DeleteAllForObject($_5e1e8bdeb7dc6725dab2802927e4f193);
    }
    
    
    
    
    
    
    
    
    
    public function Load($id, $_4a033bdf0ce701c6255d5238633ab2d0 = array())
    {
        $this->news_id = $id;
        $this->news_item = null;
    }
    
    
    
    
    
    
    public function GetAggregationObject()
    {
        if ($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_a591754a8dd" . "cdbda9c80f1d" . "b4d911e14"]($this->news_item)) {
            $this->news_item = new \NewsItem($this->news_id);
        }
        return $this->news_item;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UserHasPermission(SecurityContext $context, $perms, Comment $comment = null)
    {
        $_a916d928b8442d37068d2cfd8aaf244d = $this->GetAggregationObject();
        if (!$_a916d928b8442d37068d2cfd8aaf244d->UserHasPermission(PERM_VIEW)) {
            return false;
        }
        if ($perms != Rights::PERM_VIEW && !$_a916d928b8442d37068d2cfd8aaf244d->IsCommentingEnabled()) {
            return false;
        }
        if (($perms & Rights::PERM_EDIT) == Rights::PERM_EDIT || ($perms & Rights::PERM_DELETE) == Rights::PERM_DELETE) {
            if (!$_a916d928b8442d37068d2cfd8aaf244d->UserHasPermission(PERM_APPROVE)) {
                if ($comment && (int) $comment->user_id !== $context->GetUserId()) {
                    return false;
                }
            }
        }
        return true;
    }
    
    
    
    
    
    
    
    public function GetOptions()
    {
        return [SupportedOptions::REPLIES => true, SupportedOptions::LIKES => true, SupportedOptions::ATTACHMENTS => true];
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Notify(Comment $comment, Notification $_0dfb4a13f8c551dff0f061eebc847961)
    {
        $_0dfb4a13f8c551dff0f061eebc847961->type = \IMessage::TYPE_NEWS;
        $_60378eae7533ef2a18e2cf710db06291 = $this->GetAggregationObject();
        $_0dfb4a13f8c551dff0f061eebc847961->AddTemplateValues([$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_f784524629d9404cd62ba9e1475d3b" . "c3"] => $_60378eae7533ef2a18e2cf710db06291->GetTitle()]);
        $_fa7526ba4ccc308fe61186445986ceaa = $_0dfb4a13f8c551dff0f061eebc847961->GetRecipients();
        
        
        if ($_60378eae7533ef2a18e2cf710db06291->owner_id != $comment->user_id) {
            if (!isset($_fa7526ba4ccc308fe61186445986ceaa[$_60378eae7533ef2a18e2cf710db06291->owner_id])) {
                $_fa7526ba4ccc308fe61186445986ceaa[] = $_60378eae7533ef2a18e2cf710db06291->owner_id;
            }
        }
        $_0dfb4a13f8c551dff0f061eebc847961->SetRecipients($_fa7526ba4ccc308fe61186445986ceaa);
        $_0dfb4a13f8c551dff0f061eebc847961->Send();
    }
    public function GetBreadcrumbs(int $object_id)
    {
        $_60378eae7533ef2a18e2cf710db06291 = NewsItemBase::Get($object_id);
        return [[$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["n" . "a" . "m" . "e"] => $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_0c5123aa744" . "f69bbc0e8b3e" . "a2f6e847d"]($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_d0c05b93b1b3930a23261" . "6bd5f573345"]), $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["ur" . "l"] => $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_e06da3ffba2e84b8e6f94bd2d" . "6ca3c52"]($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_6e1e715e87d93e33372" . "5ce6b91bc6b09"])], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["nam" . "e"] => $_60378eae7533ef2a18e2cf710db06291->GetTitle(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["ur" . "l"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_e06da3ffb" . "a2e84b8e6f" . "94bd2d6ca3" . "c52"]($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_559824e0ac2e0f7e96c810473f78" . "f5fe"] . $object_id)]];
    }
}