tra('Mini Quiz'), 'documentation' => 'PluginMiniQuiz', 'description' => tra('Create a quiz using a tracker'), 'prefs' => [ 'feature_trackers', 'wikiplugin_miniquiz' ], 'body' => tra('Instructions::Feedback'), 'iconname' => 'help', 'introduced' => 1, 'format' => 'html', 'params' => [ 'trackerId' => [ 'required' => true, 'name' => tra('Tracker ID'), 'description' => tra('Numeric value representing the miniquiz tracker ID'), 'since' => '1', 'default' => '', 'profile_reference' => 'tracker', ], ], ]; } function rcmp($a, $b) { return mt_rand(-1, 1); } function shuf(&$ar) { srand((double) microtime() * 10000000); uksort($ar, "rcmp"); } function wikiplugin_miniquiz($data, $params) { global $prefs; $trklib = TikiLib::lib('trk'); if ($prefs['feature_trackers'] != 'y' || ! isset($params['trackerId']) || ! ($tracker = $trklib->get_tracker($params['trackerId']))) { $smarty = TikiLib::lib('smarty'); return $smarty->fetch("wiki-plugins/error_tracker.tpl"); } $items = $trklib->list_tracker_items($params['trackerId'], 0, -1, 'lastModif_desc', '', 'o'); $info = []; foreach ($items['data'] as $it) { $id = $it['itemId']; foreach ($it['field_values'] as $val) { $field = $val['name']; $info["$id"]["$field"] = $val['value']; } $info["$id"]['qresult'] = 'n'; } $back = ''; if ($tracker) { $success_mess[] = "Wow !"; $success_mess[] = "Congratulation !"; $success_mess[] = "Success !"; $success_mess[] = "Excellent !"; $success_mess[] = "Superb !"; $success_mess[] = "Bravo !"; $success_mess[] = "Well done !"; $success_comment[] = "You found it right !"; $success_comment[] = "This is correct."; $success_comment[] = "You are the best !"; $success_comment[] = "The answer is correct."; $success_comment[] = "Your cleverness is amazing."; $success_comment[] = "Go on that way !"; $failed_mess[] = "Wrong !"; $failed_mess[] = "Too bad !"; $failed_mess[] = "No luck !"; $failed_mess[] = "Failed !"; $failed_mess[] = "Argh !"; $failed_mess[] = "Missed !"; $failed_comment[] = "Please think before clicking."; $failed_comment[] = "Did you read the question before reading the answer ?"; $failed_comment[] = "Try again."; $failed_comment[] = "Get another chance."; $failed_comment[] = "Think carefully that time."; $failed_comment[] = "Use the force !"; $failed_comment[] = "You should concentrate a little more."; if (isset($_REQUEST['quizit']) and $_REQUEST['quizit']) { if (isset($_REQUEST['answer']) and is_array($_REQUEST['answer'])) { foreach ($_REQUEST['answer'] as $q => $a) { if ($info["$q"]['answer'] == $a) { $info["$q"]['qresult'] = 'y'; } else { $info["$q"]['qresult'] = $a; } } } else { $back .= '
Please fill the quiz!
'; } } $back .= '
'; $back .= ''; $back .= ''; $back .= '
' . $tracker["description"] . '

'; $back .= ''; foreach ($info as $id => $item) { if (isset($item['valid']) and $item['valid'] == 'y') { $back .= '
' . $item['question'] . '
'; if ($item['qresult'] !== 'n') { if ($item['qresult'] == 'y') { $back .= '
'; if (! isset($_POST["$id"])) { $back .= '' . $success_mess[array_rand($success_mess)] . ' ' . $success_comment[array_rand($success_comment)] . '
'; } $back .= 'The answer was: ' . $item['answer'] . '

'; $back .= ''; $back .= ''; } else { $back .= '
'; $back .= '' . $failed_mess[array_rand($failed_mess)] . ' ' . $failed_comment[array_rand($failed_comment)] . '
'; } } $option_base = 'option '; $options = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']; $answers = [$item['answer']]; foreach ($options as $option) { if (isset($item[$option_base . $option])) { $answers[] = $item[$option_base . $option]; } } shuf($answers); $back .= '
'; $i = 1; foreach ($answers as $aid => $answer) { $back .= '
' . $answer . ''; $back .= '
'; } $back .= '

'; } } $back .= "
"; $back .= '
'; $back .= '
Students: Suggest a new question
'; $back .= "
"; } else { $back = "No such id in trackers."; } return $back; }