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

$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"] ?: array()) + array("_aa7e860da1" . "acd4e767e0d" . "f9d7d407380" => base64_decode("ZGF0ZV9j" . "cmVhdGVk"), "_bc60b6b4ed7cd96f215" . "c398b7974e744" => base64_decode("U3VydmV5ICVzIGlzIG5vdCBMaXZlLCBzbyBpdC" . "B3aWxsIG5vdCBiZSBpbmRleGVk"), "_b15aac3aa29c10ea6d1228f58cb9" . "a7e8" => base64_decode("b2JqZ" . "WN0"), "_33f09d76394b074b7792" . "65f857d5ec8a" => base64_decode("Y291bnRfc2" . "FmZQ=="), "_d43b1a8" . "85195a4b" . "6ccc7d38" . "ba3fcb1f" . "9" => base64_decode("Z2x5cG" . "hpY29u"), "_66824e0309bb76c78bd2bbd5f" . "da8d3d8" => base64_decode("c3Rya" . "W5n"), "_33de78378f32407b852c2" . "41ec52f9a35" => base64_decode("aHJl" . "Zg=="), "_8e7b0b07b8da9d5" . "cbd9a41129b62940" . "0" => base64_decode("ZGF0ZV9" . "kZXRlY3" . "Rpb24="), "per" . "mis" . "sio" . "ns" => base64_decode("cGVybWlzc2" . "lvbnM="), "_b0eaaa954" . "1f479b4891" . "f616111743" . "7b9" => base64_decode("cXVldWV" . "fZnVsbF" . "9yZWluZ" . "GV4"), "_646df530" . "340668323" . "d9a8e6c92" . "04fe75" => base64_decode("aW1hZ2" . "Vfc3Jj"), "_945e7f180f5ac" . "7c426fa3d92712" . "223a3" => base64_decode("VW5rbm93biBzcGVjaWFsIGFjdGlvbiBmb3IgU3VydmV5cyBpbmR" . "leGluZzog"), "_feb9037589181bc30fa0f1cf" . "78b9f056" => base64_decode("dGl0bGU" . "="), "_c05fc248d5ab54" . "ad876be7ab77eb8" . "fa7" => base64_decode("L3BvbGxzLXN1cnZleX" . "Mvc3VydmV5Lw=="), "_6596b8f6a4969f9a3f6a1b22b" . "90e9331" => base64_decode("c3ByaW50Z" . "g=="), "_f521e6d29ae6e6c84ef8eb3" . "270ff440d" => base64_decode("cXVpei" . "9zdXJ2" . "ZXkvY2" . "92ZXJz"), "_f73dab606630" . "b388645c4f7d3" . "fbb13bb" => base64_decode("YXJyYXlfbWVyZ2U" . "="), "_1701bcec" . "3c1ce0841" . "f0b67a74e" . "766bcb" => base64_decode("U3VydmV5IHdpdGggSUQ" . "gJXMgZG9lcyBub3QgZX" . "hpc3Q="), "_809a58dc7" . "3011173c03" . "1a53c0b40e" . "f0e" => base64_decode("cHJvc" . "GVydG" . "llcw=" . "="), "_8e7f4b5c8440c0a24fb1b632ee" . "e28538" => base64_decode("YWN0a" . "W9u"), "_99cee2d2272a8550f4b21e3cb57f" . "ff7d" => base64_decode("ZW5" . "hYm" . "xlZ" . "A=="), "_7aefd482de78" . "85f4293c2926d" . "f28c235" => base64_decode("anNvbl9lbmN" . "vZGU="), "_74d41404196e33a2a11ac" . "3f813c155b7" => base64_decode("Z2x5cGhpY29ucyBnbHlwaGljb25zLXBv" . "bGxzLXN1cnZleQ=="), "_dadf790baf241afac942824" . "c1e6e37c4" => base64_decode("dHlwZQ" . "=="), "_4d707fab93bebb00bbe69" . "e8159697c90" => base64_decode(""), "_8ac93b484d7470c59e327620646e2d1" . "e" => base64_decode("X3NvdXJj" . "ZQ=="), "_d34599daeb8cca374d3adb38b2458" . "39c" => base64_decode("Y29udGVu" . "dHM="), "_402d65541d509737cc4cc962c69604" . "3e" => base64_decode("SW5zdHJ1Y3Rpb24gb2JqZWN0IElEIG5vdCBmb3VuZCBmb3IgU3Vyd" . "mV5"));
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["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_8ac93b484d7470" . "c59e327620646e2" . "d1e"] => [$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_99cee2d2272a8550f4b21e3cb5" . "7fff7d"] => true], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_8e7b0b07b8da9d5cbd9a41129b6294" . "00"] => true, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_809a58d" . "c7301117" . "3c031a53" . "c0b40ef0" . "e"] => [$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_feb90375891" . "81bc30fa0f1c" . "f78b9f056"] => [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_dadf790baf241afac942824c1e6" . "e37c4"] => $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_66824e0309bb76c78bd2bbd5f" . "da8d3d8"]], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_33de78378" . "f32407b852" . "c241ec52f9" . "a35"] => [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_dadf790baf241afac942824c1e6e" . "37c4"] => $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_66824e0309bb76c78b" . "d2bbd5fda8d3d8"], $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_99cee2d2272a8550f4b21e3" . "cb57fff7d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_646df530340668323d9a8e6c9" . "204fe75"] => [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_dadf790baf2" . "41afac942824" . "c1e6e37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_66824e03" . "09bb76c78" . "bd2bbd5fd" . "a8d3d8"], $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_99cee2d2272a8550f4b2" . "1e3cb57fff7d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_d43b1a885195a4b6ccc7d38ba3f" . "cb1f9"] => [$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_dadf790baf241afac94" . "2824c1e6e37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_66824e0309bb76c78bd" . "2bbd5fda8d3d8"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_99cee2d" . "2272a855" . "0f4b21e3" . "cb57fff7" . "d"] => false], $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_d34599daeb8c" . "ca374d3adb38b" . "245839c"] => TypeContents::GetPropertiesMapping(), $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_aa7e860da1acd4e767e0df9d7d4" . "07380"] => TypeDate::GetPropertiesMapping(), $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["permissi" . "ons"] => [$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_dadf790baf241afac94282" . "4c1e6e37c4"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_b15aac3aa29c10ea6d1228f58cb9a7e" . "8"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_809a58dc73011173c" . "031a53c0b40ef0e"] => SearchPermissions::GetPropertiesMapping()]]]);
    }
    
    
    
    
    
    
    
    
    
    public function Index(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        if (!$_8c5f17e2e918145535955f8a633b6c7b->object_id) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_402d65541d509737cc4cc962c69604" . "3e"]);
        }
        try {
            
            
            $survey = $this->survey_repository->Get($_8c5f17e2e918145535955f8a633b6c7b->object_id);
        } catch (NotFoundException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw new ObjectNotFoundException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_6596b8f6a4969f9" . "a3f6a1b22b90e933" . "1"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_1701bcec3c1ce0" . "841f0b67a74e766" . "bcb"], $_8c5f17e2e918145535955f8a633b6c7b->object_id));
        }
        if (!$survey->IsLive()) {
            throw new NothingToIndexException($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_6596b8f6a4969f9a3f6a1b" . "22b90e9331"]($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_bc60b6b4ed7cd96f215c398b79" . "74e744"], $survey->id));
        }
        
        
        $_87419315d6aaaec7dd2250b14245566e->Index(self::TYPE_NAME, $survey->id, $this->GetIndexData($survey));
    }
    
    
    
    
    
    
    
    
    protected function GetIndexData(Survey $survey)
    {
        $_6137f6b1054c046b6733dcd025f03c02 = $survey->GetImage($this->cdn, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_f521e6d29ae6e" . "6c84ef8eb3270f" . "f440d"]);
        $_a6fb9cc38e2b15d5b2d8171e60aa3cbe = [$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_feb9037589181bc30fa0f" . "1cf78b9f056"] => $survey->title, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_33de78378f32407b" . "852c241ec52f9a35"] => $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_c05fc248d" . "5ab54ad876" . "be7ab77eb8" . "fa7"] . $survey->id, $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_646df530340668323d9a8e6c9204fe" . "75"] => $_6137f6b1054c046b6733dcd025f03c02, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_d34599daeb8cca3" . "74d3adb38b245839" . "c"] => $this->cla_text->BBCode2Plain($survey->description ?: $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_4d707fab93bebb00bbe6" . "9e8159697c90"]), $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_aa7e860da1acd4e767e0d" . "f9d7d407380"] => TypeDate::Format($survey->created_date), $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["perm" . "issi" . "ons"] => $this->GetPermissionsIndexData($survey)];
        if ($_6137f6b1054c046b6733dcd025f03c02 === $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_4d707fab93bebb00bbe" . "69e8159697c90"]) {
            $_a6fb9cc38e2b15d5b2d8171e60aa3cbe[$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_d43b1a885195a4" . "b6ccc7d38ba3fcb" . "1f9"]] = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_74d414041" . "96e33a2a11" . "ac3f813c15" . "5b7"];
        }
        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["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_f73dab60663" . "0b388645c4f7" . "d3fbb13bb"]($_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["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_33f09d76394b074b779265" . "f857d5ec8a"]($_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"]["_33f09d76394b074b77" . "9265f857d5ec8a"]($_3e1ef20d972361db64536e4c72bb1649);
    }
    
    
    
    
    
    
    
    
    public function Special(ClientInterface $_87419315d6aaaec7dd2250b14245566e, IndexingInstruction $_8c5f17e2e918145535955f8a633b6c7b)
    {
        $_8e7f4b5c8440c0a24fb1b632eee28538 = $_8c5f17e2e918145535955f8a633b6c7b->extra[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_8e7f4b5c8440c0a24fb1b632eee28" . "538"]];
        if ($_8e7f4b5c8440c0a24fb1b632eee28538 !== $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_b0eaaa95" . "41f479b48" . "91f616111" . "7437b9"]) {
            throw new UnsupportedOperationException($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_945e7f180f5a" . "c7c426fa3d927" . "12223a3"] . $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_7aefd482de7885f4" . "293c2926df28c235"]($_8c5f17e2e918145535955f8a633b6c7b->extra));
        }
        $this->QueueFullReindex(true);
    }
}