<?php
namespace Claromentis\Projects\Comments;

$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"] = (@$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] ?: array()) + array("_b663a44bd9712bc095641" . "39d4db1cc2a" => base64_decode("Iy9kaXNjdX" . "NzaW9uVGFi"), "_e06da3ffba2e84b8e6f94b" . "d2d6ca3c52" => base64_decode("Y3JlYXRlX2ludGVybm" . "FsX2xpbms="), "_06cb50f090d050" . "fd50a05e9142986" . "f20" => base64_decode("L3By" . "b2pl" . "Y3Rz"), "_c927258f5322288a9" . "92c77be40ae0b53" => base64_decode("dX" . "Js"), "_e8c78c894ad907fd423d93530fdf" . "58fd" => base64_decode("bG1zZw" . "=="), "_bacbe8dd9caf37d515b" . "d02bcff1ba9fa" => base64_decode("cHJvamVjdHMucHJvam" . "VjdC5wYWdlX3RpdGxl"), "_043583fc6e4063be6ec4a3" . "1bf951616c" => base64_decode("L3Byb2plY3Rz" . "Lw=="), "_8dabb06efc95df" . "4cff7c4afe91857" . "b53" => base64_decode("bm" . "Ft" . "ZQ" . "=="));
use Claromentis\Comments\CommentableInterface;
use Claromentis\Comments\CommentLocationInterface;
use Claromentis\Comments\CommentUserPermissionsInterface;
use Claromentis\Comments\Model\Comment;
use Claromentis\Comments\Notification\Notification;
use Claromentis\Comments\ObjectUserPermissionsInterface;
use Claromentis\Comments\SupportedOptions;
use Claromentis\Comments\Rights;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Projects\Permissions;
use Claromentis\Projects\ProjectApi;
use Claromentis\Projects\Service\NotificationService;
use Claromentis\Projects\PermissionsChecker;
use Claromentis\Projects\Model\Project;
use Claromentis\Projects\Repository\ProjectRepository;
class CommentableProject implements CommentableInterface, CommentLocationInterface, CommentUserPermissionsInterface, ObjectUserPermissionsInterface
{
    private $project_id;
    
    
    
    
    private $project;
    
    
    protected $notification_service;
    
    
    protected $permissions_checker;
    
    
    protected $project_repository;
    
    
    protected $project_api;
    public function __construct()
    {
        global $g_application;
        
        
        $this->notification_service = $g_application[NotificationService::class];
        $this->permissions_checker = $g_application[PermissionsChecker::class];
        $this->project_repository = $g_application[ProjectRepository::class];
        $this->project_api = $g_application[ProjectApi::class];
    }
    
    
    
    
    
    
    
