Annotation of db/prgsrc/drupal/modules/chgk_db/classes/DbQuestion/DbQuestionJeopardy.class.php, revision 1.1

1.1     ! roma7       1: <?php
        !             2: 
        !             3: require_once (dirname(__FILE__)."/../DbQuestion.class.php");
        !             4: require_once (dirname(__FILE__)."/../DbField/DbFieldJeopardyItem.class.php");
        !             5: require_once (dirname(__FILE__)."/../DbField/DbFieldAnswer.class.php");
        !             6: 
        !             7: class DbQuestionJeopardy extends DbQuestion {
        !             8: 
        !             9:   public $theme;
        !            10:   public $questions;
        !            11: 
        !            12:   public function getHtml() {
        !            13:     $this->packSources();
        !            14:     return theme('chgk_db_jeopardy_question', $this);
        !            15:   }
        !            16:   
        !            17: 
        !            18:   protected function setFields() {
        !            19:     parent::setFields();
        !            20:     $this->split();
        !            21:     $this->packSources();
        !            22:   }
        !            23: 
        !            24:   private function packSources() {
        !            25:       if (!isset ($this->fields['Sources'])) {
        !            26:           return;
        !            27:       }
        !            28:       $this->fields['Sources']->pack();
        !            29:   }
        !            30: 
        !            31:   private function split() {
        !            32:     $this->splitQuestions();
        !            33:     $this->splitAnswers();
        !            34:   }
        !            35: 
        !            36:   private function splitAnswers(){
        !            37:     $a = "dummy\n". $this->getField('Answer')->getValue();
        !            38:     $parts = preg_split('/\n\s+(\d+)\.\s*/', $a, -1, PREG_SPLIT_DELIM_CAPTURE);
        !            39:     array_shift($parts);
        !            40:     while ($parts) {
        !            41:       $number = array_shift($parts);
        !            42:       $text  = array_shift($parts);
        !            43:       $this->questions[$number]->Answer=
        !            44:               new DbFieldAnswer('', $text, $number);
        !            45:     }
        !            46:   }
        !            47: 
        !            48:   private function splitQuestions() {
        !            49:     $q = $this->getField('Question')->getValue();
        !            50:     $parts = preg_split('/\n\s+(\d+)\.\s*/', $q, -1, PREG_SPLIT_DELIM_CAPTURE);
        !            51:     $this->theme = array_shift($parts);
        !            52:     while ($parts) {
        !            53:       $number = array_shift($parts);
        !            54:       $text  = array_shift($parts);
        !            55:       $row = new stdClass();
        !            56:       $row->Question = new DbFieldQuestion('', $text, $number);
        !            57:       $row->number = $number;
        !            58:       $this->questions[$number]=$row;
        !            59:     }
        !            60:   }
        !            61: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>