public function addCopyAction() { if (!$this->hasACL('edit_evaluations')) { $this->doNoAccessError(); } $request = $this->getRequest(); $qtext = $this->getSanParam('qtext'); $qtype = $this->getSanParam('qtype'); $title = $this->getSanParam('title'); if ($request->isPost()) { //validate $status = ValidationContainer::instance(); $status->checkRequired($this, 'title', t('Title')); foreach ($qtext as $i => $t) { if ($t and !$qtype[$i]) { $status->addError('qtype', t('You must choose a question type for each question.')); break; } if (!$t and $qtype[$i]) { $status->addError('qtype', t('You must enter question text for each question.')); break; } } $custom_answers = array(); $useCustomAnswers = $this->getSanParam('qrelabel'); foreach ($qtext as $i => $val) { $custom_answers[] = $useCustomAnswers[$i] ? $this->getSanParam('answers' . ($i + 1)) : array(); } if ($status->hasError()) { $status->setStatusMessage(t('The evaluation could not be saved.')); } else { $ev = new Evaluation(); $ev_row = $ev->createRow(array('title' => $title)); if ($id = $ev_row->save()) { $ev->insertQuestions($id, $qtext, $qtype, $custom_answers); $status->setStatusMessage(t('The new evaluation was created.')); $this->_redirect('evaluation/browse'); } else { $status->setStatusMessage(t('The evaluation could not be saved.')); } } } else { if ($id = $this->getSanParam('id')) { list($title, $qtext, $qtype, $qid) = $this->_fetchQuestions(); } } $this->view->assign('title', $title); $this->view->assign('qtext', $qtext); $this->view->assign('qtype', $qtype); }