public function dataAction() { $request = $this->getRequest(); $id = $this->getSanParam('id'); //get training and evaluation ids list($evaluation_id, $training_id) = Evaluation::fetchAssignment($id); if (!$evaluation_id) { $status->setStatusMessage(t('The evaluation could not be loaded.')); return; } //load training $trainingTable = new Training(); $course_name = $trainingTable->getCourseName($training_id); $this->view->assign('course_name', $course_name); list($title, $qtext, $qtype, $qid) = $this->_fetchQuestions($evaluation_id); $answerArray = Evaluation::fetchRelatedCustomAnswers($evaluation_id); if ($request->isPost()) { //validate $status = ValidationContainer::instance(); if ($status->hasError()) { $status->setStatusMessage(t('The evaluation could not be saved.')); } else { //make sure we have at least one response $found = false; foreach ($qid as $qidi) { if ($this->getSanParam('value_' . $qidi) !== null && $this->getSanParam('value_' . $qidi) !== '') { $found = true; } } if ($found) { //save response row $qr_table = new ITechTable(array('name' => 'evaluation_response')); $qr_row = $qr_table->createRow(); $qr_row->evaluation_to_training_id = $id; if (isset($qr_row->trainer_person_id)) { $qr_row->trainer_person_id = $this->getSanParam('trainer_id') ? $this->getSanParam('trainer_id') : null; } if (isset($qr_row->person_id)) { $qr_row->person_id = $this->getSanParam('person_id') ? $this->getSanParam('person_id') : null; } $qr_id = $qr_row->save(); //save question rows $erq_table = new ITechTable(array('name' => 'evaluation_question_response')); foreach ($qid as $qk => $qidi) { // $q_table = new ITechTable(array('name'=>'evaluation_question')); $qrow = $erq_table->createRow(); $qrow->evaluation_response_id = $qr_id; $qrow->evaluation_question_id = $qidi; $response_value = $this->getSanParam('value_' . $qidi); if ($qtype[$qk] == 'Text' || !empty($answerArray[$qidi])) { // is text or relabeled (will store as text) $qrow->value_text = $response_value; } else { $qrow->value_int = $response_value; } if ($response_value) { $qrow->save(); } } } if ($this->getSanParam('go')) { $this->_redirect('training/edit/id/' . $training_id); } } } $this->view->assign('title', $title); $this->view->assign('qtext', $qtext); $this->view->assign('qtype', $qtype); $this->view->assign('qid', $qid); $this->view->assign('answers', $answerArray); // list of trainers require_once 'models/table/TrainingToTrainer.php'; require_once 'models/table/PersonToTraining.php'; $this->view->assign('trainers', TrainingToTrainer::getTrainers($training_id)->toArray()); $this->view->assign('participants', PersonToTraining::getParticipants($training_id)->toArray()); // all evaluations attached to this training if ($training_id) { $otherEvalDropDown = ''; $db = $this->dbfunc(); $otherEvals = $db->fetchAll('SELECT ett.id, evaluation_id, title FROM evaluation_to_training as ett LEFT JOIN evaluation e ON e.id = ett.evaluation_id WHERE e.is_deleted = 0 AND ett.training_id = ?', $training_id); if ($otherEvals && count($otherEvals) > 1) { $selectOptions = array(); foreach ($otherEvals as $v) { if ($v['id'] && $v['title']) { $selectOptions[] = "<option value=\"{$v['id']}\"" . ($id == $v['id'] ? ' selected' : '') . ">{$v['title']}</option>"; } } $otherEvalDropDown = '<select id="other_evals" name="other_evals">' . implode('', $selectOptions) . '</select>'; } $this->view->assign('otherEvalDropDown', $otherEvalDropDown); } }