<?php
namespace Claromentis\Quiz\Repository;

$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"] ?: array()) + array("_62d701c3c53404f06345eb35720a47" . "b4" => base64_decode("aXNfbnVtZX" . "JpYw=="), "question" . "_id" => base64_decode("cXVlc3Rpb25fa" . "WQ="), "_fee8f1bac1346f4f51472c32f6c6d7" . "69" => base64_decode("U2V0T3" . "B0aW9u" . "cw=="), "_fb181f138b94816d7290" . "1c265594bc96" => base64_decode("cXVlc3Rpb25faWQ" . "gPSBpbnQ6cXVlc3" . "Rpb25faWQ="), "_adf3905b2c4fe39180057e" . "61fefbcab4" => base64_decode("c29ydF9vcmRlciBBU0MsIG9wdG" . "lvbl90ZXh0IEFTQw=="), "_685e6aa3dcfb75b66aea7ec8bdc" . "fb565" => base64_decode("cXVlc3Rpb25fa" . "WQgSU4gaW46aW" . "50OnF1ZXN0aW9" . "uX2lkcw=="), "_d230962d9a57dc6ba2b7" . "74d9ba3bb81e" => base64_decode("bm" . "93"), "_78850c674ec5b1707600" . "0fcba7bb526f" => base64_decode("REVMRVRFIEZST00gcXVpel9vcHRpb24gV0hFUkUgcXVlc3Rp" . "b25faWQgPSBpbnQ6cXVlc3Rpb25faWQgQU5EIGlkIE5PVCBJ" . "TiBpbjppbnQ6b3B0aW9uX2lkcw=="), "i" . "d" => base64_decode("aW" . "Q="), "_ea449a1ba93a302c7d1611" . "f56e22449e" => base64_decode("cXVlc3Rpb25faWQgQVNDLCBzb3J0X29yZGVyIEFTQywgb3B0aW9uX3R" . "leHQgQVND"));
use Claromentis\Core\DAL;
use Claromentis\Quiz\Model;
use Claromentis\Core\Repository\Repository;
use Claromentis\Quiz\Util\Relations;




class OptionRepository extends Repository
{
    
    
    
    
    
    
    
    public function ListOptions($question_id)
    {
        $_03e9164d0a343b742df4793268b80767 = new DAL\QueryPart($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_fb181f138b94816d72901c2655" . "94bc96"], $question_id);
        
        
        
        
        $options = $this->GetObjects($_03e9164d0a343b742df4793268b80767, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_adf3905b2c4fe39180057e61fe" . "fbcab4"]);
        return $options;
    }
    
    
    
    
    
    
    
    public function GetQuestionOptions($questions)
    {
        $_ccac80360ec3a22ae939584a5b406d92 = static::PrepareQuestionIds($questions);
        $_03e9164d0a343b742df4793268b80767 = new DAL\QueryPart($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_685e6aa3d" . "cfb75b66ae" . "a7ec8bdcfb" . "565"], $_ccac80360ec3a22ae939584a5b406d92);
        
        
        
        
        $options = $this->GetObjects($_03e9164d0a343b742df4793268b80767, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_ea449a1ba93a302c7" . "d1611f56e22449e"]);
        return $options;
    }
    
    
    
    
    
    
    
    
    public function GetOptionsForQuestion($question, $option_id = 0)
    {
        $question_id = $question;
        if ($question instanceof Model\Question) {
            $question_id = $question->id;
        }
        if (!$option_id) {
            $options = $this->ListOptions($question_id);
        } else {
            $options = array($this->Get($option_id));
        }
        return $options;
    }
    
    
    
    
    
    
    
    public function LoadQuestionOptions(array $questions, $_3b0b788afd03419829052390c6bd8208 = null)
    {
        return Relations::LoadFor($questions, $this, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["question_i" . "d"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_fee8f1bac1346f4f51472c32f" . "6c6d769"], $_3b0b788afd03419829052390c6bd8208);
    }
    
    
    
    
    
    
    public function DeleteOptionsWithIgnoredId($question_id, array $_2f2518a4b87caa8e59d6bd3ff0b75a54)
    {
        $this->db->query($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_78850c674ec5b17076000fcba7b" . "b526f"], $question_id, $_2f2518a4b87caa8e59d6bd3ff0b75a54);
    }
    
    
    
    
    
    
    public function NewObject()
    {
        
        
        
        
        $_ab3f4d20f08bd694b2839e5c36c149a2 = parent::NewObject();
        return $_ab3f4d20f08bd694b2839e5c36c149a2;
    }
    
    
    
    
    
    
    
    
    
    protected static function PrepareQuestionIds($questions)
    {
        $_9cee5807b5bab08d25cd4213e63cb764 = array();
        foreach ($questions as $question) {
            if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_62d701c3c" . "53404f0634" . "5eb35720a4" . "7b4"]($question)) {
                $_9cee5807b5bab08d25cd4213e63cb764[] = $question;
            }
            if ($question instanceof Model\Question) {
                $_9cee5807b5bab08d25cd4213e63cb764[] = $question->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["i" . "d"]);
            }
        }
        return $_9cee5807b5bab08d25cd4213e63cb764;
    }
    
    
    
    
    
    
    
    public function DeleteOption(int $id) : bool
    {
        $_ab3f4d20f08bd694b2839e5c36c149a2 = $this->NewObject();
        $_ab3f4d20f08bd694b2839e5c36c149a2->id = $id;
        return parent::Delete($_ab3f4d20f08bd694b2839e5c36c149a2);
    }
    
    
    
    
    
    
    
    
    public function DuplicateOptions(int $question_id, int $_a7a52d915339013c9b4e71922a990578, int $user_id) : void
    {
        $options = $this->GetOptionsForQuestion($question_id);
        foreach ($options as $_ab3f4d20f08bd694b2839e5c36c149a2) {
            $_aa28ebaa9e17fc6a67b37600d92d6054 = new \Date($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_d230962d9a57dc6ba2b774d9b" . "a3bb81e"]);
            $_9938e643b3f5d6496bfe2b9cc873ffdb = $this->NewObject();
            $_9938e643b3f5d6496bfe2b9cc873ffdb->SetQuestionId($_a7a52d915339013c9b4e71922a990578);
            $_9938e643b3f5d6496bfe2b9cc873ffdb->SetType($_ab3f4d20f08bd694b2839e5c36c149a2->type);
            $_9938e643b3f5d6496bfe2b9cc873ffdb->SetOptionText($_ab3f4d20f08bd694b2839e5c36c149a2->option_text);
            $_9938e643b3f5d6496bfe2b9cc873ffdb->SetPoints(null);
            $_9938e643b3f5d6496bfe2b9cc873ffdb->SetCorrect(null);
            $_9938e643b3f5d6496bfe2b9cc873ffdb->SetSortOrder($_ab3f4d20f08bd694b2839e5c36c149a2->sort_order);
            $_9938e643b3f5d6496bfe2b9cc873ffdb->SetCreatedBy($user_id);
            $_9938e643b3f5d6496bfe2b9cc873ffdb->SetCreatedDate($_aa28ebaa9e17fc6a67b37600d92d6054->getDate());
            $this->Save($_9938e643b3f5d6496bfe2b9cc873ffdb);
        }
    }
}