<?php
namespace Claromentis\Projects\Comments;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] ?: array()) + array("_52d03f7cce0e564b4b6" . "f92d9f0be3b6f" => base64_decode("L3Byb2plY" . "3RzL3Rhc2" . "sv"), "_043583fc6e4063be6ec4a31bf" . "951616c" => base64_decode("L3Byb2" . "plY3Rz" . "Lw=="), "_3ad1a2417" . "88d51921db" . "8e8da90d8e" . "233" => base64_decode("cHJvamVjdHMudGFza" . "3MuYWxsX3Rhc2tzLn" . "BhZ2VfdGl0bGU="), "_06cb50f090d050f" . "d50a05e9142986f2" . "0" => base64_decode("L3Byb" . "2plY3" . "Rz"), "_e8c78c894" . "ad907fd423" . "d93530fdf5" . "8fd" => base64_decode("bG1z" . "Zw=="), "_539e88e91d70683b12" . "1c29f08d02fe07" => base64_decode("L3Byb2plY3RzL3Rh" . "c2tz"), "_e06da3ffb" . "a2e84b8e6f" . "94bd2d6ca3" . "c52" => base64_decode("Y3JlYXRlX2ludGVybmFsX" . "2xpbms="), "_8dabb06efc95df" . "4cff7c4afe91857" . "b53" => base64_decode("bmFt" . "ZQ=="), "_bacbe8dd9caf37d515bd02bcff1ba" . "9fa" => base64_decode("cHJvamVjdHMucHJvamVjdC5wYWdlX3Rpd" . "Gxl"), "_feb9037589181bc30fa0f1cf78" . "b9f056" => base64_decode("dGl" . "0bG" . "U="), "_c927258f5322288a992c" . "77be40ae0b53" => base64_decode("dXJ" . "s"));
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\Repository\TeamRepository;
use Claromentis\Projects\Service\NotificationService;
use Claromentis\Projects\PermissionsChecker;
use Claromentis\Projects\Repository\ProjectRepository;
use Claromentis\Projects\Model\Task;
use Claromentis\Projects\Repository\TaskRepository;
class CommentableTask implements CommentableInterface, CommentLocationInterface, CommentUserPermissionsInterface, ObjectUserPermissionsInterface
{
    private $task_id;
    
    
    
    
    private $task;
    
    
    protected $notification_service;
    
    
    protected $permissions_checker;
    
    
    protected $task_repository;
    
    
    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->task_repository = $g_application[TaskRepository::class];
        $this->project_repository = $g_application[ProjectRepository::class];
        $this->project_api = $g_application[ProjectApi::class];
    }
    
    
    
    
    
    
    
    public function Load($_0ea4e32b57963ac0cb3057e03e9aef64, $_4a033bdf0ce701c6255d5238633ab2d0 = array())
    {
        $this->task_id = $_0ea4e32b57963ac0cb3057e03e9aef64;
        $this->task = null;
    }
    
    
    
    
    
    
    public function GetAggregationObject()
    {
        if ($this->task === null) {
            $this->task = $this->task_repository->LoadTask($this->task_id);
        }
        return $this->task;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UserHasPermission(SecurityContext $_0f4808db75324a12fb1768e785daadb7, $_a18f3f2e515f9b634cee4e5fbdcdb572, Comment $_e8d840684607f6c2bbef523090642168 = null)
    {
        
        
        $_a916d928b8442d37068d2cfd8aaf244d = $this->GetAggregationObject();
        if ($_a916d928b8442d37068d2cfd8aaf244d->IsAdHoc()) {
            if (($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_ADD) === Rights::PERM_ADD) {
                return $_a916d928b8442d37068d2cfd8aaf244d->CanIAddComment($this->permissions_checker);
            }
            if (($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_EDIT) === Rights::PERM_EDIT) {
                return $_a916d928b8442d37068d2cfd8aaf244d->CanIEditComment($this->permissions_checker, $_e8d840684607f6c2bbef523090642168);
            }
            if ($_e8d840684607f6c2bbef523090642168 && ($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_DELETE) === Rights::PERM_DELETE) {
                return !$_e8d840684607f6c2bbef523090642168->HasReplies() && $_a916d928b8442d37068d2cfd8aaf244d->CanIDeleteComment($this->permissions_checker, $_e8d840684607f6c2bbef523090642168);
            }
        }
        if (!$_a916d928b8442d37068d2cfd8aaf244d->CanIViewComment($this->permissions_checker)) {
            return false;
        }
        if (($_a18f3f2e515f9b634cee4e5fbdcdb572 & Rights::PERM_ADD) == Rights::PERM_ADD && !$_a916d928b8442d37068d2cfd8aaf244d->CanIAddComment($this->permissions_checker)) {
            return false;
        }
        if (($_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->CanSendTaskNotifications((int) $_e8d840684607f6c2bbef523090642168->object_id)) {
            $_99aaa03a11622e16e59bff0771ea8ef3 = new TaskCommentNotification($_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)
    {
        $_696b535739055ed7d827709916d07dea = $this->task_repository->LoadTask($_2d876b122533fac9677b16ea6c640aa6);
        if ($_696b535739055ed7d827709916d07dea->GetProject() == 0) {
            
            
            return [[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_8dabb06efc95df4cff7c4afe9185" . "7b53"] => $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_e8c78c894ad907fd423" . "d93530fdf58fd"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_3ad1a24178" . "8d51921db8e" . "8da90d8e233"]), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_c927258f5322288a992c77be" . "40ae0b53"] => $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_e06da3ffba2e84b8e6f94bd2d6c" . "a3c52"]($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_539e88e91d7068" . "3b121c29f08d02f" . "e07"])], [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_8dabb06efc95df4cff7" . "c4afe91857b53"] => $_696b535739055ed7d827709916d07dea->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_feb9037589181bc3" . "0fa0f1cf78b9f056"]), $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_c927258f532228" . "8a992c77be40ae0" . "b53"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_e06da3ffba2e84b8e6f94bd2d6ca3c" . "52"]($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_52d03f7cce0e564b4b6f92d" . "9f0be3b6f"] . $_2d876b122533fac9677b16ea6c640aa6)]];
        } else {
            $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($_696b535739055ed7d827709916d07dea->GetProject());
            return [[$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_8dabb06efc95df4cff7c4" . "afe91857b53"] => $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_e8c78c894ad907fd423d93530fdf58" . "fd"]($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_bacbe8dd9c" . "af37d515bd0" . "2bcff1ba9fa"]), $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_c927258f5322288a992c77be" . "40ae0b53"] => $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_e06da3ffba2" . "e84b8e6f94bd" . "2d6ca3c52"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_06cb50f090d050f" . "d50a05e9142986f2" . "0"])], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_8dabb06ef" . "c95df4cff7" . "c4afe91857" . "b53"] => $_0a3f284de65e596869ef47aa9e91f906->GetProperty($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_8dabb06efc95df4cff7c4a" . "fe91857b53"]), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_c927258" . "f5322288" . "a992c77b" . "e40ae0b5" . "3"] => $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_e06da3ffba2e84b8e6f94bd2d6ca3c" . "52"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_043583fc6e4063be6ec4a31b" . "f951616c"] . $_0a3f284de65e596869ef47aa9e91f906->GetId())], [$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_8dabb06efc95df4c" . "ff7c4afe91857b53"] => $_696b535739055ed7d827709916d07dea->GetProperty($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_feb9037589181bc30fa0f1" . "cf78b9f056"]), $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_c927258f5322288a9" . "92c77be40ae0b53"] => $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_e06da3ffba2e8" . "4b8e6f94bd2d6c" . "a3c52"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_52d03f7cce0" . "e564b4b6f92d" . "9f0be3b6f"] . $_2d876b122533fac9677b16ea6c640aa6)]];
        }
    }
    
    
    
    
    
    
    
    
    public function getUsersWithPermission(Comment $_e8d840684607f6c2bbef523090642168, int $_5630a508eaf62fdbab410362fa17735c = Rights::PERM_VIEW) : ?array
    {
        
        
        if ((int) $_e8d840684607f6c2bbef523090642168->aggregation !== Permissions::TASK_AGGREGATION) {
            return null;
        }
        $_696b535739055ed7d827709916d07dea = $this->task_repository->LoadTask($_e8d840684607f6c2bbef523090642168->object_id);
        $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($_696b535739055ed7d827709916d07dea->GetProject());
        if ($_5630a508eaf62fdbab410362fa17735c === Rights::PERM_VIEW) {
            return $this->permissions_checker->GetProjectMembersWithViewTopicsRights($_0a3f284de65e596869ef47aa9e91f906->GetId(), false);
        }
        return [];
    }
    
    
    
    
    
    
    public function getUserIdsWhoCanViewProject() : array
    {
        $_696b535739055ed7d827709916d07dea = $this->task_repository->LoadTask($this->task_id);
        $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($_696b535739055ed7d827709916d07dea->GetProject());
        if ($_0a3f284de65e596869ef47aa9e91f906 === null) {
            return [];
        }
        return $this->permissions_checker->GetProjectMemberWithViewProjectRights($_0a3f284de65e596869ef47aa9e91f906->GetId());
    }
}