<?php
namespace Claromentis\Quiz\Search\Indexing;

$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"] ?: array()) + array("_4d707fab93bebb" . "00bbe69e8159697" . "c90" => base64_decode(""), "_feb90375891" . "81bc30fa0f1c" . "f78b9f056" => base64_decode("dGl0" . "bGU="), "_d0acf63c20abded6f7458ea8e700" . "9e96" => base64_decode("SW5zdHJ1Y3Rpb24gb2JqZWN0IElE" . "IG5vdCBmb3VuZCBmb3IgUXVpeg=="), "_dadf790baf241afa" . "c942824c1e6e37c4" => base64_decode("dHlwZQ=" . "="), "_7aefd482de7885f4293c2926d" . "f28c235" => base64_decode("anNvbl9" . "lbmNvZG" . "U="), "_ab8199b97ed2d8fa1f" . "096f35efbbe647" => base64_decode("L3BvbGxzLXN1c" . "nZleXMvcG9sbC" . "8="), "_809a58dc73011173c031a53c" . "0b40ef0e" => base64_decode("cHJvc" . "GVydG" . "llcw=" . "="), "_8e7f4b5c" . "8440c0a24" . "fb1b632ee" . "e28538" => base64_decode("YWN0aW" . "9u"), "_8e7b0b07b8da9d5cbd" . "9a41129b629400" => base64_decode("ZGF0ZV" . "9kZXRl" . "Y3Rpb2" . "4="), "_aa7e860da1acd4" . "e767e0df9d7d407" . "380" => base64_decode("ZGF0ZV9jcmVhd" . "GVk"), "_9ea10b1280f50314a9d1" . "8333d6d18d4f" => base64_decode("cXVpei9wb2xsL2N" . "vdmVycw=="), "_b0eaaa9541f479b4891f61611174" . "37b9" => base64_decode("cXVldWVfZnVsbF9yZWluZGV" . "4"), "per" . "mis" . "sio" . "ns" => base64_decode("cGVybWlzc2lvbn" . "M="), "_d43b1a8" . "85195a4b" . "6ccc7d38" . "ba3fcb1f" . "9" => base64_decode("Z2x5cG" . "hpY29u"), "_6ebc0afe64bb119" . "ce3df66d2745d8c3" . "8" => base64_decode("IGlzIG5vdCBMaXZlLCBzbyBpdCB3aWxsIG5vdCBiZSBpbmRleGV" . "k"), "_19a7dfbfa05ce488f968b8580e2d6" . "185" => base64_decode("UG9sbCB3aX" . "RoIElEIA=="), "_646df530340668323d9a8e6c9204" . "fe75" => base64_decode("aW1hZ2Vfc3" . "Jj"), "_695b93f9bbf781be992587b4e62" . "ec823" => base64_decode("UG9sb" . "CA="), "_31767d7" . "ad58e706" . "dbf47b7a" . "51a0fe6c" . "4" => base64_decode("Y291" . "bnQ="), "_74d41404196" . "e33a2a11ac3f" . "813c155b7" => base64_decode("Z2x5cGhpY29ucyBnbHlwaG" . "ljb25zLXBvbGxzLXN1cnZl" . "eQ=="), "_99cee2d2272a8" . "550f4b21e3cb57" . "fff7d" => base64_decode("ZW5" . "hYm" . "xlZ" . "A=="), "_66824e0309bb76c78bd2" . "bbd5fda8d3d8" => base64_decode("c3RyaW" . "5n"), "_f73dab606630b388645c4" . "f7d3fbb13bb" => base64_decode("YXJyYXlfbWV" . "yZ2U="), "_db694a72c731761cffae60" . "60e4b092bc" => base64_decode("VW5rbm93biBzcGVjaWFsIGFjdGlvbiBmb3Ig" . "U3VydmV5IGluZGV4aW5nOiA="), "_fa96cdf" . "58bff3b0" . "695fb2bc" . "0803d7b1" . "2" => base64_decode("IGRvZXMgbm90IGV4aX" . "N0"), "_d34599daeb8cca3" . "74d3adb38b245839" . "c" => base64_decode("Y29" . "udG" . "Vud" . "HM="), "_33de78378f32407b852c241ec52f9a" . "35" => base64_decode("aH" . "Jl" . "Zg" . "=="), "_8ac93b484d7470c59e32762" . "0646e2d1e" => base64_decode("X3NvdXJ" . "jZQ=="), "_b15aac3aa29c10ea6d1228f58c" . "b9a7e8" => base64_decode("b2JqZWN" . "0"));
use Claromentis\Core\Acl\Acl;
use Claromentis\Core\Acl\AclRepository;
use Claromentis\Core\Acl\PermOClass;
use Claromentis\Core\CDN\CDNInterface;
use Claromentis\Core\Repository\Exception\NotFoundException;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Quiz\Facade\PollFacade;
use Claromentis\Quiz\Model\Poll;
use Claromentis\Quiz\Model\Question;
use Claromentis\Quiz\Permissions\PollPermissions;
use Claromentis\Quiz\Permissions\QuizAdminPermissions;
use Claromentis\Quiz\Permissions\QuizPermissions;
use Claromentis\Quiz\Permissions\SurveyAdminPermissions;
use Claromentis\Quiz\Repository\PollRepository;
use Claromentis\Quiz\Repository\QuizRepository;
use Claromentis\Search\FieldType\TypeContents;
use Claromentis\Search\FieldType\TypeDate;
use Claromentis\Search\Indexing\Client\ClientInterface;
use Claromentis\Search\Indexing\Exception\IndexingException;
use Claromentis\Search\Indexing\Exception\NothingToIndexException;
use Claromentis\Search\Indexing\Exception\ObjectNotFoundException;
use Claromentis\Search\Indexing\Exception\UnsupportedOperationException;
use Claromentis\Search\Indexing\IndexingInstruction;
use Claromentis\Search\Indexing\IndexingItemInterface;
use Claromentis\Search\Indexing\IndexingQueue;
use Claromentis\Search\Permissions as SearchPermissions;
use ClaText;
use Permissions;




