/** * @desc Validates that the question is without PG errors as mandated by codecheck level. * @param $data array The form data that needs to be validated. * @return array An array of errors indexed by field. */ function validation($data) { //init $errors = array(); //build dataobject $dataobject = new stdClass(); $dataobject->code = $data['code']; $dataobject->codecheck = $data['codecheck']; //attempt to find an ID (if updating) if (isset($this->question->webwork)) { $dataobject->id = $this->question->webwork->getId(); } //try and build the question object try { if (isset($this->_form->_submitValues['makecopy'])) { $wwquestion = WebworkQuestionFactory::CreateFormCopy($dataobject); } else { if (isset($dataobject->id)) { $wwquestion = WebworkQuestionFactory::CreateFormUpdate($dataobject); } else { $wwquestion = WebworkQuestionFactory::CreateFormNew($dataobject); } } WebworkQuestionFactory::Store($data['storekey'], $wwquestion); } catch (Exception $e) { $errors['code'] = $e->getMessage(); } return $errors; }