<?php
namespace Claromentis\Projects\Comments;

$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"] ?: array()) + array("_d50d529d5739d" . "103bc48e65a4b5" . "13fe3" => base64_decode("Q29tbWVudEFkZGV" . "kRXZlbnRSZWNlaX" . "Zlcg=="), "_3877cdf57a61e49b56aeab7af930e" . "e82" => base64_decode("dXNlcl9pZA=" . "="), "_93939227a8e7cf780efaa642" . "c3da9723" => base64_decode("Ynlf" . "dXNl" . "cl9p" . "ZA=="), "_c927258f5322288a9" . "92c77be40ae0b53" => base64_decode("d" . "X" . "J" . "s"), "_e06da3ffba2e84b8e6f94bd2d" . "6ca3c52" => base64_decode("Y3JlYXRlX" . "2ludGVybm" . "FsX2xpbms" . "="), "_077e2716867" . "3cad4e72653c" . "8730129b5" => base64_decode("ZmlsZW5" . "hbWU="), "_2d876b122533fac9677b16ea6c640a" . "a6" => base64_decode("b2JqZW" . "N0X2lk"), "_00f2055c7cbd408ef569" . "49f35c62b721" => base64_decode("Zmls" . "ZXM="), "_699cd46f386ae1974722616ce651a" . "3a1" => base64_decode("YWdncmVnYXRpb" . "24="), "_31767d7a" . "d58e706db" . "f47b7a51a" . "0fe6c4" => base64_decode("Y291b" . "nQ="), "_191a9c694701b5e98f9" . "b02b73105f5cf" => base64_decode("Q29tbWVudERlbGV0ZWRFdmVudFJlY2Vpd" . "mVy"), "_db618ca8e79f97b" . "4dff753ec837942c" . "f" => base64_decode("cHJvamVj" . "dF9pZA=="), "_76b1e0edd97786ed9ddb" . "7b7f6083c218" => base64_decode("cHJvamVjdHMucH" . "JvamVjdHNfcHJv" . "dmlkZXI="), "_9bb5cca7404" . "240f9068ffc9" . "838b77be1" => base64_decode("Q29tbWVudEF0dGFjaG1lbnRzQWRkZWRFdmVudFJlY2Vpd" . "mVy"), "_e3037a4609adf1f69b1e8dc98" . "13b51ec" => base64_decode("dGFza19p" . "ZA=="), "_dadf790baf241afac" . "942824c1e6e37c4" => base64_decode("dHlwZQ=" . "="));
use Claromentis\Comments\Events\CommentAddedEvent;
use Claromentis\Comments\Events\CommentAttachmentsAddedEvent;
use Claromentis\Comments\Events\CommentDeletedEvent;
use Claromentis\Comments\Model\Attachment;
use Claromentis\Comments\Model\Comment;
use Claromentis\Core\Services;
use Claromentis\Projects\Entity\Topic;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Projects\Service\NotificationService;
use Claromentis\Projects\Service\FilesService;
use Claromentis\Projects\Permissions;
use Claromentis\Projects\Exceptions\ProjectsFolderException;
use Claromentis\Projects\ProjectEvent;
use Claromentis\Projects\Repository\ProjectRepository;
use Claromentis\Projects\Repository\TopicRepository;
use Claromentis\Projects\Repository\TaskRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;






