<?php
namespace Claromentis\Quiz\Repository;

$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] ?: array()) + array("_fee8f1bac1346f4f5147" . "2c32f6c6d769" => base64_decode("U2V0T3B0aW9ucw" . "=="), "_78850c674ec5b17076" . "000fcba7bb526f" => base64_decode("REVMRVRFIEZST00gcXVpel9vcHRpb24gV0hFUkUgcXVlc3Rpb25faWQgPSBpbnQ6cXVlc3Rpb25faWQgQU5EIGlkIE5PVCBJTiBpbjp" . "pbnQ6b3B0aW9uX2lkcw=="), "question_" . "id" => base64_decode("cXVlc3Rpb" . "25faWQ="), "_d230962d9a57dc6" . "ba2b774d9ba3bb81" . "e" => base64_decode("bm9" . "3"), "_62d701c3c53404f06345eb3572" . "0a47b4" => base64_decode("aXNfbnVtZX" . "JpYw=="), "_fb181f138b94816d" . "72901c265594bc96" => base64_decode("cXVlc3Rpb25faW" . "QgPSBpbnQ6cXVl" . "c3Rpb25faWQ="), "_ea449a1ba93a302c7d1" . "611f56e22449e" => base64_decode("cXVlc3Rpb25faWQgQVNDLCBzb3J0X29yZGVyIEFTQywgb3B0aW9u" . "X3RleHQgQVND"), "_685e6aa3dcfb75b66aea7ec8bdcfb56" . "5" => base64_decode("cXVlc3Rpb25faWQgSU4" . "gaW46aW50OnF1ZXN0aW" . "9uX2lkcw=="), "_adf3905b2c4fe39180057e61f" . "efbcab4" => base64_decode("c29ydF9vcmRlciBBU0MsIG9wdGlvbl90ZXh0" . "IEFTQw=="), "i" . "d" => base64_decode("aW" . "Q="));
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["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_fb181f138b94816d72901c265594bc9" . "6"], $question_id);
        
        
        
        
        $options = $this->GetObjects($_03e9164d0a343b742df4793268b80767, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_adf3905b2c4fe39180" . "057e61fefbcab4"]);
        return $options;
    }
    
    
    
    
    
    
    
    public function GetQuestionOptions($questions)
    {
        $_ccac80360ec3a22ae939584a5b406d92 = static::PrepareQuestionIds($questions);
        $_03e9164d0a343b742df4793268b80767 = new DAL\QueryPart($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_685e6aa3dcfb75b66aea7ec8b" . "dcfb565"], $_ccac80360ec3a22ae939584a5b406d92);
        
        
        
        
        $options = $this->GetObjects($_03e9164d0a343b742df4793268b80767, $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_ea449a1ba93a" . "302c7d1611f56" . "e22449e"]);
        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["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["question_" . "id"], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_fee8f1bac1346f4f5147" . "2c32f6c6d769"], $_3b0b788afd03419829052390c6bd8208);
    }
    
    
    
    
    
    
    public function DeleteOptionsWithIgnoredId($question_id, array $_2f2518a4b87caa8e59d6bd3ff0b75a54)
    {
        $this->db->query($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_78850c674ec5b17076000fcba7bb526" . "f"], $question_id, $_2f2518a4b87caa8e59d6bd3ff0b75a54);
    }
    
    
    
    
    
    
    public function NewObject()
    {
        
        
        
        
        $_ab3f4d20f08bd694b2839e5c36c149a2 = parent::NewObject();
        return $_ab3f4d20f08bd694b2839e5c36c149a2;
    }
    
    
    
    
    
    
    
    
    
    protected static function PrepareQuestionIds($questions)
    {
        $_9cee5807b5bab08d25cd4213e63cb764 = array();
        foreach ($questions as $question) {
            if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_62d701c3c53404" . "f06345eb35720a4" . "7b4"]($question)) {
                $_9cee5807b5bab08d25cd4213e63cb764[] = $question;
            }
            if ($question instanceof Model\Question) {
                $_9cee5807b5bab08d25cd4213e63cb764[] = $question->GetProperty($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["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["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_d230962d9a57dc6" . "ba2b774d9ba3bb81" . "e"]);
            $_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);
        }
    }
}