Ejemplo n.º 1
0
 public function get_errors($casdebug = false)
 {
     if (null === $this->valid) {
         $this->validate();
     }
     if ($casdebug) {
         return $this->errors . $this->session->get_debuginfo();
     }
     return $this->errors;
 }
 /**
  *
  *
  * @return bool
  * @access public
  */
 public function do_test()
 {
     if ('' == trim($this->sanskey)) {
         $this->aterror = stack_string('TEST_FAILED', array('errors' => stack_string("AT_EmptySA")));
         $this->atfeedback = stack_string('TEST_FAILED', array('errors' => stack_string("AT_EmptySA")));
         $this->atansnote = $this->casfunction . 'TEST_FAILED:Empty SA.';
         $this->atmark = 0;
         $this->atvalid = false;
         return null;
     }
     if ('' == trim($this->tanskey)) {
         $this->aterror = stack_string('TEST_FAILED', array('errors' => stack_string("AT_EmptyTA")));
         $this->atfeedback = stack_string('TEST_FAILED', array('errors' => stack_string("AT_EmptyTA")));
         $this->atansnote = $this->casfunction . 'TEST_FAILED:Empty TA.';
         $this->atmark = 0;
         $this->atvalid = false;
         return null;
     }
     if ($this->processcasoptions) {
         if (null == $this->atoption or '' == $this->atoption) {
             $this->aterror = 'TEST_FAILED';
             $this->atfeedback = stack_string('TEST_FAILED', array('errors' => stack_string("AT_MissingOptions")));
             $this->atansnote = 'STACKERROR_OPTION.';
             $this->atmark = 0;
             $this->atvalid = false;
             return null;
         } else {
             // Validate with teacher privileges, strict syntax & no automatically adding stars.
             $ct = new stack_cas_casstring($this->atoption);
             if (!$ct->get_valid('t', true, 1)) {
                 $this->aterror = 'TEST_FAILED';
                 $this->atfeedback = stack_string('TEST_FAILED', array('errors' => ''));
                 $this->atfeedback .= stack_string('AT_InvalidOptions', array('errors' => $ct->get_errors()));
                 $this->atansnote = 'STACKERROR_OPTION.';
                 $this->atmark = 0;
                 $this->atvalid = false;
                 return null;
             }
         }
         $atopt = $this->atoption;
         $ta = "[{$this->tanskey},{$atopt}]";
     } else {
         $ta = $this->tanskey;
     }
     // Sort out options.
     if (null === $this->options) {
         $this->options = new stack_options();
     }
     if (!(null === $this->simp)) {
         $this->options->set_option('simplify', $this->simp);
     }
     $cascommands = array();
     $cascommands[] = "STACKSA:{$this->sanskey}";
     $cascommands[] = "STACKTA:{$ta}";
     $cascommands[] = "result:StackReturn({$this->casfunction}(STACKSA,STACKTA))";
     $cts = array();
     foreach ($cascommands as $com) {
         $cs = new stack_cas_casstring($com);
         $cs->get_valid('t', true, 0);
         $cts[] = $cs;
     }
     $session = new stack_cas_session($cts, $this->options, 0);
     $session->instantiate();
     $this->debuginfo = $session->get_debuginfo();
     if ('' != $session->get_errors_key('STACKSA')) {
         $this->aterror = 'TEST_FAILED';
         $this->atfeedback = stack_string('TEST_FAILED', array('errors' => $session->get_errors_key('STACKSA')));
         $this->atansnote = $this->casfunction . '_STACKERROR_SAns.';
         $this->atmark = 0;
         $this->atvalid = false;
         return null;
     }
     if ('' != $session->get_errors_key('STACKTA')) {
         $this->aterror = 'TEST_FAILED';
         $this->atfeedback = stack_string('TEST_FAILED', array('errors' => $session->get_errors_key('STACKTA')));
         $this->atansnote = $this->casfunction . '_STACKERROR_TAns.';
         $this->atmark = 0;
         $this->atvalid = false;
         return null;
     }
     $sessionvars = $session->get_session();
     $result = $sessionvars[2];
     if ('' != $result->get_errors()) {
         $this->aterror = 'TEST_FAILED';
         if ('' != trim($result->get_feedback())) {
             $this->atfeedback = $result->get_feedback();
         } else {
             $this->atfeedback = stack_string('TEST_FAILED', array('errors' => $result->get_errors()));
         }
         $this->atansnote = trim($result->get_answernote());
         $this->atmark = 0;
         $this->atvalid = false;
         return null;
     }
     $this->atansnote = trim($result->get_answernote());
     // Convert the Maxima string 'true' to PHP true.
     if ('true' == $result->get_value()) {
         $this->atmark = 1;
     } else {
         $this->atmark = 0;
     }
     $this->atfeedback = $result->get_feedback();
     $this->atvalid = $result->get_valid();
     if ($this->atmark) {
         return true;
     } else {
         return false;
     }
 }