class PollIndexing implements IndexingItemInterface
{
    const TYPE_NAME = 'poll';
    
    
    protected $cdn;
    
    
    protected $cla_text;
    protected $poll_repo;
    protected $survey_admin_permissions;
    protected $poll_facade;
    public function __construct(CDNInterface $cdn, \Claromentis\Core\TextUtil\ClaText $cla_text, PollRepository $poll_repo, SurveyAdminPermissions $survey_admin_permissions, PollFacade $poll_facade)
    {
        $this->cdn = $cdn;
        $this->cla_text = $cla_text;
        $this->poll_repo = $poll_repo;
        $this->survey_admin_permissions = $survey_admin_permissions;
        $this->poll_facade = $poll_facade;
    }
    
    
    
    
    
    
    public function InitMapping(ClientInterface $_87419315d6aaaec7dd2250b14245566e)
    {
        $_87419315d6aaaec7dd2250b14245566e->AddMapping(self::TYPE_NAME, [$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8ac93b4" . "84d7470c" . "59e32762" . "0646e2d1" . "e"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_99cee2d2272a8550f4b21e3cb57" . "fff7d"] => true], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_8e7b0b07b8da9d5c" . "bd9a41129b629400"] => true, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_809a58dc73011173c031a53c0b4" . "0ef0e"] => [$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_feb903758" . "9181bc30fa" . "0f1cf78b9f" . "056"] => [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_dadf790baf241afac94" . "2824c1e6e37c4"] => $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_66824e0309bb76c78bd2bbd" . "5fda8d3d8"]], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_33de78378f32407b852c241ec52" . "f9a35"] => [$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_dadf790baf2" . "41afac942824" . "c1e6e37c4"] => $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_66824e0309bb76c78bd2" . "bbd5fda8d3d8"], $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_99cee2d2272a8550f4b21e3c" . "b57fff7d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_646df5303406683" . "23d9a8e6c9204fe7" . "5"] => [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_dadf790baf241afac9" . "42824c1e6e37c4"] => $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_66824e0309bb76c78bd2bbd5fda8d3" . "d8"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_99cee2d2272a8550f4b21e3cb57fff" . "7d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_d43b1a885195a" . "4b6ccc7d38ba3f" . "cb1f9"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_dadf790baf241afac94" . "2824c1e6e37c4"] => $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_66824e0309bb76c" . "78bd2bbd5fda8d3d" . "8"], $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_99cee2d2272a8550f4b21e3" . "cb57fff7d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_d34599daeb8cca374d3ad" . "b38b245839c"] => TypeContents::GetPropertiesMapping(), $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_aa7e860da1acd4e767e0df9d7" . "d407380"] => TypeDate::GetPropertiesMapping(), $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["permiss" . "ions"] => array($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_dadf790baf241afac942824c1e6e3" . "7c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_b15aac3a" . "a29c10ea6" . "d1228f58c" . "b9a7e8"], $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_809a58dc73011173c031a53c" . "0b40ef0e"] => SearchPermissions::GetPropertiesMapping())]]);
    }
    
    
    
    
    
    
    
    
    
    public function Index(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        if (!$_8c5f17e2e918145535955f8a633b6c7b->object_id) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_d0acf63c20abded6f7458ea8e7009" . "e96"]);
        }
        
        
        
        
        $_8652ba33e6ffeba02459fa9cbb320851 = $this->poll_repo;
        try {
            
            
            
            
            $_b3ee1ca1d7e4bff63ae777968483325d = $_8652ba33e6ffeba02459fa9cbb320851->Get($_8c5f17e2e918145535955f8a633b6c7b->object_id);
        } catch (NotFoundException $_c35473364fa7a050299058f332ec29c1) {
            throw new ObjectNotFoundException($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_19a7dfbfa05ce488f9" . "68b8580e2d6185"] . $_8c5f17e2e918145535955f8a633b6c7b->object_id . $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_fa96cdf58bff3b069" . "5fb2bc0803d7b12"]);
        }
        
        
        if (!$_b3ee1ca1d7e4bff63ae777968483325d->IsLive()) {
            throw new NothingToIndexException($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_695b93f9bbf781be992587b4e" . "62ec823"] . $_b3ee1ca1d7e4bff63ae777968483325d->id . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_6ebc0afe64bb119ce3df66d27" . "45d8c38"]);
        }
        
        
        $_a6fb9cc38e2b15d5b2d8171e60aa3cbe = $this->GetIndexData($_b3ee1ca1d7e4bff63ae777968483325d);
        $_87419315d6aaaec7dd2250b14245566e->Index(self::TYPE_NAME, $_b3ee1ca1d7e4bff63ae777968483325d->id, $_a6fb9cc38e2b15d5b2d8171e60aa3cbe);
    }
    
    
    
    
    
    
    protected function GetIndexData(Poll $_b3ee1ca1d7e4bff63ae777968483325d)
    {
        
        
        $_6137f6b1054c046b6733dcd025f03c02 = $_b3ee1ca1d7e4bff63ae777968483325d->getImage($this->cdn, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_9ea10b1280f50314a9d18333d6d18" . "d4f"]);
        $question = $this->poll_facade->GetQuestionForPoll($_b3ee1ca1d7e4bff63ae777968483325d)[0];
        $_a6fb9cc38e2b15d5b2d8171e60aa3cbe = [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_feb9037589181bc30fa0f" . "1cf78b9f056"] => $question->text, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_33de78378f32" . "407b852c241ec" . "52f9a35"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_ab8199b9" . "7ed2d8fa1" . "f096f35ef" . "bbe647"] . $_b3ee1ca1d7e4bff63ae777968483325d->id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_646df530340" . "668323d9a8e6" . "c9204fe75"] => $_6137f6b1054c046b6733dcd025f03c02, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_d34599daeb8cc" . "a374d3adb38b24" . "5839c"] => $this->cla_text->BBCode2Plain($_b3ee1ca1d7e4bff63ae777968483325d->description ?: $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_4d707fab93bebb00bbe69e81596" . "97c90"]), $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_aa7e860da1acd4" . "e767e0df9d7d407" . "380"] => TypeDate::Format($_b3ee1ca1d7e4bff63ae777968483325d->created_date), $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["permis" . "sions"] => $this->GetPermissionsIndexData($_b3ee1ca1d7e4bff63ae777968483325d)];
        if ($_6137f6b1054c046b6733dcd025f03c02 === $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_4d707fab93bebb00" . "bbe69e8159697c90"]) {
            $_a6fb9cc38e2b15d5b2d8171e60aa3cbe[$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_d43b1a885195a4b6ccc7d38ba3fcb" . "1f9"]] = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_74d41404196e33a2a11ac3f813" . "c155b7"];
        }
        return $_a6fb9cc38e2b15d5b2d8171e60aa3cbe;
    }
    
    
    
    
    
    
    
    protected function GetPermissionsIndexData(Poll $_b3ee1ca1d7e4bff63ae777968483325d)
    {
        
        
        $permissions = new Permissions(PollPermissions::CLASS_POLL, $_b3ee1ca1d7e4bff63ae777968483325d->id);
        $_665240f1a489ba897ccc8ace510a47cb = new Permissions(SurveyAdminPermissions::CLASS_SURVEY_ADMIN, 1);
        
        
        $_c9dab5b1c7628cf9721eea495ec5d40b = $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_f73dab606630b388645c4f7" . "d3fbb13bb"]($_665240f1a489ba897ccc8ace510a47cb->GetAllOwnersList(SurveyAdminPermissions::PERM_MANAGE_ALL), $_665240f1a489ba897ccc8ace510a47cb->GetAllOwnersList(SurveyAdminPermissions::PERM_VIEW_RESULTS));
        
        
        foreach ($_c9dab5b1c7628cf9721eea495ec5d40b as $_c4d674abe9291be143b224c411958fcf) {
            list($_fab148434571859ce581a09251188f00, $_28685591a1d64debd044e3074d01b84d) = $_c4d674abe9291be143b224c411958fcf;
            $permissions->Add(PollPermissions::PERM_ANSWER, $_fab148434571859ce581a09251188f00, $_28685591a1d64debd044e3074d01b84d);
        }
        
        
        $_f053e79538903e098fb90b42736274df = $this->survey_admin_permissions->CanManageOwn(SecurityContext::CreateForUser($_b3ee1ca1d7e4bff63ae777968483325d->created_by));
        if ($_f053e79538903e098fb90b42736274df) {
            $permissions->Add(PollPermissions::PERM_MANAGE, PermOClass::INDIVIDUAL, $_b3ee1ca1d7e4bff63ae777968483325d->created_by);
        }
        
        
        $_5572df110aae46854e281078ba4712b2 = new SearchPermissions();
        return $_5572df110aae46854e281078ba4712b2->GetIndexDataSimple($permissions);
    }
    
    
    
    
    
    
    public function Delete(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        
        
        if (!$_8c5f17e2e918145535955f8a633b6c7b->object_id) {
            return;
        }
        
        
        $_87419315d6aaaec7dd2250b14245566e->Delete(self::TYPE_NAME, $_8c5f17e2e918145535955f8a633b6c7b->object_id);
    }
    
    
    
    
    
    
    protected function GetAllPollIds()
    {
        
        
        
        
        $_8652ba33e6ffeba02459fa9cbb320851 = $this->poll_repo;
        return $_8652ba33e6ffeba02459fa9cbb320851->ListPollIds(false);
    }
    
    
    
    
    
    
    public function QueueFullIndex()
    {
        $_88c689fbf84627709073c0827df9cfb7 = $this->GetAllPollIds();
        foreach ($_88c689fbf84627709073c0827df9cfb7 as $poll_id) {
            IndexingQueue::Index(self::TYPE_NAME, $poll_id);
        }
        return $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_31767d7ad58e706dbf47b7a51" . "a0fe6c4"]($_88c689fbf84627709073c0827df9cfb7);
    }
    
    
    
    
    
    
    
    public function QueueFullReindex($_4433a5922f5df0ebd8436fbb431e146c)
    {
        if (!$_4433a5922f5df0ebd8436fbb431e146c) {
            return $this->QueueFullIndex();
        }
        $_88c689fbf84627709073c0827df9cfb7 = $this->GetAllPollIds();
        foreach ($_88c689fbf84627709073c0827df9cfb7 as $poll_id) {
            IndexingQueue::Reindex(self::TYPE_NAME, $poll_id);
        }
        return $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_31767d7ad58e7" . "06dbf47b7a51a0" . "fe6c4"]($_88c689fbf84627709073c0827df9cfb7);
    }
    
    
    
    
    
    
    
    
    public function Special(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        $_8e7f4b5c8440c0a24fb1b632eee28538 = $_8c5f17e2e918145535955f8a633b6c7b->extra[$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_8e7f4b5c8440c" . "0a24fb1b632eee" . "28538"]];
        if ($_8e7f4b5c8440c0a24fb1b632eee28538 !== $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_b0eaaa9" . "541f479b" . "4891f616" . "1117437b" . "9"]) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_db694a72c731761cffae6060e4" . "b092bc"] . $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_7aefd482de7885f4293c2" . "926df28c235"]($_8c5f17e2e918145535955f8a633b6c7b->extra));
        }
        $this->QueueFullReindex(true);
    }
}