<?php
namespace Claromentis\Core\Like;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"] = (@$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] ?: array()) + array("_4f9cf2a" . "e36d8001" . "02b93b3f" . "07b8f9df" . "1" => base64_decode("U0VMRUNUIENPVU5UKDEpIEZST00gbG" . "lrZXMgV0hFUkUgYWdncmVnYXRpb249" . "aW50OmFnZ3IgQU5EIG9iamVjdF9pZD" . "1pbnQ6b2JqX2lk"), "_93bec24a59da" . "dcc3a55385646" . "7724049" => base64_decode("aW50Om9iamVjdF9" . "pZA=="), "_51bf540348e50763696" . "1ac634c592993" => base64_decode("U0VMRUNUICogRlJPTSBsaWtlcyBXSEVSRSBhZ2dyZWdhdGlvbj1pbnQ6YWdnci" . "BBTkQgb2JqZWN0X2lkPWludDpvYmpfaWQgT1JERVIgQlkgdGltZXN0YW1wIERF" . "U0M="), "like" . "s" => base64_decode("bGl" . "rZX" . "M="), "_c86eb9efd8" . "b83325ef895" . "e88008c98d0" => base64_decode("aW50On" . "RpbWVz" . "dGFtcA" . "=="), "ob" . "je" . "ct" . "_i" . "d" => base64_decode("b2JqZW" . "N0X2lk"), "_e786f0e59" . "8409878229" . "1a9a32af94" . "1b2" => base64_decode("REVMRVRFIEZST00gbGlr" . "ZXMgV0hFUkUgdXNlcl9p" . "ZD1pbnQ6dXNlcl9pZA=="), "_54835c417c39e87e647408c531372" . "f2d" => base64_decode("REVMRVRFIEZST00gbGlrZXMgV" . "0hFUkUgYWdncmVnYXRpb249aW" . "50OmFnZ3IgQU5EIG9iamVjdF9" . "pZD1pbnQ6b2JqX2lk"), "_9b632c465856330aeeee43d" . "21dc50acb" => base64_decode("aW50O" . "mFnZ3" . "JlZ2F" . "0aW9u"), "_0877a0b48cf424" . "a0de57a453ce95e" . "30c" => base64_decode("aW50" . "OnVz" . "ZXJf" . "aWQ="), "user_" . "id" => base64_decode("dXN" . "lcl" . "9pZ" . "A=="), "_c1044b3e91ab3b7929e6d9a52f0a5" . "0a2" => base64_decode("U0VMRUNUIDEgRlJPTSBsaWtlcyBXSEVSRSBhZ2dyZWdhdGlvbj1pbnQ6YWdnciBBTkQgb2" . "JqZWN0X2lkPWludDpvYmpfaWQgQU5EIHVzZXJfaWQ9aW50OnVzZXJfaWQ="), "aggre" . "gatio" . "n" => base64_decode("YWdnc" . "mVnYX" . "Rpb24" . "="), "_02d68192f568a0a76fed790d96d933" . "18" => base64_decode("REVMRVRFIEZST00gbGlrZXMgV0hFUkUgdX" . "Nlcl9pZCA9IGludDp1c2VyaWQgQU5EIG9i" . "amVjdF9pZCA9IGludDpvYmplY3RpZCBBTk" . "QgYWdncmVnYXRpb24gPSBpbnQ6YWdn"));
use Claromentis\Core\DAL;
use Claromentis\Core\Event\EventDispatcher;
use Claromentis\Core\Event\GenericEvent;




class LikesRepository
{
    
    
    
    
    protected $dispatcher;
    
    
    
    
    private $db;
    
    
    
    
    public function __construct(DAL\Db $db, EventDispatcher $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        $this->db = $db;
        $this->dispatcher = $_b497ce6f2af10f67516aed0ecf34d8cf;
    }
    
    
    
    
    
    
    
    
    public function Add($aggregation, $object_id, $user_id)
    {
        if ($this->IsLiked($aggregation, $object_id, $user_id)) {
            return;
        }
        $this->db->query(new DAL\QueryInsert($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["like" . "s"], [$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_9b632c465856330aeeee43d21" . "dc50acb"] => $aggregation, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_93bec24a59dad" . "cc3a5538564677" . "24049"] => $object_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_0877a0b48cf424a0de57a453ce9" . "5e30c"] => $user_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_c86eb9efd8b83325ef895e88" . "008c98d0"] => \Date::getNowTimestamp()]));
        $event = new GenericEvent(null, [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["aggre" . "gatio" . "n"] => $aggregation, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["object" . "_id"] => $object_id, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["user_" . "id"] => $user_id]);
        $this->dispatcher->dispatch(LikeEvents::OBJECT_LIKED, $event);
    }
    public function Remove($aggregation, $object_id, $user_id)
    {
        if (!$this->IsLiked($aggregation, $object_id, $user_id)) {
            return;
        }
        $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_02d68192f568a0a76fed790d96d" . "93318"], $user_id, $object_id, $aggregation);
        $event = new GenericEvent(null, [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["aggreg" . "ation"] => $aggregation, $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["object_i" . "d"] => $object_id, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["us" . "er" . "_i" . "d"] => $user_id]);
        $this->dispatcher->dispatch(LikeEvents::OBJECT_UNLIKED, $event);
    }
    
    
    
    
    
    
    
    
    
    public function IsLiked($aggregation, $object_id, $user_id)
    {
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_c1044b3e91ab3b" . "7929e6d9a52f0a5" . "0a2"], (int) $aggregation, (int) $object_id, (int) $user_id);
        return $_189840d11056515e52402d1412a0b6e4->hasData();
    }
    
    
    
    
    
    
    
    
    public function GetCount($aggregation, $object_id)
    {
        list($_f53d35a1a1e233d98d9ce73d92ab3bb1) = $this->db->query_row($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_4f9cf2ae36d800102b93b3f0" . "7b8f9df1"], $aggregation, $object_id);
        return $_f53d35a1a1e233d98d9ce73d92ab3bb1;
    }
    
    
    
    
    
    
    
    public function DeleteByObject($aggregation, $object_id)
    {
        $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_54835c417c3" . "9e87e647408c" . "531372f2d"], $aggregation, $object_id);
    }
    
    
    
    
    
    
    public function DeleteByUser($user_id)
    {
        $this->db->query($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_e786f0e" . "59840987" . "82291a9a" . "32af941b" . "2"], $user_id);
    }
    
    
    
    
    
    
    
    public function GetLikes($aggregation, $object_id, $_f11369824f533e8206f9ccc0c9aab3a0 = 50, $_1f50e30be8c2fefa6881834e71d504a2 = 0)
    {
        $_7f5aa4e96d4b415a86ed72ebff677cbe = new DAL\Query($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_51bf540348e507636961ac634c" . "592993"], $aggregation, $object_id);
        $_7f5aa4e96d4b415a86ed72ebff677cbe->setLimit($_f11369824f533e8206f9ccc0c9aab3a0, $_1f50e30be8c2fefa6881834e71d504a2);
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query($_7f5aa4e96d4b415a86ed72ebff677cbe);
        $_40d3655ba45c47853ff1adcc6921cb45 = [];
        while ($_343a395319323dd7609bcbc465b4d034 = $_189840d11056515e52402d1412a0b6e4->fetchArray()) {
            $_40d3655ba45c47853ff1adcc6921cb45[] = $_343a395319323dd7609bcbc465b4d034;
        }
        return $_40d3655ba45c47853ff1adcc6921cb45;
    }
}