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

$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] ?: array()) + array("_d43b1a885195a4b6ccc7d38ba3fcb1f" . "9" => base64_decode("Z2x" . "5cG" . "hpY" . "29u"), "_feb9037589181bc30fa0f1cf78b9" . "f056" => base64_decode("dGl0bGU" . "="), "_dadf790baf24" . "1afac942824c1" . "e6e37c4" => base64_decode("dHl" . "wZQ" . "=="), "_8e7b0b07b8da9" . "d5cbd9a41129b6" . "29400" => base64_decode("ZGF0ZV9kZ" . "XRlY3Rpb2" . "4="), "_6ebc0afe64bb119ce3df66d2745d8" . "c38" => base64_decode("IGlzIG5vdCBMaXZlLCBzbyBpdCB3aWxsIG5vdCBiZSBpbmRleG" . "Vk"), "_fa96cdf58" . "bff3b0695f" . "b2bc0803d7" . "b12" => base64_decode("IGRvZXMgbm90IG" . "V4aXN0"), "_31767d7ad58" . "e706dbf47b7a" . "51a0fe6c4" => base64_decode("Y29" . "1bn" . "Q="), "_66824e0309bb76c78bd" . "2bbd5fda8d3d8" => base64_decode("c3Rya" . "W5n"), "_f73dab6066" . "30b388645c4" . "f7d3fbb13bb" => base64_decode("YXJyY" . "XlfbW" . "VyZ2U" . "="), "_99cee2d2272a8550f4b21e" . "3cb57fff7d" => base64_decode("ZW5hYmx" . "lZA=="), "_8e7f4b5c8440c0a24fb1b632eee28" . "538" => base64_decode("YWN" . "0aW" . "9u"), "_aa7e860da1a" . "cd4e767e0df9" . "d7d407380" => base64_decode("ZGF0ZV9jcmVhdGV" . "k"), "_7aefd482de7885f" . "4293c2926df28c23" . "5" => base64_decode("anNvbl9l" . "bmNvZGU="), "_809a58dc73011173c031a53c0" . "b40ef0e" => base64_decode("cHJvcGVydGllcw" . "=="), "_b15aac3aa" . "29c10ea6d1" . "228f58cb9a" . "7e8" => base64_decode("b2Jq" . "ZWN0"), "_4d707fab93b" . "ebb00bbe69e8" . "159697c90" => base64_decode(""), "_ab8199b97ed2d8fa1f096f35efbb" . "e647" => base64_decode("L3BvbGxzLXN1cnZle" . "XMvcG9sbC8="), "_33de78378f32407b852" . "c241ec52f9a35" => base64_decode("aHJ" . "lZg" . "=="), "permi" . "ssion" . "s" => base64_decode("cGVybWlzc2" . "lvbnM="), "_695b93f9bbf781be992587b4e" . "62ec823" => base64_decode("UG9sb" . "CA="), "_b0eaaa9" . "541f479b" . "4891f616" . "1117437b" . "9" => base64_decode("cXVldWVfZn" . "VsbF9yZWlu" . "ZGV4"), "_db694a72c731761cffae6060e4b092" . "bc" => base64_decode("VW5rbm93biBzcGVjaWFsIGFjdGlvbiBmb3IgU3VydmV5IGluZGV4aW5" . "nOiA="), "_d0acf63c20abded6f7458ea8e7" . "009e96" => base64_decode("SW5zdHJ1Y3Rpb24gb2JqZWN0IEl" . "EIG5vdCBmb3VuZCBmb3IgUXVpeg" . "=="), "_8ac93b484d7470c59e327620646" . "e2d1e" => base64_decode("X3NvdXJjZ" . "Q=="), "_74d41404196e33a2a11ac3" . "f813c155b7" => base64_decode("Z2x5cGhpY29ucyB" . "nbHlwaGljb25zLX" . "BvbGxzLXN1cnZle" . "Q=="), "_646df530340668323d9a8e6c9204fe7" . "5" => base64_decode("aW1hZ2Vf" . "c3Jj"), "_19a7dfbfa05" . "ce488f968b85" . "80e2d6185" => base64_decode("UG9sbCB3aXRoIElEI" . "A=="), "_d34599daeb8cca374d3ad" . "b38b245839c" => base64_decode("Y29udGV" . "udHM="), "_9ea10b12" . "80f50314a" . "9d18333d6" . "d18d4f" => base64_decode("cXVpei9wb2xsL2NvdmVycw" . "=="));
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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_8ac93b484d7470c59e3" . "27620646e2d1e"] => [$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_99cee2d2272a8550f4b21e3cb57fff7" . "d"] => true], $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8e7b0b07b8da9d5cbd9a411" . "29b629400"] => true, $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_809a58dc73011173c031a" . "53c0b40ef0e"] => [$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_feb9037589181bc30f" . "a0f1cf78b9f056"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_dadf790baf24" . "1afac942824c1" . "e6e37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_66824e0" . "309bb76c" . "78bd2bbd" . "5fda8d3d" . "8"]], $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_33de78378f32407b852c241e" . "c52f9a35"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_dadf790baf24" . "1afac942824c1" . "e6e37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_66824e0309bb76c78bd2bbd5fda8d3" . "d8"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_99cee2d2272a8550f4b21e3cb5" . "7fff7d"] => false], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_646df530" . "340668323" . "d9a8e6c92" . "04fe75"] => [$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_dadf790baf241afac942824c1e6e" . "37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_66824e0309bb76c78bd2bbd5fda8d" . "3d8"], $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_99cee2d2272" . "a8550f4b21e3" . "cb57fff7d"] => false], $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_d43b1a885195a4b6ccc7d38ba3fcb1f" . "9"] => [$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_dadf790baf241a" . "fac942824c1e6e3" . "7c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_66824e0309bb76c78bd2" . "bbd5fda8d3d8"], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_99cee2d2272a8550f4b2" . "1e3cb57fff7d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_d34599daeb8cca374d3" . "adb38b245839c"] => TypeContents::GetPropertiesMapping(), $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_aa7e860da1acd4e767e0df" . "9d7d407380"] => TypeDate::GetPropertiesMapping(), $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["permiss" . "ions"] => array($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_dadf790baf" . "241afac9428" . "24c1e6e37c4"] => $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_b15aac3aa29c10ea" . "6d1228f58cb9a7e8"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_809a58dc73" . "011173c031a" . "53c0b40ef0e"] => SearchPermissions::GetPropertiesMapping())]]);
    }
    
    
    
    
    
    
    
    
    
    public function Index(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        if (!$_8c5f17e2e918145535955f8a633b6c7b->object_id) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_d0acf63c20abded6f7458ea8e700" . "9e96"]);
        }
        
        
        
        
        $_8652ba33e6ffeba02459fa9cbb320851 = $this->poll_repo;
        try {
            
            
            
            
            $_b3ee1ca1d7e4bff63ae777968483325d = $_8652ba33e6ffeba02459fa9cbb320851->Get($_8c5f17e2e918145535955f8a633b6c7b->object_id);
        } catch (NotFoundException $_c35473364fa7a050299058f332ec29c1) {
            throw new ObjectNotFoundException($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_19a7dfbfa05ce488f968b8" . "580e2d6185"] . $_8c5f17e2e918145535955f8a633b6c7b->object_id . $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_fa96cdf58bff3b069" . "5fb2bc0803d7b12"]);
        }
        
        
        if (!$_b3ee1ca1d7e4bff63ae777968483325d->IsLive()) {
            throw new NothingToIndexException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_695b93f9bbf781be99258" . "7b4e62ec823"] . $_b3ee1ca1d7e4bff63ae777968483325d->id . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_6ebc0afe64bb119ce3df66d" . "2745d8c38"]);
        }
        
        
        $_a6fb9cc38e2b15d5b2d8171e60aa3cbe = $this->GetIndexData($_b3ee1ca1d7e4bff63ae777968483325d);
        $_87419315d6aaaec7dd2250b14245566e->Index(self::TYPE_NAME, $_b3ee1ca1d7e4bff63ae777968483325d->id, $_a6fb9cc38e2b15d5b2d8171e60aa3cbe);
    }
    
    
    
    
    
    
    protected function GetIndexData(Poll $_b3ee1ca1d7e4bff63ae777968483325d)
    {
        
        
        $_6137f6b1054c046b6733dcd025f03c02 = $_b3ee1ca1d7e4bff63ae777968483325d->getImage($this->cdn, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_9ea10b1" . "280f5031" . "4a9d1833" . "3d6d18d4" . "f"]);
        $question = $this->poll_facade->GetQuestionForPoll($_b3ee1ca1d7e4bff63ae777968483325d)[0];
        $_a6fb9cc38e2b15d5b2d8171e60aa3cbe = [$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_feb9037589181bc30fa0f1cf7" . "8b9f056"] => $question->text, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_33de78378f32407b852c2" . "41ec52f9a35"] => $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_ab8199b97ed" . "2d8fa1f096f3" . "5efbbe647"] . $_b3ee1ca1d7e4bff63ae777968483325d->id, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_646df5303406683" . "23d9a8e6c9204fe7" . "5"] => $_6137f6b1054c046b6733dcd025f03c02, $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_d34599daeb8" . "cca374d3adb3" . "8b245839c"] => $this->cla_text->BBCode2Plain($_b3ee1ca1d7e4bff63ae777968483325d->description ?: $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_4d707fab93bebb00bbe69e815" . "9697c90"]), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_aa7e860da1a" . "cd4e767e0df9" . "d7d407380"] => TypeDate::Format($_b3ee1ca1d7e4bff63ae777968483325d->created_date), $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["permis" . "sions"] => $this->GetPermissionsIndexData($_b3ee1ca1d7e4bff63ae777968483325d)];
        if ($_6137f6b1054c046b6733dcd025f03c02 === $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_4d707fab93bebb00bbe69e815" . "9697c90"]) {
            $_a6fb9cc38e2b15d5b2d8171e60aa3cbe[$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_d43b1a8" . "85195a4b" . "6ccc7d38" . "ba3fcb1f" . "9"]] = $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_74d41404196e3" . "3a2a11ac3f813c" . "155b7"];
        }
        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["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_f73dab606630b388645c4" . "f7d3fbb13bb"]($_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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_31767d7ad58e706" . "dbf47b7a51a0fe6c" . "4"]($_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["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_31767d7ad58e70" . "6dbf47b7a51a0fe" . "6c4"]($_88c689fbf84627709073c0827df9cfb7);
    }
    
    
    
    
    
    
    
    
    public function Special(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        $_8e7f4b5c8440c0a24fb1b632eee28538 = $_8c5f17e2e918145535955f8a633b6c7b->extra[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_8e7f4b5c844" . "0c0a24fb1b63" . "2eee28538"]];
        if ($_8e7f4b5c8440c0a24fb1b632eee28538 !== $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_b0eaaa954" . "1f479b4891" . "f616111743" . "7b9"]) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_db694a72c731761cffae606" . "0e4b092bc"] . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_7aefd482de" . "7885f4293c2" . "926df28c235"]($_8c5f17e2e918145535955f8a633b6c7b->extra));
        }
        $this->QueueFullReindex(true);
    }
}