<?php
namespace Claromentis\Projects\Comments;

$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] = (@$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] ?: array()) + array("_db618ca8e79f97b4dff753ec" . "837942cf" => base64_decode("cHJvamVjdF9" . "pZA=="), "_e3037a4609adf1f69b1e" . "8dc9813b51ec" => base64_decode("dGFz" . "a19p" . "ZA=="), "_76b1e0e" . "dd97786e" . "d9ddb7b7" . "f6083c21" . "8" => base64_decode("cHJvamVjdHMucHJvamVjdHNf" . "cHJvdmlkZXI="), "_e06da3ffba2e84b8e6f94bd2d6c" . "a3c52" => base64_decode("Y3JlYXRlX2lud" . "GVybmFsX2xpbm" . "s="), "_699cd46f386ae197" . "4722616ce651a3a1" => base64_decode("YWdncmVnYXRpb" . "24="), "_93939227a8e7cf780e" . "faa642c3da9723" => base64_decode("YnlfdXNlcl" . "9pZA=="), "_2d876b122533fac9677b16" . "ea6c640aa6" => base64_decode("b2JqZWN0X" . "2lk"), "_191a9c694701b5" . "e98f9b02b73105f" . "5cf" => base64_decode("Q29tbWVudERlbGV0ZWRFdmVudFJ" . "lY2VpdmVy"), "_00f2055c7cbd40" . "8ef56949f35c62b" . "721" => base64_decode("Zm" . "ls" . "ZX" . "M="), "_d50d529d5739d103bc48e65a4b513" . "fe3" => base64_decode("Q29tbWVudEFkZGVkRXZlbnRSZ" . "WNlaXZlcg=="), "_3877cdf57a61e49b56aeab7af930e" . "e82" => base64_decode("dXNlcl9pZ" . "A=="), "_31767d7ad58" . "e706dbf47b7a" . "51a0fe6c4" => base64_decode("Y291bn" . "Q="), "_c927258f" . "5322288a9" . "92c77be40" . "ae0b53" => base64_decode("dXJ" . "s"), "_9bb5cca7404240f9068ffc9838" . "b77be1" => base64_decode("Q29tbWVudEF0dGFjaG1lbn" . "RzQWRkZWRFdmVudFJlY2Vp" . "dmVy"), "_dadf790baf241afac9" . "42824c1e6e37c4" => base64_decode("dHlwZ" . "Q=="), "_077e271" . "68673cad" . "4e72653c" . "8730129b" . "5" => base64_decode("ZmlsZW" . "5hbWU="));
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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_d50d529d5739d103bc48" . "e65a4b513fe3"], CommentDeletedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_191a9c694701b" . "5e98f9b02b7310" . "5f5cf"], CommentAttachmentsAddedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_9bb5cca7404240f9068f" . "fc9838b77be1"]];
    }
    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["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_76b1e0edd97786ed9ddb7b7f608" . "3c218"]};
                $_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["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_2d876b122533fac9677b16ea6c6" . "40aa6"]);
        $_696b535739055ed7d827709916d07dea = null;
        $_0a3f284de65e596869ef47aa9e91f906 = null;
        switch ($_e8d840684607f6c2bbef523090642168->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_699cd46f386ae1974722616ce651" . "a3a1"])) {
            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["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_dadf790baf24" . "1afac942824c1" . "e6e37c4"]);
            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["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_31767d7" . "ad58e706" . "dbf47b7a" . "51a0fe6c" . "4"]($_00f2055c7cbd408ef56949f35c62b721) === 0) {
            return;
        }
        if ($_696b535739055ed7d827709916d07dea === null) {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_e06da3f" . "fba2e84b" . "8e6f94bd" . "2d6ca3c5" . "2"]($_0a3f284de65e596869ef47aa9e91f906->GetUrl());
        } else {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_e06da3ffba2e84b8e6f94bd2d6ca3c5" . "2"]($_696b535739055ed7d827709916d07dea->GetUrl());
        }
        $_8248f758e7baf777ae70aa7fe7eb48d0 = array();
        
        
        foreach ($_00f2055c7cbd408ef56949f35c62b721 as $_6ae3783b9ad544a6c31a979683fed870) {
            $_8248f758e7baf777ae70aa7fe7eb48d0[] = array($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_077e27168673c" . "ad4e72653c8730" . "129b5"] => $_6ae3783b9ad544a6c31a979683fed870->GetTitle(), $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_c927258f5322288a992c77b" . "e40ae0b53"] => $_6ae3783b9ad544a6c31a979683fed870->GetDetailsURL(true));
        }
        
        
        $_a71dc9333bd8ad95d55d6624b477875f = array($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_db618ca8e7" . "9f97b4dff75" . "3ec837942cf"] => $_0a3f284de65e596869ef47aa9e91f906 !== null ? $_0a3f284de65e596869ef47aa9e91f906->GetId() : 0, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_e3037a4609adf1f69b1" . "e8dc9813b51ec"] => $_696b535739055ed7d827709916d07dea !== null ? $_696b535739055ed7d827709916d07dea->GetId() : 0, $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_00f2055c7" . "cbd408ef56" . "949f35c62b" . "721"] => $_8248f758e7baf777ae70aa7fe7eb48d0, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_3877cdf57a61e49b56aeab7a" . "f930ee82"] => $this->context->GetUserId(), $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_c927258f5322288" . "a992c77be40ae0b5" . "3"] => $_c927258f5322288a992c77be40ae0b53, $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_93939227a8e7cf780efaa" . "642c3da9723"] => \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);
        }
    }
}