File:  [Local Repository] / db / prgsrc / drupal / modules / chgk_db / classes / DbQuestion / DbQuestionJeopardy.class.php
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Sat Mar 20 17:23:42 2010 UTC (14 years, 1 month ago) by roma7
Branches: MAIN
CVS tags: HEAD
issue http://db.chgk.info/v2/node/10

<?php

require_once (dirname(__FILE__)."/../DbQuestion.class.php");
require_once (dirname(__FILE__)."/../DbField/DbFieldJeopardyItem.class.php");
require_once (dirname(__FILE__)."/../DbField/DbFieldAnswer.class.php");

class DbQuestionJeopardy extends DbQuestion {

  public $theme;
  public $questions;

  public function getHtml() {
    $this->packSources();
    return theme('chgk_db_jeopardy_question', $this);
  }
  

  protected function setFields() {
    parent::setFields();
    $this->split();
    $this->packSources();
  }

  private function packSources() {
      if (!isset ($this->fields['Sources'])) {
          return;
      }
      $this->fields['Sources']->pack();
  }

  private function split() {
    $this->splitQuestions();
    $this->splitAnswers();
  }

  private function splitAnswers(){
    $a = "dummy\n". $this->getField('Answer')->getValue();
    $parts = preg_split('/\n\s+(\d+)\.\s*/', $a, -1, PREG_SPLIT_DELIM_CAPTURE);
    array_shift($parts);
    while ($parts) {
      $number = array_shift($parts);
      $text  = array_shift($parts);
      $this->questions[$number]->Answer=
              new DbFieldAnswer('', $text, $number);
    }
  }

  private function splitQuestions() {
    $q = $this->getField('Question')->getValue();
    $parts = preg_split('/\n\s+(\d+)\.\s*/', $q, -1, PREG_SPLIT_DELIM_CAPTURE);
    $this->theme = array_shift($parts);
    while ($parts) {
      $number = array_shift($parts);
      $text  = array_shift($parts);
      $row = new stdClass();
      $row->Question = new DbFieldQuestion('', $text, $number);
      $row->number = $number;
      $this->questions[$number]=$row;
    }
  }
}

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