<?php
namespace Claromentis\Projects\Comments;

$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] ?: array()) + array("_e06da3ff" . "ba2e84b8e" . "6f94bd2d6" . "ca3c52" => base64_decode("Y3JlYXRl" . "X2ludGVy" . "bmFsX2xp" . "bms="), "_077e27168673cad4e72653c873012" . "9b5" => base64_decode("Zmls" . "ZW5h" . "bWU="), "_d50d529d5739d103bc48e" . "65a4b513fe3" => base64_decode("Q29tbWVudEFkZGVk" . "RXZlbnRSZWNlaXZl" . "cg=="), "_3877cdf57a61e49b56aeab7af" . "930ee82" => base64_decode("dXNlcl9pZ" . "A=="), "_c927258" . "f5322288" . "a992c77b" . "e40ae0b5" . "3" => base64_decode("d" . "X" . "J" . "s"), "_db618ca8e79f97b4dff753ec837" . "942cf" => base64_decode("cHJvamVjdF9pZA" . "=="), "_76b1e0edd97786ed9ddb7b7f6" . "083c218" => base64_decode("cHJvamVjdHMucHJv" . "amVjdHNfcHJvdmlk" . "ZXI="), "_e3037a4609adf1f69b1e8dc9813b" . "51ec" => base64_decode("dGFza19p" . "ZA=="), "_31767d7ad58e706dbf47b" . "7a51a0fe6c4" => base64_decode("Y291bnQ" . "="), "_dadf790" . "baf241af" . "ac942824" . "c1e6e37c" . "4" => base64_decode("dHlwZ" . "Q=="), "_9bb5cca7404240f9068ffc9838b7" . "7be1" => base64_decode("Q29tbWVudEF0dGFjaG1lbnRzQWRkZWR" . "FdmVudFJlY2VpdmVy"), "_699cd46f386" . "ae1974722616" . "ce651a3a1" => base64_decode("YWdncmVnYXRpb" . "24="), "_93939227a" . "8e7cf780ef" . "aa642c3da9" . "723" => base64_decode("YnlfdXNlcl9" . "pZA=="), "_191a9c694701b5e98f9" . "b02b73105f5cf" => base64_decode("Q29tbWVudERlbG" . "V0ZWRFdmVudFJl" . "Y2VpdmVy"), "_2d876b122" . "533fac9677" . "b16ea6c640" . "aa6" => base64_decode("b2JqZWN0" . "X2lk"), "_00f2055c7cbd408ef56949f35c62" . "b721" => base64_decode("ZmlsZ" . "XM="));
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"]["_d50d529d" . "5739d103b" . "c48e65a4b" . "513fe3"], CommentDeletedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_191a9c694701b5e98f9b0" . "2b73105f5cf"], CommentAttachmentsAddedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_9bb5cca7404240f9068ffc9838" . "b77be1"]];
    }
    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["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_76b1e0edd97786ed9ddb7b" . "7f6083c218"]};
                $_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["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_2d876b122533fac9677b16ea6c64" . "0aa6"]);
        $_696b535739055ed7d827709916d07dea = null;
        $_0a3f284de65e596869ef47aa9e91f906 = null;
        switch ($_e8d840684607f6c2bbef523090642168->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_699cd46f386" . "ae1974722616" . "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["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_dadf790baf241afac942824c1e" . "6e37c4"]);
            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["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_31767d7ad58e706dbf47b7a51a0" . "fe6c4"]($_00f2055c7cbd408ef56949f35c62b721) === 0) {
            return;
        }
        if ($_696b535739055ed7d827709916d07dea === null) {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_e06da3ffba" . "2e84b8e6f94" . "bd2d6ca3c52"]($_0a3f284de65e596869ef47aa9e91f906->GetUrl());
        } else {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_e06da3ffba2e84b8e6f94bd2d6ca3" . "c52"]($_696b535739055ed7d827709916d07dea->GetUrl());
        }
        $_8248f758e7baf777ae70aa7fe7eb48d0 = array();
        
        
        foreach ($_00f2055c7cbd408ef56949f35c62b721 as $_6ae3783b9ad544a6c31a979683fed870) {
            $_8248f758e7baf777ae70aa7fe7eb48d0[] = array($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_077e27168673cad4e" . "72653c8730129b5"] => $_6ae3783b9ad544a6c31a979683fed870->GetTitle(), $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_c927258f5322288a992c77b" . "e40ae0b53"] => $_6ae3783b9ad544a6c31a979683fed870->GetDetailsURL(true));
        }
        
        
        $_a71dc9333bd8ad95d55d6624b477875f = array($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_db618ca8e" . "79f97b4dff" . "753ec83794" . "2cf"] => $_0a3f284de65e596869ef47aa9e91f906 !== null ? $_0a3f284de65e596869ef47aa9e91f906->GetId() : 0, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_e3037a4" . "609adf1f" . "69b1e8dc" . "9813b51e" . "c"] => $_696b535739055ed7d827709916d07dea !== null ? $_696b535739055ed7d827709916d07dea->GetId() : 0, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_00f2055c7cbd408ef" . "56949f35c62b721"] => $_8248f758e7baf777ae70aa7fe7eb48d0, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_3877cdf57" . "a61e49b56a" . "eab7af930e" . "e82"] => $this->context->GetUserId(), $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_c927258f5322" . "288a992c77be4" . "0ae0b53"] => $_c927258f5322288a992c77be40ae0b53, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_93939227a" . "8e7cf780ef" . "aa642c3da9" . "723"] => \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);
        }
    }
}