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

$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"] = (@$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] ?: array()) + array("_66824e0309bb76c78bd2bbd5fda8" . "d3d8" => base64_decode("c3Ry" . "aW5n"), "_b15aac3aa29c10ea6d1" . "228f58cb9a7e8" => base64_decode("b2JqZ" . "WN0"), "_33de78378f32407b8" . "52c241ec52f9a35" => base64_decode("aHJ" . "lZg" . "=="), "_dadf790baf241afac942824c1e6e3" . "7c4" => base64_decode("dHlwZQ" . "=="), "_bc60b6b4ed7cd96f21" . "5c398b7974e744" => base64_decode("U3VydmV5ICVzIGlzIG5vdCBMaXZlLCBzbyBpdCB3aWxsIG5vdCBiZSB" . "pbmRleGVk"), "permiss" . "ions" => base64_decode("cGVybWlz" . "c2lvbnM="), "_6596b8f6a4969f9a3f6a" . "1b22b90e9331" => base64_decode("c3B" . "yaW" . "50Z" . "g=="), "_1701bcec3c1ce0841f0b67a74e766" . "bcb" => base64_decode("U3VydmV5IHdpdGggS" . "UQgJXMgZG9lcyBub3" . "QgZXhpc3Q="), "_c05fc24" . "8d5ab54a" . "d876be7a" . "b77eb8fa" . "7" => base64_decode("L3BvbGxzL" . "XN1cnZleX" . "Mvc3VydmV" . "5Lw=="), "_8e7f4b5c8440c0a24fb1b632e" . "ee28538" => base64_decode("YWN0a" . "W9u"), "_f521e6d29ae6e6c84ef" . "8eb3270ff440d" => base64_decode("cXVpei9zdXJ2Z" . "XkvY292ZXJz"), "_d43b1a885195a4b6ccc7d38ba3fcb1" . "f9" => base64_decode("Z2x5" . "cGhp" . "Y29u"), "_33f09d76394b074b779265f857d5ec" . "8a" => base64_decode("Y291bnRf" . "c2FmZQ=="), "_945e7f180f5ac7c426fa" . "3d92712223a3" => base64_decode("VW5rbm93biBzcGVjaWFsIGFj" . "dGlvbiBmb3IgU3VydmV5cyBp" . "bmRleGluZzog"), "_809a58dc73011173" . "c031a53c0b40ef0e" => base64_decode("cHJvcGVyd" . "Gllcw=="), "_aa7e860" . "da1acd4e" . "767e0df9" . "d7d40738" . "0" => base64_decode("ZGF0ZV9jcmVhdG" . "Vk"), "_402d65541d509737cc4cc9" . "62c696043e" => base64_decode("SW5zdHJ1Y3Rpb24gb2JqZWN0IElEIG5vdCBmb3Vu" . "ZCBmb3IgU3VydmV5"), "_8e7b0b07b8da9d" . "5cbd9a41129b629" . "400" => base64_decode("ZGF0ZV9kZ" . "XRlY3Rpb2" . "4="), "_f73dab606630b3" . "88645c4f7d3fbb1" . "3bb" => base64_decode("YXJyYXlfb" . "WVyZ2U="), "_646df530340668323d" . "9a8e6c9204fe75" => base64_decode("aW1hZ2V" . "fc3Jj"), "_4d707fab93bebb00bbe69e8159697c9" . "0" => base64_decode(""), "_feb9037589181bc30fa0f1cf78" . "b9f056" => base64_decode("dG" . "l0" . "bG" . "U="), "_74d41404196e33a2a11ac" . "3f813c155b7" => base64_decode("Z2x5cGhpY29ucyBnbHlwaGljb25zLXBvbGxzLXN1c" . "nZleQ=="), "_7aefd482de7" . "885f4293c292" . "6df28c235" => base64_decode("anNvbl9l" . "bmNvZGU="), "_99cee2d2272a8550f4b2" . "1e3cb57fff7d" => base64_decode("ZW5hYmxlZA=" . "="), "_8ac93b484d7470c5" . "9e327620646e2d1e" => base64_decode("X3Nv" . "dXJj" . "ZQ=="), "_b0eaaa9541f479b4891f616111743" . "7b9" => base64_decode("cXVldWVfZnVsbF9yZWluZG" . "V4"), "_d34599daeb8cca374d" . "3adb38b245839c" => base64_decode("Y29u" . "dGVu" . "dHM="));
use Claromentis\Core\Acl\PermOClass;
use Claromentis\Core\CDN\CDNInterface;
use Claromentis\Core\Repository\Exception\NotFoundException;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Quiz\Model\Survey;
use Claromentis\Quiz\Permissions\SurveyAdminPermissions;
use Claromentis\Quiz\Permissions\SurveyPermissions;
use Claromentis\Quiz\Repository\SurveyRepository;
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 Claromentis\Core\TextUtil\ClaText;
use Permissions;