    public function Load($_0ea4e32b57963ac0cb3057e03e9aef64, $_4a033bdf0ce701c6255d5238633ab2d0 = array())
    {
        $this->project_id = $_0ea4e32b57963ac0cb3057e03e9aef64;
        $this->project = null;
    }
    
    
    
    
    
    
    public function GetAggregationObject()
    {
        if ($this->project === null) {
            $this->project = $this->project_repository->GetProject($this->project_id);
        }
        return $this->project;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UserHasPermission(SecurityContext $_0f4808db75324a12fb1768e785daadb7, $_a18f3f2e515f9b634cee4e5fbdcdb572, Comment $_e8d840684607f6c2bbef523090642168 = null)
    {
        
        
        $_a916d928b8442d37068d2cfd8aaf244d = $this->GetAggregationObject();
        if (!$_a916d928b8442d37068d2cfd8aaf244d->CanIViewComment($this->permissions_checker)) {
            return false;
        }
        if (($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_ADD) == Rights::PERM_ADD && !$_a916d928b8442d37068d2cfd8aaf244d->CanIAddComment($this->permissions_checker)) {
            return false;
        }
        if ($_e8d840684607f6c2bbef523090642168 && ($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_EDIT) == Rights::PERM_EDIT && !$_a916d928b8442d37068d2cfd8aaf244d->CanIEditComment($this->permissions_checker, $_e8d840684607f6c2bbef523090642168)) {
            return false;
        }
        if ($_e8d840684607f6c2bbef523090642168 && ($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_DELETE) == Rights::PERM_DELETE && ($_e8d840684607f6c2bbef523090642168->HasReplies() || !$_a916d928b8442d37068d2cfd8aaf244d->CanIDeleteComment($this->permissions_checker, $_e8d840684607f6c2bbef523090642168))) {
            return false;
        }
        return true;
    }
    
    
    
    
    
    
    
    public function GetOptions()
    {
        return [SupportedOptions::REPLIES => true, SupportedOptions::LIKES => true, SupportedOptions::ATTACHMENTS => true];
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Notify(Comment $_e8d840684607f6c2bbef523090642168, Notification $_0dfb4a13f8c551dff0f061eebc847961)
    {
        if ($this->notification_service->CanSendProjectNotifications((int) $_e8d840684607f6c2bbef523090642168->object_id)) {
            $_99aaa03a11622e16e59bff0771ea8ef3 = new ProjectCommentNotification($_e8d840684607f6c2bbef523090642168, $this->notification_service);
            $_0dfb4a13f8c551dff0f061eebc847961->template = $_99aaa03a11622e16e59bff0771ea8ef3->GetTemplate();
            $_0dfb4a13f8c551dff0f061eebc847961->type = $_99aaa03a11622e16e59bff0771ea8ef3->GetType();
            $_0dfb4a13f8c551dff0f061eebc847961->SetTemplateValues($_99aaa03a11622e16e59bff0771ea8ef3->GetMessageParams());
            $_0dfb4a13f8c551dff0f061eebc847961->SetRecipients($_99aaa03a11622e16e59bff0771ea8ef3->GetRecipients());
            $_0dfb4a13f8c551dff0f061eebc847961->Send();
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function GetBreadcrumbs(int $_2d876b122533fac9677b16ea6c640aa6)
    {
        $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($_2d876b122533fac9677b16ea6c640aa6);
        return [[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_8dabb06efc95d" . "f4cff7c4afe918" . "57b53"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_e8c78c894" . "ad907fd423" . "d93530fdf5" . "8fd"]($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_bacbe8dd9caf37d515bd02bcf" . "f1ba9fa"]), $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_c927258f5322" . "288a992c77be4" . "0ae0b53"] => $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_e06da3ffba2e8" . "4b8e6f94bd2d6c" . "a3c52"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_06cb50f090d050fd50a05e9142986" . "f20"])], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_8dabb06ef" . "c95df4cff7" . "c4afe91857" . "b53"] => $_0a3f284de65e596869ef47aa9e91f906->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_8dabb06efc95" . "df4cff7c4afe9" . "1857b53"]), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_c927258f5322288a992c77be40ae" . "0b53"] => $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_e06da3ffba2e84b8e6" . "f94bd2d6ca3c52"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_043583f" . "c6e4063b" . "e6ec4a31" . "bf951616" . "c"] . $_2d876b122533fac9677b16ea6c640aa6 . $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_b663a44bd9712bc09564139d4db" . "1cc2a"])]];
    }
    
    
    
    
    
    
    
    
    public function getUsersWithPermission(Comment $_e8d840684607f6c2bbef523090642168, int $_5630a508eaf62fdbab410362fa17735c = Rights::PERM_VIEW) : ?array
    {
        
        
        if ((int) $_e8d840684607f6c2bbef523090642168->aggregation !== Permissions::PROJECT_AGGREGATION) {
            return null;
        }
        $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($_e8d840684607f6c2bbef523090642168->object_id);
        if ($_5630a508eaf62fdbab410362fa17735c === Rights::PERM_VIEW) {
            return $this->permissions_checker->GetProjectMembersWithViewTopicsRights($_0a3f284de65e596869ef47aa9e91f906->GetId(), false);
        }
        return [];
    }
    
    
    
    
    
    
    
    public function getUserIdsWhoCanViewProject(?int $_5630a508eaf62fdbab410362fa17735c = null) : array
    {
        
        
        $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($this->project_id);
        if ($_0a3f284de65e596869ef47aa9e91f906 === null) {
            return [];
        }
        return $this->permissions_checker->GetProjectMemberWithViewProjectRights($_0a3f284de65e596869ef47aa9e91f906->GetId());
    }
}