<?php
namespace Claromentis\Core\Like;

$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] ?: array()) + array("_93bec24a59dadcc3a55385646772" . "4049" => base64_decode("aW50Om9iamVjdF" . "9pZA=="), "_c1044b3e91ab3b7929e6d9a52f0a" . "50a2" => base64_decode("U0VMRUNUIDEgRlJPTSBsaWtlcyBXSEVSRSBhZ2dyZWdhdGlvbj1pbnQ6YWdnci" . "BBTkQgb2JqZWN0X2lkPWludDpvYmpfaWQgQU5EIHVzZXJfaWQ9aW50OnVzZXJf" . "aWQ="), "obje" . "ct_i" . "d" => base64_decode("b2JqZWN0X2" . "lk"), "_c86eb9efd8b83325ef89" . "5e88008c98d0" => base64_decode("aW50OnRpbWVzdGFtcA=" . "="), "li" . "ke" . "s" => base64_decode("bGlr" . "ZXM="), "_51bf540348e5076" . "36961ac634c59299" . "3" => base64_decode("U0VMRUNUICogRlJPTSBsaWtlcyBXSEVSRSBhZ2dyZWdhdGlvbj1pbnQ6YWdnciBBTkQgb2JqZWN" . "0X2lkPWludDpvYmpfaWQgT1JERVIgQlkgdGltZXN0YW1wIERFU0M="), "_9b632c465856330aeeee43d21dc50ac" . "b" => base64_decode("aW50OmFnZ3JlZ2F0a" . "W9u"), "_0877a0b48cf424a0de57a453ce95e3" . "0c" => base64_decode("aW50OnVz" . "ZXJfaWQ="), "_e786f0e5984098" . "782291a9a32af94" . "1b2" => base64_decode("REVMRVRFIEZST00gbGlrZXMgV0hFUkUg" . "dXNlcl9pZD1pbnQ6dXNlcl9pZA=="), "aggre" . "gatio" . "n" => base64_decode("YWdncmVnY" . "XRpb24="), "_54835c417c3" . "9e87e647408c" . "531372f2d" => base64_decode("REVMRVRFIEZST00gbGlrZXMgV0hFUkUgYWdncmVnYX" . "Rpb249aW50OmFnZ3IgQU5EIG9iamVjdF9pZD1pbnQ6" . "b2JqX2lk"), "_4f9cf2ae36d800102" . "b93b3f07b8f9df1" => base64_decode("U0VMRUNUIENPVU5UKDEpIEZST00gbGlrZXMg" . "V0hFUkUgYWdncmVnYXRpb249aW50OmFnZ3Ig" . "QU5EIG9iamVjdF9pZD1pbnQ6b2JqX2lk"), "_02d68192f5" . "68a0a76fed7" . "90d96d93318" => base64_decode("REVMRVRFIEZST00gbGlrZXMgV0hFUkUgdXNlcl9pZCA9IGludDp1c2VyaWQgQU5EIG" . "9iamVjdF9pZCA9IGludDpvYmplY3RpZCBBTkQgYWdncmVnYXRpb24gPSBpbnQ6YWdn"), "_3877cdf57a61e49b56aeab7af930ee8" . "2" => base64_decode("dXNlcl9pZA" . "=="));
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, $_3877cdf57a61e49b56aeab7af930ee82)
    {
        if ($this->IsLiked($aggregation, $object_id, $_3877cdf57a61e49b56aeab7af930ee82)) {
            return;
        }
        $this->db->query(new DAL\QueryInsert($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["lik" . "es"], [$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_9b632c4658563" . "30aeeee43d21dc" . "50acb"] => $aggregation, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_93bec24a59dadcc3" . "a553856467724049"] => $object_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_0877a0b48cf424a0de57a453ce95e30" . "c"] => $_3877cdf57a61e49b56aeab7af930ee82, $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_c86eb9efd8b83325ef895e88008c9" . "8d0"] => \Date::getNowTimestamp()]));
        $event = new GenericEvent(null, [$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["aggr" . "egat" . "ion"] => $aggregation, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["object_" . "id"] => $object_id, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_3877cdf57a" . "61e49b56aea" . "b7af930ee82"] => $_3877cdf57a61e49b56aeab7af930ee82]);
        $this->dispatcher->dispatch(LikeEvents::OBJECT_LIKED, $event);
    }
    public function Remove($aggregation, $object_id, $_3877cdf57a61e49b56aeab7af930ee82)
    {
        if (!$this->IsLiked($aggregation, $object_id, $_3877cdf57a61e49b56aeab7af930ee82)) {
            return;
        }
        $this->db->query($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_02d68192f568a0a76fed" . "790d96d93318"], $_3877cdf57a61e49b56aeab7af930ee82, $object_id, $aggregation);
        $event = new GenericEvent(null, [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["aggr" . "egat" . "ion"] => $aggregation, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["object_" . "id"] => $object_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_3877cdf57" . "a61e49b56a" . "eab7af930e" . "e82"] => $_3877cdf57a61e49b56aeab7af930ee82]);
        $this->dispatcher->dispatch(LikeEvents::OBJECT_UNLIKED, $event);
    }
    
    
    
    
    
    
    
    
    
    public function IsLiked($aggregation, $object_id, $_3877cdf57a61e49b56aeab7af930ee82)
    {
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_c1044b3e91ab3b7929e6d9a52" . "f0a50a2"], (int) $aggregation, (int) $object_id, (int) $_3877cdf57a61e49b56aeab7af930ee82);
        return $_189840d11056515e52402d1412a0b6e4->hasData();
    }
    
    
    
    
    
    
    
    
    public function GetCount($aggregation, $object_id)
    {
        list($_f53d35a1a1e233d98d9ce73d92ab3bb1) = $this->db->query_row($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_4f9cf2ae36d800102b93b3" . "f07b8f9df1"], $aggregation, $object_id);
        return $_f53d35a1a1e233d98d9ce73d92ab3bb1;
    }
    
    
    
    
    
    
    
    public function DeleteByObject($aggregation, $object_id)
    {
        $this->db->query($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_54835c417c39e87e647408c531" . "372f2d"], $aggregation, $object_id);
    }
    
    
    
    
    
    
    public function DeleteByUser($_3877cdf57a61e49b56aeab7af930ee82)
    {
        $this->db->query($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_e786f0e598409" . "8782291a9a32af" . "941b2"], $_3877cdf57a61e49b56aeab7af930ee82);
    }
    
    
    
    
    
    
    
    public function GetLikes($aggregation, $object_id, $_f11369824f533e8206f9ccc0c9aab3a0 = 50, $_1f50e30be8c2fefa6881834e71d504a2 = 0)
    {
        $_7f5aa4e96d4b415a86ed72ebff677cbe = new DAL\Query($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_51bf540348e507636961ac634c" . "592993"], $aggregation, $object_id);
        $_7f5aa4e96d4b415a86ed72ebff677cbe->setLimit($_f11369824f533e8206f9ccc0c9aab3a0, $_1f50e30be8c2fefa6881834e71d504a2);
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query($_7f5aa4e96d4b415a86ed72ebff677cbe);
        $_40d3655ba45c47853ff1adcc6921cb45 = [];
        while ($_343a395319323dd7609bcbc465b4d034 = $_189840d11056515e52402d1412a0b6e4->fetchArray()) {
            $_40d3655ba45c47853ff1adcc6921cb45[] = $_343a395319323dd7609bcbc465b4d034;
        }
        return $_40d3655ba45c47853ff1adcc6921cb45;
    }
}