<?php
namespace Claromentis\Documents\Comments;

$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"] = (@$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] ?: array()) + array("u" . "r" . "l" => base64_decode("d" . "X" . "J" . "s"), "_8e9463b" . "7f041a84" . "acd38de6" . "32adb12d" . "8" => base64_decode("bGlua190b19kaXNjdX" . "Nz"), "_a591754a8ddcdbd" . "a9c80f1db4d911e1" . "4" => base64_decode("aXNfbnVsb" . "A=="), "_c75814e1b13" . "755967929fb6" . "7a846a799" => base64_decode("Iy9jb21t" . "ZW50LXRh" . "Yg=="), "_0c5123a" . "a744f69b" . "bc0e8b3e" . "a2f6e847" . "d" => base64_decode("bG1zZw=" . "="), "_4881467ca" . "468da5ceb0" . "51a35155b9" . "dab" => base64_decode("L2ludHJhbmV0L2RvY3VtZW50cy8jbGlz" . "dC8w"), "n" . "a" . "m" . "e" => base64_decode("bmFtZQ" . "=="), "_f784524629d9404cd62b" . "a9e1475d3bc3" => base64_decode("b2JqZWN0X25h" . "bWU="), "_12638e95eb" . "592dc440b73" . "a4e7ea3ca21" => base64_decode("Y29tbW9uLnR5cGU" . "uZG9jdW1lbnRz"), "_e06da3ffba2e84b8e6f9" . "4bd2d6ca3c52" => base64_decode("Y3JlYXRlX2ludGVybmFsX2xpbm" . "s="));
use Claromentis\Comments\CommentableInterface;
use Claromentis\Comments\CommentLocationInterface;
use Claromentis\Comments\Model\Comment;
use Claromentis\Comments\Notification\Notification;
use Claromentis\Comments\Rights;
use Claromentis\Comments\SupportedOptions;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Core\Services;
class CommentableDocuments implements CommentableInterface, CommentLocationInterface
{
    private $document_id;
    
    
    
    
    
    private $document_obj;
    public static function CreateFromObject(\ERMSDataObj $_b641d83881f6249afce3fa798125708a)
    {
        $_68ffaaa31e3ba49ed9d6159fbee9f043 = new static();
        $_68ffaaa31e3ba49ed9d6159fbee9f043->document_obj = $_b641d83881f6249afce3fa798125708a;
        $_68ffaaa31e3ba49ed9d6159fbee9f043->document_id = $_b641d83881f6249afce3fa798125708a->GetDocId();
        
        
        
        $_68ffaaa31e3ba49ed9d6159fbee9f043->document_obj->id = $_68ffaaa31e3ba49ed9d6159fbee9f043->document_id;
        return $_68ffaaa31e3ba49ed9d6159fbee9f043;
    }
    
    
    
    
    
    
    
    
    public function Load($id, $_4a033bdf0ce701c6255d5238633ab2d0 = array())
    {
        
        
        
        $_b2e2301cda45361416cebc466d340194 = \ERMSBrowser::I();
        $this->document_id = $id;
        $_55d3c75af03093e4e61a38a65c80ff45 = $_b2e2301cda45361416cebc466d340194->GetIdByDocId($id);
        $this->document_obj = $_b2e2301cda45361416cebc466d340194->GetERMSObject($_55d3c75af03093e4e61a38a65c80ff45, AGGREGATION_DATA);
        $this->document_obj->id = $id;
    }
    
    
    
    
    
    
    
