public function adapt_to_model_answer($teacheranswer) { // Work out how big the matrix should be from the INSTANTIATED VALUE of the teacher's answer. $cs = new stack_cas_casstring('ta:matrix_size(' . $teacheranswer . ')'); $cs->get_valid('t'); $at1 = new stack_cas_session(array($cs), null, 0); $at1->instantiate(); if ('' != $at1->get_errors()) { $this->errors = $at1->get_errors(); return; } $size = $at1->get_value_key('ta'); $dimensions = explode(',', $size); $this->height = trim($dimensions[0], '[]'); $this->width = trim($dimensions[1], '[]'); }
private function validate() { if (empty($this->raw) or '' == trim($this->raw)) { $this->valid = true; return true; } // CAS keyval may not contain @ or $. if (strpos($this->raw, '@') !== false || strpos($this->raw, '$') !== false) { $this->errors = stack_string('illegalcaschars'); $this->valid = false; return false; } // Subtle one: must protect things inside strings before we explode. $str = $this->raw; $strings = stack_utils::all_substring_strings($str); foreach ($strings as $key => $string) { $str = str_replace('"' . $string . '"', '[STR:' . $key . ']', $str); } $str = str_replace("\n", ';', $str); $str = stack_utils::remove_comments($str); $str = str_replace(';', "\n", $str); $kvarray = explode("\n", $str); foreach ($strings as $key => $string) { foreach ($kvarray as $kkey => $kstr) { $kvarray[$kkey] = str_replace('[STR:' . $key . ']', '"' . $string . '"', $kstr); } } // 23/4/12 - significant changes to the way keyvals are interpreted. Use Maxima assignmentsm i.e. x:2. $errors = ''; $valid = true; $vars = array(); foreach ($kvarray as $kvs) { $kvs = trim($kvs); if ('' != $kvs) { $cs = new stack_cas_casstring($kvs); $cs->get_valid($this->security, $this->syntax, $this->insertstars); $vars[] = $cs; } } $this->session->add_vars($vars); $this->valid = $this->session->get_valid(); $this->errors = $this->session->get_errors(); }