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

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] = (@$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] ?: array()) + array("_6ebc0afe64bb119ce3df6" . "6d2745d8c38" => base64_decode("IGlzIG5vdCBMaXZlLCBzbyBpd" . "CB3aWxsIG5vdCBiZSBpbmRleG" . "Vk"), "permission" . "s" => base64_decode("cGVybWlzc" . "2lvbnM="), "_19a7dfbfa05" . "ce488f968b85" . "80e2d6185" => base64_decode("UG9sbCB3aXRoIElEI" . "A=="), "_809a58dc73011" . "173c031a53c0b4" . "0ef0e" => base64_decode("cHJvcGVydGllcw" . "=="), "_b0eaaa9541f479b4891f6161117437" . "b9" => base64_decode("cXVldWVfZnVsbF9yZWluZG" . "V4"), "_31767d7ad58e706dbf47b" . "7a51a0fe6c4" => base64_decode("Y291b" . "nQ="), "_4d707fab93bebb00bbe" . "69e8159697c90" => base64_decode(""), "_646df530340668323d9a8e6c9204fe" . "75" => base64_decode("aW1hZ2" . "Vfc3Jj"), "_66824e0309bb76c78bd2bbd5fda8d" . "3d8" => base64_decode("c3Ry" . "aW5n"), "_8ac93b484d7470c59e327620" . "646e2d1e" => base64_decode("X3NvdXJjZQ" . "=="), "_fa96cdf58" . "bff3b0695f" . "b2bc0803d7" . "b12" => base64_decode("IGRvZXMgbm9" . "0IGV4aXN0"), "_f73dab606630b388645c4f7d3fbb13b" . "b" => base64_decode("YXJyYXlfbWVy" . "Z2U="), "_7aefd482de" . "7885f4293c2" . "926df28c235" => base64_decode("anNvbl9lbmNv" . "ZGU="), "_d43b1a885" . "195a4b6ccc" . "7d38ba3fcb" . "1f9" => base64_decode("Z2x" . "5cG" . "hpY" . "29u"), "_b15aac3aa29c10ea6d1228f58cb9a7e" . "8" => base64_decode("b2Jq" . "ZWN0"), "_695b93f9bbf78" . "1be992587b4e62" . "ec823" => base64_decode("UG9sbC" . "A="), "_feb9037" . "589181bc" . "30fa0f1c" . "f78b9f05" . "6" => base64_decode("dGl0b" . "GU="), "_aa7e860da1a" . "cd4e767e0df9" . "d7d407380" => base64_decode("ZGF0ZV9jcmV" . "hdGVk"), "_74d41404196e33a2a11ac3f8" . "13c155b7" => base64_decode("Z2x5cGhpY29ucyBnbHlwaGljb25zLXBvbGxzLXN1" . "cnZleQ=="), "_d0acf63c20abded6f7458ea8e7009e9" . "6" => base64_decode("SW5zdHJ1Y3Rpb24gb2JqZWN0IElEIG5vdCBmb3" . "VuZCBmb3IgUXVpeg=="), "_33de78378f3240" . "7b852c241ec52f9" . "a35" => base64_decode("aHJ" . "lZg" . "=="), "_99cee2d2272a8550f4" . "b21e3cb57fff7d" => base64_decode("ZW5hY" . "mxlZA" . "=="), "_8e7f4b5c8" . "440c0a24fb" . "1b632eee28" . "538" => base64_decode("YWN0aW" . "9u"), "_db694a72c731" . "761cffae6060e" . "4b092bc" => base64_decode("VW5rbm93biBzcGVjaWFsIGFjdGlvbiBmb3IgU3VydmV5IGluZGV4" . "aW5nOiA="), "_ab8199b97ed2d" . "8fa1f096f35efb" . "be647" => base64_decode("L3BvbGx" . "zLXN1cn" . "ZleXMvc" . "G9sbC8="), "_dadf790baf241afac942824c" . "1e6e37c4" => base64_decode("dH" . "lw" . "ZQ" . "=="), "_9ea10b1280f50314a" . "9d18333d6d18d4f" => base64_decode("cXVpei" . "9wb2xs" . "L2Nvdm" . "Vycw=="), "_8e7b0b07b8da9d5cbd9a" . "41129b629400" => base64_decode("ZGF0ZV9kZXRlY3Rp" . "b24="), "_d34599daeb8cca374" . "d3adb38b245839c" => base64_decode("Y29udG" . "VudHM="));
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["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_8ac93b484d7470c59e327620646e2d" . "1e"] => [$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_99cee2d2272a8550f4b" . "21e3cb57fff7d"] => true], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_8e7b0b07b8d" . "a9d5cbd9a411" . "29b629400"] => true, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_809a58dc73" . "011173c031a" . "53c0b40ef0e"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_feb9037589181b" . "c30fa0f1cf78b9f" . "056"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_dadf790" . "baf241af" . "ac942824" . "c1e6e37c" . "4"] => $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_66824e0309bb76c78" . "bd2bbd5fda8d3d8"]], $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_33de78378f32407b852c241ec52f9a" . "35"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_dadf790baf241afac94282" . "4c1e6e37c4"] => $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_66824e0309b" . "b76c78bd2bbd" . "5fda8d3d8"], $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_99cee2d2272a8550" . "f4b21e3cb57fff7d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_646df530340668323d9a8e6" . "c9204fe75"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_dadf790baf241afac" . "942824c1e6e37c4"] => $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_66824e0309bb76c78" . "bd2bbd5fda8d3d8"], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_99cee2d2272a855" . "0f4b21e3cb57fff7" . "d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_d43b1a885195a4b6ccc7d38ba3fcb1f" . "9"] => [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_dadf790baf241afac94282" . "4c1e6e37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_66824e0" . "309bb76c" . "78bd2bbd" . "5fda8d3d" . "8"], $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_99cee2d2272a8" . "550f4b21e3cb57" . "fff7d"] => false], $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_d34599daeb8cca374d3adb38b24583" . "9c"] => TypeContents::GetPropertiesMapping(), $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_aa7e860da1acd" . "4e767e0df9d7d4" . "07380"] => TypeDate::GetPropertiesMapping(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["per" . "mis" . "sio" . "ns"] => array($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_dadf790baf241afac" . "942824c1e6e37c4"] => $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_b15aac3aa29c10ea6d12" . "28f58cb9a7e8"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_809a58dc730111" . "73c031a53c0b40e" . "f0e"] => SearchPermissions::GetPropertiesMapping())]]);
    }
    
    
    
    
    
    
    
    
    
    public function Index(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        if (!$_8c5f17e2e918145535955f8a633b6c7b->object_id) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_d0acf63c20abded6f7458ea8e70" . "09e96"]);
        }
        
        
        
        
        $_8652ba33e6ffeba02459fa9cbb320851 = $this->poll_repo;
        try {
            
            
            
            
            $_b3ee1ca1d7e4bff63ae777968483325d = $_8652ba33e6ffeba02459fa9cbb320851->Get($_8c5f17e2e918145535955f8a633b6c7b->object_id);
        } catch (NotFoundException $_c35473364fa7a050299058f332ec29c1) {
            throw new ObjectNotFoundException($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_19a7dfbfa05" . "ce488f968b85" . "80e2d6185"] . $_8c5f17e2e918145535955f8a633b6c7b->object_id . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_fa96cdf58bff3b0695fb2bc0803d7b1" . "2"]);
        }
        
        
        if (!$_b3ee1ca1d7e4bff63ae777968483325d->IsLive()) {
            throw new NothingToIndexException($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_695b93f9bbf781be992587b4e62ec82" . "3"] . $_b3ee1ca1d7e4bff63ae777968483325d->id . $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_6ebc0afe6" . "4bb119ce3d" . "f66d2745d8" . "c38"]);
        }
        
        
        $_a6fb9cc38e2b15d5b2d8171e60aa3cbe = $this->GetIndexData($_b3ee1ca1d7e4bff63ae777968483325d);
        $_87419315d6aaaec7dd2250b14245566e->Index(self::TYPE_NAME, $_b3ee1ca1d7e4bff63ae777968483325d->id, $_a6fb9cc38e2b15d5b2d8171e60aa3cbe);
    }
    
    
    
    
    
    
    protected function GetIndexData(Poll $_b3ee1ca1d7e4bff63ae777968483325d)
    {
        
        
        $_6137f6b1054c046b6733dcd025f03c02 = $_b3ee1ca1d7e4bff63ae777968483325d->getImage($this->cdn, $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_9ea10b1280f50314a9d18333d" . "6d18d4f"]);
        $question = $this->poll_facade->GetQuestionForPoll($_b3ee1ca1d7e4bff63ae777968483325d)[0];
        $_a6fb9cc38e2b15d5b2d8171e60aa3cbe = [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_feb90375891" . "81bc30fa0f1c" . "f78b9f056"] => $question->text, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_33de7837" . "8f32407b8" . "52c241ec5" . "2f9a35"] => $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_ab8199b97ed2d8fa1" . "f096f35efbbe647"] . $_b3ee1ca1d7e4bff63ae777968483325d->id, $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_646df530340668323d9a8e6" . "c9204fe75"] => $_6137f6b1054c046b6733dcd025f03c02, $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_d34599dae" . "b8cca374d3" . "adb38b2458" . "39c"] => $this->cla_text->BBCode2Plain($_b3ee1ca1d7e4bff63ae777968483325d->description ?: $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_4d707fab93bebb00bb" . "e69e8159697c90"]), $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_aa7e860da1acd4e767e" . "0df9d7d407380"] => TypeDate::Format($_b3ee1ca1d7e4bff63ae777968483325d->created_date), $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["perm" . "issi" . "ons"] => $this->GetPermissionsIndexData($_b3ee1ca1d7e4bff63ae777968483325d)];
        if ($_6137f6b1054c046b6733dcd025f03c02 === $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_4d707fab93bebb00" . "bbe69e8159697c90"]) {
            $_a6fb9cc38e2b15d5b2d8171e60aa3cbe[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_d43b1a885195a4b6ccc7d3" . "8ba3fcb1f9"]] = $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_74d41404196e33a2a11ac3f813c1" . "55b7"];
        }
        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["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_f73dab606630b38" . "8645c4f7d3fbb13b" . "b"]($_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["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_31767d7ad5" . "8e706dbf47b" . "7a51a0fe6c4"]($_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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_31767d7ad58" . "e706dbf47b7a" . "51a0fe6c4"]($_88c689fbf84627709073c0827df9cfb7);
    }
    
    
    
    
    
    
    
    
    public function Special(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        $_8e7f4b5c8440c0a24fb1b632eee28538 = $_8c5f17e2e918145535955f8a633b6c7b->extra[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_8e7f4b5c8440c0a24fb1b632eee" . "28538"]];
        if ($_8e7f4b5c8440c0a24fb1b632eee28538 !== $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_b0eaaa954" . "1f479b4891" . "f616111743" . "7b9"]) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_db694a72c73176" . "1cffae6060e4b09" . "2bc"] . $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_7aefd482" . "de7885f42" . "93c2926df" . "28c235"]($_8c5f17e2e918145535955f8a633b6c7b->extra));
        }
        $this->QueueFullReindex(true);
    }
}