Example #1
0
 /**
  * Creates a Problem.
  * @param $type Problem type: 'text', 'equation', ... ?
  * @param $content An xml string with the problem content. The format depends on the $type.
  */
 public static function create($type, $content)
 {
     if ($type == 'text') {
         return ProblemFactory::createText($content);
     }
     throw new Exception("Problem type {$type} is undefined.");
 }
Example #2
0
 function testTextProblem()
 {
     $content = '<problem><text>Problem question.</text><answer>The answer.</answer></problem>';
     $p = ProblemFactory::create('text', $content);
     $txt = $p->getText();
     echo "text={$txt}\nans={$p->answer}\n";
     $this->assertEqual($p->getText(), 'Problem question.');
     $this->assertEqual($p->answer, 'The answer.');
 }
Example #3
0
 /**
  * Initializes the inputs with existing post data.
  * This method is invoked by the framework when the page is being initialized.
  * @param mixed event parameter
  */
 public function onInit($param)
 {
     parent::onInit($param);
     // Retrieves the existing user data. This is equivalent to:
     // $postRecord=$this->getPost();
     $problemRecord = $this->Problem;
     // Authorization check: only the author or the administrator can edit the post
     //if($postRecord->author_id!==$this->User->Name && !$this->User->IsAdmin)
     //    throw new THttpException(500,'You are not allowed to edit this post.');
     if (!$this->IsPostBack) {
         // Populates the input controls with the existing post data
         $p = ProblemFactory::create($problemRecord->problem_type, $problemRecord->content);
         $this->TextEdit->Text = $p->getText();
         $this->AnswerEdit->Text = $p->answer;
     }
 }
Example #4
0
 public function define()
 {
     $p = ProblemFactory::newProblem("Test");
     $x = $p->variable('X', 1, 10);
     $y = $p->variable('Y', 1, 10);
     $z = $p->variable('Z', 1, 10);
     $r = $p->variable('R', 1, 10);
     $vars = array($x, $y, $z, $r);
     $p->post($x, '<', $y);
     $p->post($z, '>', 4);
     $p->post($x->plus($y), '=', $z);
     $p->postAllDifferent($vars);
     $coef1 = array(3, 4, -5, 2);
     $p->post($coef1, $vars, '>', 0);
     $p->post($vars, '>=', 15);
     $coef2 = array(2, -4, 5, 1);
     $p->post($coef2, $vars, '>', $x->multiply($y));
     $this->problem = $p;
     $this->data = $vars;
 }
Example #5
0
 public function getText()
 {
     $p = ProblemFactory::create($this->Data->problem_type, $this->Data->content);
     return $p->getText();
 }