class CommentsSubscriber implements EventSubscriberInterface
{
    
    
    protected $project_repository;
    
    
    protected $task_repository;
    
    
    protected $files_service;
    
    
    protected $context;
    public function __construct(ProjectRepository $_3df6a3ee29561bd6e42ae4d5e62ba1be, TaskRepository $_21f780f08a9470c494fb6a449b8f20bd, FilesService $_b45408acf432d2f575dd658b48fcb432, SecurityContext $_0f4808db75324a12fb1768e785daadb7, TopicRepository $_018eed6448abbc8c4aae90cde2897af1)
    {
        $this->project_repository = $_3df6a3ee29561bd6e42ae4d5e62ba1be;
        $this->task_repository = $_21f780f08a9470c494fb6a449b8f20bd;
        $this->files_service = $_b45408acf432d2f575dd658b48fcb432;
        $this->context = $_0f4808db75324a12fb1768e785daadb7;
        $this->topic_repository = $_018eed6448abbc8c4aae90cde2897af1;
    }
    
    
    
    
    protected $topic_repository;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public static function getSubscribedEvents()
    {
        return [CommentAddedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_d50d529d5739d103bc48e65a4b513" . "fe3"], CommentDeletedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_191a9c694701b5e98f9b0" . "2b73105f5cf"], CommentAttachmentsAddedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_9bb5cca7404240f9068ffc9" . "838b77be1"]];
    }
    public function CommentAddedEventReceiver(CommentAddedEvent $_e62ca7bbb93b52cafc82da1c2aefe9ec, $_5693d84b45564f912e36404cbe8957e8, EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        
        
        $_e8d840684607f6c2bbef523090642168 = $_e62ca7bbb93b52cafc82da1c2aefe9ec->getComment();
        switch ($_e8d840684607f6c2bbef523090642168->aggregation) {
            case Topic::AGGREGATION:
                
                
                $_9a3559422c29efc571cba589ffa1a59f = $this->topic_repository->find($_e8d840684607f6c2bbef523090642168->object_id);
                
                
                $_9a3559422c29efc571cba589ffa1a59f->modified = new \Date();
                $this->topic_repository->store($_9a3559422c29efc571cba589ffa1a59f);
                
                
                $_f4a2686c1ded90204b914f133dc57722 = Services::I()->{$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_76b1e0edd97786" . "ed9ddb7b7f6083c" . "218"]};
                $_f4a2686c1ded90204b914f133dc57722->IncrementCommentCount($_9a3559422c29efc571cba589ffa1a59f->project_id);
                if ($_e8d840684607f6c2bbef523090642168->parent_id === 0) {
                    
                    
                    $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::PROJECT_DISCUSSION_POSTED, new ProjectEvent($_e8d840684607f6c2bbef523090642168));
                } else {
                    
                    
                    $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::PROJECT_REPLY_POSTED, new ProjectEvent($_e8d840684607f6c2bbef523090642168));
                }
                $_e62ca7bbb93b52cafc82da1c2aefe9ec->stopPropagation();
            case Permissions::TASK_AGGREGATION:
                $this->task_repository->IncrementCommentCount($_e8d840684607f6c2bbef523090642168->object_id);
                if ($_e8d840684607f6c2bbef523090642168->parent_id === 0) {
                    
                    
                    $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::TASK_DISCUSSION_POSTED, new ProjectEvent($_e8d840684607f6c2bbef523090642168));
                } else {
                    
                    
                    $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::TASK_REPLY_POSTED, new ProjectEvent($_e8d840684607f6c2bbef523090642168));
                }
                $_e62ca7bbb93b52cafc82da1c2aefe9ec->stopPropagation();
                break;
        }
    }
    public function CommentDeletedEventReceiver(CommentDeletedEvent $_e62ca7bbb93b52cafc82da1c2aefe9ec)
    {
        
        
        $_e8d840684607f6c2bbef523090642168 = $_e62ca7bbb93b52cafc82da1c2aefe9ec->getComment();
        switch ($_e8d840684607f6c2bbef523090642168->aggregation) {
            case Permissions::TASK_AGGREGATION:
                $this->task_repository->DecrementCommentCount($_e8d840684607f6c2bbef523090642168->object_id);
                $_e62ca7bbb93b52cafc82da1c2aefe9ec->stopPropagation();
                break;
        }
    }
    public function CommentAttachmentsAddedEventReceiver(CommentAttachmentsAddedEvent $_e62ca7bbb93b52cafc82da1c2aefe9ec, $_5693d84b45564f912e36404cbe8957e8, EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        $_4e7ab34a53ffb13eb0838003f33034d4 = $_e62ca7bbb93b52cafc82da1c2aefe9ec->GetAttachments();
        $_e8d840684607f6c2bbef523090642168 = $_e62ca7bbb93b52cafc82da1c2aefe9ec->GetComment();
        
        
        $_2d876b122533fac9677b16ea6c640aa6 = $_e8d840684607f6c2bbef523090642168->GetProperty($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_2d876b122533fac9677b16ea6c64" . "0aa6"]);
        $_696b535739055ed7d827709916d07dea = null;
        $_0a3f284de65e596869ef47aa9e91f906 = null;
        switch ($_e8d840684607f6c2bbef523090642168->GetProperty($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_699cd46f386ae1974722616" . "ce651a3a1"])) {
            case Permissions::TASK_AGGREGATION:
                $_696b535739055ed7d827709916d07dea = $this->task_repository->LoadTask($_2d876b122533fac9677b16ea6c640aa6);
                $_db618ca8e79f97b4dff753ec837942cf = $_696b535739055ed7d827709916d07dea->GetProject();
                $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($_db618ca8e79f97b4dff753ec837942cf);
                break;
            case Topic::AGGREGATION:
                $_9a3559422c29efc571cba589ffa1a59f = $this->topic_repository->findOrFail($_2d876b122533fac9677b16ea6c640aa6);
                $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($_9a3559422c29efc571cba589ffa1a59f->project_id);
                break;
            default:
                
                
                return;
        }
        $_00f2055c7cbd408ef56949f35c62b721 = array();
        foreach ($_4e7ab34a53ffb13eb0838003f33034d4 as $_5feede65e7cfe8f0b3d9854c0363d548) {
            
            
            $_dadf790baf241afac942824c1e6e37c4 = $_5feede65e7cfe8f0b3d9854c0363d548->GetProperty($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_dadf790baf241afac942824c" . "1e6e37c4"]);
            if ($_dadf790baf241afac942824c1e6e37c4 != Attachment::TYPE_FILE) {
                continue;
            }
            if ($_696b535739055ed7d827709916d07dea === null) {
                $_09f61d3133f39f8e5aff0eb6a7d185a1 = $this->files_service->CopyCommentFileToProject($_5feede65e7cfe8f0b3d9854c0363d548, $_0a3f284de65e596869ef47aa9e91f906);
            } else {
                try {
                    $_09f61d3133f39f8e5aff0eb6a7d185a1 = $this->files_service->CopyCommentFileToTask($_5feede65e7cfe8f0b3d9854c0363d548, $_696b535739055ed7d827709916d07dea, $_0a3f284de65e596869ef47aa9e91f906);
                } catch (ProjectsFolderException $_c35473364fa7a050299058f332ec29c1) {
                    continue;
                }
            }
            $_00f2055c7cbd408ef56949f35c62b721[] = $_09f61d3133f39f8e5aff0eb6a7d185a1;
        }
        $this->files_service->SendNotifications();
        
        
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_31767d7ad58e706dbf47b" . "7a51a0fe6c4"]($_00f2055c7cbd408ef56949f35c62b721) === 0) {
            return;
        }
        if ($_696b535739055ed7d827709916d07dea === null) {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_e06da3ffba2e84b8e6f94bd2d6" . "ca3c52"]($_0a3f284de65e596869ef47aa9e91f906->GetUrl());
        } else {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_e06da3ffba2e84b8e6f9" . "4bd2d6ca3c52"]($_696b535739055ed7d827709916d07dea->GetUrl());
        }
        $_8248f758e7baf777ae70aa7fe7eb48d0 = array();
        
        
        foreach ($_00f2055c7cbd408ef56949f35c62b721 as $_6ae3783b9ad544a6c31a979683fed870) {
            $_8248f758e7baf777ae70aa7fe7eb48d0[] = array($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_077e27168" . "673cad4e72" . "653c873012" . "9b5"] => $_6ae3783b9ad544a6c31a979683fed870->GetTitle(), $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_c927258f5322288a" . "992c77be40ae0b53"] => $_6ae3783b9ad544a6c31a979683fed870->GetDetailsURL(true));
        }
        
        
        $_a71dc9333bd8ad95d55d6624b477875f = array($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_db618ca8e79f97b4dff753e" . "c837942cf"] => $_0a3f284de65e596869ef47aa9e91f906->GetId(), $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_e3037a4609adf1f69b" . "1e8dc9813b51ec"] => $_696b535739055ed7d827709916d07dea !== null ? $_696b535739055ed7d827709916d07dea->GetId() : 0, $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_00f2055c7cbd408" . "ef56949f35c62b72" . "1"] => $_8248f758e7baf777ae70aa7fe7eb48d0, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_3877cdf57a61e49b56aeab7af93" . "0ee82"] => $this->context->GetUserId(), $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_c927258f5322288a992c77be" . "40ae0b53"] => $_c927258f5322288a992c77be40ae0b53, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_93939227a8e7cf780" . "efaa642c3da9723"] => \AuthUser::I()->GetId());
        $_e62ca7bbb93b52cafc82da1c2aefe9ec->stopPropagation();
        $_e62ca7bbb93b52cafc82da1c2aefe9ec = new ProjectEvent($_a71dc9333bd8ad95d55d6624b477875f);
        if ($_696b535739055ed7d827709916d07dea === null) {
            $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::PROJECT_FILE_ADDED, $_e62ca7bbb93b52cafc82da1c2aefe9ec);
        } else {
            $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::TASK_FILE_ADDED, $_e62ca7bbb93b52cafc82da1c2aefe9ec);
        }
    }
}