/** * Creates an option and adds it to the receiver * * @param String $value * @param String $label * @param (boolean) $checked * @param (String) $id */ public function createOption($value, $label, $checked = false, $id = null) { // by incoming request $val = $this->getRequestValue(); if ($val != null && $val == $value) { $checked = true; } else { if ($val != null && $val != $value) { $checked = false; } } $option = new Option(); $option->setValue($value); $option->setLabel($label); $option->setChecked($checked); if (!is_null($id)) { $option->setId($id); } $this->options[] = $option; return $option; }
/** * @return Question * @param int $id */ public static function get($id) { $db = DB::getConn(); $stm = $db->prepare('select * from Question where id = :id'); $stm->bindParam(':id', $id); $stm->execute(); $rs = $stm->fetchAll()[0]; $q = new Question($rs['category'], $rs['point'], $rs['title'], $rs['explain']); $q->setId($id); $stm = $db->prepare('select * from Option where question = :id'); $stm->bindParam(':id', $id); $stm->execute(); $arr = $stm->fetchAll(); foreach ($arr as $o) { $opt = new Option($o['question'], $o['title'], $o['isCorrect'] ? true : false); $opt->setId($o['id']); $q->addOpt($opt); } return $q; }
QuestionCtrl::addOption($o); } $opt3 = htmlspecialchars($_POST['opt3']); $optCR3 = isset($_POST['opt3-cr']); $o = new Option($qid, $opt3, $optCR3); if ($update) { $o->setId($_POST['o3-id']); QuestionCtrl::updateOption($o); } else { QuestionCtrl::addOption($o); } $opt4 = htmlspecialchars($_POST['opt4']); $optCR4 = isset($_POST['opt4-cr']); $o = new Option($qid, $opt4, $optCR4); if ($update) { $o->setId($_POST['o4-id']); QuestionCtrl::updateOption($o); } else { QuestionCtrl::addOption($o); } $ok = ''; } } $submit = 'Save'; $text = 'added'; $text_css = 'success'; $title = 'New Question'; if (isset($_GET['id']) && $_GET['id'] != '') { $id = $_GET['id']; $link = '&id=' . $id; $text = 'updated';