function output_cas_text($title, $intro, $castext) { global $OUTPUT; echo $OUTPUT->heading($title, 3); echo html_writer::tag('p', $intro); echo html_writer::tag('pre', s($castext)); $ct = new stack_cas_text($castext, null, 0, 't'); echo html_writer::tag('p', format_text(stack_ouput_castext($ct->get_display_castext()))); echo output_debug(stack_string('errors'), $ct->get_errors()); echo output_debug(stack_string('debuginfo'), $ct->get_debuginfo()); }
/** * Validate a CAS text field. * @param array $errors the errors array that validation is assembling. * @param string $value the submitted value validate. * @param string $fieldname the name of the field add any errors to. * @param string $savesession the array key to save the session to in $this->validationcasstrings. * @return array updated $errors array. */ protected function validate_cas_text($errors, $value, $fieldname, $fixingdollars, $session = null) { if (!$fixingdollars && strpos($value, '$$') !== false) { $errors[$fieldname][] = stack_string('forbiddendoubledollars'); } $castext = new stack_cas_text($value, $session, $this->seed, 't'); if (!$castext->get_valid()) { $errors[$fieldname][] = $castext->get_errors(); return $errors; } // Validate any [[facts:...]] tags. $unrecognisedtags = stack_fact_sheets::get_unrecognised_tags($value); if ($unrecognisedtags) { $errors[$fieldname][] = stack_string('unrecognisedfactstags', array('tags' => implode(', ', $unrecognisedtags))); return $errors; } if ($session) { $display = $castext->get_display_castext(); if ($castext->get_errors()) { $errors[$fieldname][] = $castext->get_errors(); return $errors; } } return $errors; }
/** * Subsitute variables into the feedback text. * @param string $feedback the concatenated feedback text. * @return string the feedback with question variables substituted. */ public function substitue_variables_in_feedback($feedback) { $feedbackct = new stack_cas_text($feedback, $this->cascontext, $this->seed, 't', false, 0); $result = $feedbackct->get_display_castext(); $this->_errors = trim($this->_errors . ' ' . $feedbackct->get_errors()); return $result; }
public function test_empty_strings() { $s = '@"This is a string"@ whereas this is empty @""@.'; $at2 = new stack_cas_text($s, null, 0, 't'); $this->assertTrue($at2->get_valid()); $at2->get_display_castext(); $this->assertEquals($at2->get_display_castext(), '\\(\\mbox{This is a string}\\) whereas this is empty \\(\\mbox{ }\\).'); }
if (!$vars and !$string) { $simp = true; } if ($string) { $options = new stack_options(); $options->set_site_defaults(); $options->set_option('simplify', $simp); $session = new stack_cas_session(null, $options); if ($vars) { $keyvals = new stack_cas_keyval($vars, $options, 0, 't'); $session = $keyvals->get_session(); $varerrs = $keyvals->get_errors(); } if (!$varerrs) { $ct = new stack_cas_text($string, $session, 0, 't'); $displaytext = $ct->get_display_castext(); $errs = $ct->get_errors(); $debuginfo = $ct->get_debuginfo(); } } echo $OUTPUT->header(); echo $OUTPUT->heading($title); echo html_writer::tag('p', stack_string('chatintro')); // If we are editing the General Feedback from a question it is very helpful to see the question text. if ($questionid) { echo $OUTPUT->heading(stack_string('questiontext'), 3); echo html_writer::tag('pre', $question->questiontext, array('class' => 'questiontext')); } if (!$varerrs) { if ($string) { echo $OUTPUT->box(stack_ouput_castext($displaytext));