class SurveyIndexing implements IndexingItemInterface
{
    const TYPE_NAME = 'survey';
    
    
    private $cla_text;
    
    
    private $cdn;
    
    
    private $survey_repository;
    
    
    private $survey_admin_permissions;
    public function __construct(ClaText $cla_text, CDNInterface $cdn, SurveyRepository $_d788c955b64166f591e5ce0a44478441, SurveyAdminPermissions $survey_admin_permissions)
    {
        $this->cla_text = $cla_text;
        $this->cdn = $cdn;
        $this->survey_repository = $_d788c955b64166f591e5ce0a44478441;
        $this->survey_admin_permissions = $survey_admin_permissions;
    }
    
    
    
    
    
    
    public function InitMapping(ClientInterface $_87419315d6aaaec7dd2250b14245566e)
    {
        $_87419315d6aaaec7dd2250b14245566e->AddMapping(self::TYPE_NAME, [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_8ac93b484" . "d7470c59e3" . "27620646e2" . "d1e"] => [$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_99cee2d2272a8550f" . "4b21e3cb57fff7d"] => true], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_8e7b0b07b8da9d5cbd9a41129b629" . "400"] => true, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_809a58dc7301117" . "3c031a53c0b40ef0" . "e"] => [$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_feb9037589181bc30fa0" . "f1cf78b9f056"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_dadf790baf241af" . "ac942824c1e6e37c" . "4"] => $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_66824e030" . "9bb76c78bd" . "2bbd5fda8d" . "3d8"]], $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_33de78378f32407b852c241" . "ec52f9a35"] => [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_dadf790baf241afac942824c1e6e" . "37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_66824e0309bb76c78" . "bd2bbd5fda8d3d8"], $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_99cee2d2272a8" . "550f4b21e3cb57" . "fff7d"] => false], $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_646df53" . "03406683" . "23d9a8e6" . "c9204fe7" . "5"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_dadf790baf241afac942824c1e6e3" . "7c4"] => $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_66824e030" . "9bb76c78bd" . "2bbd5fda8d" . "3d8"], $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_99cee2d2" . "272a8550f" . "4b21e3cb5" . "7fff7d"] => false], $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_d43b1a885195a4b6ccc7d38ba3f" . "cb1f9"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_dadf790baf241afac942824c1e6e3" . "7c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_66824e03" . "09bb76c78" . "bd2bbd5fd" . "a8d3d8"], $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_99cee2d22" . "72a8550f4b" . "21e3cb57ff" . "f7d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_d34599daeb8cca374" . "d3adb38b245839c"] => TypeContents::GetPropertiesMapping(), $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_aa7e860da1acd4e767e0df9d" . "7d407380"] => TypeDate::GetPropertiesMapping(), $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["permiss" . "ions"] => [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_dadf790baf241afac942824c1e6e37c" . "4"] => $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_b15aac3aa29c10ea6d1228f58cb9" . "a7e8"], $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_809a58d" . "c7301117" . "3c031a53" . "c0b40ef0" . "e"] => SearchPermissions::GetPropertiesMapping()]]]);
    }
    
    
    
    
    
    
    
    
    
    public function Index(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        if (!$_8c5f17e2e918145535955f8a633b6c7b->object_id) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_402d65541d509737cc4cc962c" . "696043e"]);
        }
        try {
            
            
            $survey = $this->survey_repository->Get($_8c5f17e2e918145535955f8a633b6c7b->object_id);
        } catch (NotFoundException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new ObjectNotFoundException($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_6596b8f" . "6a4969f9" . "a3f6a1b2" . "2b90e933" . "1"]($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_1701bcec3c1ce0841f0" . "b67a74e766bcb"], $_8c5f17e2e918145535955f8a633b6c7b->object_id));
        }
        if (!$survey->IsLive()) {
            throw new NothingToIndexException($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_6596b8f" . "6a4969f9" . "a3f6a1b2" . "2b90e933" . "1"]($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_bc60b6b4ed7cd" . "96f215c398b797" . "4e744"], $survey->id));
        }
        
        
        $_87419315d6aaaec7dd2250b14245566e->Index(self::TYPE_NAME, $survey->id, $this->GetIndexData($survey));
    }
    
    
    
    
    
    
    
    
    protected function GetIndexData(Survey $survey)
    {
        $_6137f6b1054c046b6733dcd025f03c02 = $survey->GetImage($this->cdn, $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_f521e6d" . "29ae6e6c" . "84ef8eb3" . "270ff440" . "d"]);
        $_a6fb9cc38e2b15d5b2d8171e60aa3cbe = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_feb9037589181bc30fa0f1cf78b9f" . "056"] => $survey->title, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_33de78378f32407b852c241" . "ec52f9a35"] => $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_c05fc248d5ab54ad876be7ab" . "77eb8fa7"] . $survey->id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_646df530340668323d9a8e6c9204fe7" . "5"] => $_6137f6b1054c046b6733dcd025f03c02, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_d34599daeb8cca374d3adb38" . "b245839c"] => $this->cla_text->BBCode2Plain($survey->description ?: $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_4d707fab93" . "bebb00bbe69" . "e8159697c90"]), $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_aa7e860da1acd4e767e0df9d7" . "d407380"] => TypeDate::Format($survey->created_date), $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["permission" . "s"] => $this->GetPermissionsIndexData($survey)];
        if ($_6137f6b1054c046b6733dcd025f03c02 === $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_4d707fab93bebb00" . "bbe69e8159697c90"]) {
            $_a6fb9cc38e2b15d5b2d8171e60aa3cbe[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_d43b1a885195a4b6ccc7d38b" . "a3fcb1f9"]] = $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_74d41404196e" . "33a2a11ac3f81" . "3c155b7"];
        }
        return $_a6fb9cc38e2b15d5b2d8171e60aa3cbe;
    }
    
    
    
    
    
    
    
    protected function GetPermissionsIndexData(Survey $survey)
    {
        
        
        $permissions = new Permissions(SurveyPermissions::CLASS_SURVEY, $survey->id);
        $_665240f1a489ba897ccc8ace510a47cb = new Permissions(SurveyAdminPermissions::CLASS_SURVEY_ADMIN, 1);
        $permissions->Load();
        $_665240f1a489ba897ccc8ace510a47cb->Load();
        
        
        $_c9dab5b1c7628cf9721eea495ec5d40b = $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_f73dab606630b388645c4f7d3fbb13b" . "b"]($_665240f1a489ba897ccc8ace510a47cb->GetAllOwnersList(SurveyAdminPermissions::PERM_VIEW_RESULTS), $_665240f1a489ba897ccc8ace510a47cb->GetAllOwnersList(SurveyAdminPermissions::PERM_MANAGE_ALL));
        
        
        foreach ($_c9dab5b1c7628cf9721eea495ec5d40b as $_c4d674abe9291be143b224c411958fcf) {
            list($_fab148434571859ce581a09251188f00, $_28685591a1d64debd044e3074d01b84d) = $_c4d674abe9291be143b224c411958fcf;
            $permissions->Add(SurveyPermissions::PERM_TAKE, $_fab148434571859ce581a09251188f00, $_28685591a1d64debd044e3074d01b84d);
        }
        
        
        $_f053e79538903e098fb90b42736274df = $this->survey_admin_permissions->CanManageOwn(SecurityContext::CreateForUser($survey->created_by));
        if ($_f053e79538903e098fb90b42736274df) {
            $permissions->Add(SurveyPermissions::PERM_TAKE, PermOClass::INDIVIDUAL, $survey->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 GetAllSurveyIds()
    {
        return $this->survey_repository->ListAllSurveyIds();
    }
    
    
    
    
    
    
    public function QueueFullIndex()
    {
        $_21251b5cbf8c4f9d4d56281f4886036f = $this->GetAllSurveyIds();
        foreach ($_21251b5cbf8c4f9d4d56281f4886036f as $survey_id) {
            IndexingQueue::Index(self::TYPE_NAME, $survey_id);
        }
        return $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_33f09d7" . "6394b074" . "b779265f" . "857d5ec8" . "a"]($_21251b5cbf8c4f9d4d56281f4886036f);
    }
    
    
    
    
    
    
    
    public function QueueFullReindex($_4433a5922f5df0ebd8436fbb431e146c)
    {
        if (!$_4433a5922f5df0ebd8436fbb431e146c) {
            return $this->QueueFullIndex();
        }
        $_3e1ef20d972361db64536e4c72bb1649 = $this->GetAllSurveyIds();
        foreach ($_3e1ef20d972361db64536e4c72bb1649 as $quiz_id) {
            IndexingQueue::Reindex(self::TYPE_NAME, $quiz_id);
        }
        return $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_33f09d76394b074b779265" . "f857d5ec8a"]($_3e1ef20d972361db64536e4c72bb1649);
    }
    
    
    
    
    
    
    
    
    public function Special(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        $_8e7f4b5c8440c0a24fb1b632eee28538 = $_8c5f17e2e918145535955f8a633b6c7b->extra[$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8e7f4b5c8440c0a24fb1" . "b632eee28538"]];
        if ($_8e7f4b5c8440c0a24fb1b632eee28538 !== $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_b0eaaa9541f479b4891f6161117437b" . "9"]) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_945e7f180f5ac7c" . "426fa3d92712223a" . "3"] . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_7aefd482de7885f4293c2926df2" . "8c235"]($_8c5f17e2e918145535955f8a633b6c7b->extra));
        }
        $this->QueueFullReindex(true);
    }
}