    public function GetAggregationObject()
    {
        if ($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_a591754a8dd" . "cdbda9c80f1d" . "b4d911e14"]($this->document_obj)) {
            $_b2e2301cda45361416cebc466d340194 = \ERMSBrowser::I();
            try {
                $this->document_obj = $_b2e2301cda45361416cebc466d340194->GetERMSObject($this->document_id, AGGREGATION_DATA);
            } catch (\Exception $_fe441aa3ef350bfb1a1a1ad8520dd530) {
                
                
                $this->document_obj = null;
            }
        }
        return $this->document_obj;
    }
    
    
    
    
    
    
    
    
    public function GetOptions()
    {
        return [SupportedOptions::REPLIES => true, SupportedOptions::LIKES => true, SupportedOptions::ATTACHMENTS => true];
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UserHasPermission(SecurityContext $context, $perms, Comment $comment = null)
    {
        $_fc4ffcaec4dff19ed04cc1c9229222d1 = $this->GetAggregationObject();
        $_232d8d8e26373a28d75581603d074938 = new \ERMSPermsCheckerUser();
        
        
        if ($perms != Rights::PERM_VIEW && !$_232d8d8e26373a28d75581603d074938->CanView($_fc4ffcaec4dff19ed04cc1c9229222d1)) {
            return false;
        }
        
        
        if (($perms & Rights::PERM_EDIT) == Rights::PERM_EDIT || ($perms & Rights::PERM_DELETE) == Rights::PERM_DELETE) {
            if (!$_232d8d8e26373a28d75581603d074938->CanModerate($_fc4ffcaec4dff19ed04cc1c9229222d1)) {
                if ($comment && (int) $comment->user_id !== $context->GetUserId()) {
                    return false;
                }
            }
        }
        
        
        if ($comment && ($perms & Rights::PERM_DELETE) == Rights::PERM_DELETE && $comment->HasReplies()) {
            return false;
        }
        return true;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Notify(Comment $comment, Notification $_0dfb4a13f8c551dff0f061eebc847961)
    {
        $_0dfb4a13f8c551dff0f061eebc847961->type = \IMessage::TYPE_DOCUMENTS;
        $_fc4ffcaec4dff19ed04cc1c9229222d1 = $this->GetAggregationObject();
        $_0dfb4a13f8c551dff0f061eebc847961->AddTemplateValues([$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_f784524629d9404cd62ba" . "9e1475d3bc3"] => $_fc4ffcaec4dff19ed04cc1c9229222d1->GetTitle(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_8e9463b7f041a84acd38" . "de632adb12d8"] => $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_e06da3ffba2e84" . "b8e6f94bd2d6ca3" . "c52"]($_fc4ffcaec4dff19ed04cc1c9229222d1->GetPrimaryVersionUrl() . $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_c75814e1b137559" . "67929fb67a846a79" . "9"])]);
        $_0dfb4a13f8c551dff0f061eebc847961->AddRecipients([$_fc4ffcaec4dff19ed04cc1c9229222d1->GetCreator(), $_fc4ffcaec4dff19ed04cc1c9229222d1->GetLastModifiedBy()]);
        $_0dfb4a13f8c551dff0f061eebc847961->Send();
    }
    public function GetBreadcrumbs(int $object_id)
    {
        $_028c56e9753e5e2b616127818a6b7f8d = [[$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["nam" . "e"] => $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_0c5123aa744f69" . "bbc0e8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_12638e95" . "eb592dc44" . "0b73a4e7e" . "a3ca21"]), $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["u" . "r" . "l"] => $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_4881467ca468da" . "5ceb051a35155b9" . "dab"]]];
        global $db;
        $db = Services::I()->GetDb();
        
        
        
        $_b2e2301cda45361416cebc466d340194 = \ERMSBrowser::I();
        $_55d3c75af03093e4e61a38a65c80ff45 = $_b2e2301cda45361416cebc466d340194->GetIdByDocId($object_id);
        $_fc4ffcaec4dff19ed04cc1c9229222d1 = $_b2e2301cda45361416cebc466d340194->GetData($_55d3c75af03093e4e61a38a65c80ff45);
        $_fc4ffcaec4dff19ed04cc1c9229222d1->id = $object_id;
        $this->GetParentsBreadcrumb($_fc4ffcaec4dff19ed04cc1c9229222d1->GetAllParents()[0], $_028c56e9753e5e2b616127818a6b7f8d);
        $_028c56e9753e5e2b616127818a6b7f8d[] = [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["na" . "me"] => $_fc4ffcaec4dff19ed04cc1c9229222d1->GetTitle(), $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["ur" . "l"] => $_fc4ffcaec4dff19ed04cc1c9229222d1->GetUrl()];
        return $_028c56e9753e5e2b616127818a6b7f8d;
    }
    protected function GetParentsBreadcrumb(\ERMSFolder $_a4b4fe29a876bd36f8024f56a625bf4c, &$_028c56e9753e5e2b616127818a6b7f8d)
    {
        $_568fcb2872723a3ebac6afca64f9238e = $_a4b4fe29a876bd36f8024f56a625bf4c->GetParent();
        if ($_568fcb2872723a3ebac6afca64f9238e instanceof \ERMSFolder) {
            $this->GetParentsBreadcrumb($_568fcb2872723a3ebac6afca64f9238e, $_028c56e9753e5e2b616127818a6b7f8d);
        }
        $_028c56e9753e5e2b616127818a6b7f8d[] = [$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["nam" . "e"] => $_a4b4fe29a876bd36f8024f56a625bf4c->GetTitle(), $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["ur" . "l"] => $_a4b4fe29a876bd36f8024f56a625bf4c->GetUrl()];
    }
}