本文整理汇总了PHP中Question::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::read方法的具体用法?PHP Question::read怎么用?PHP Question::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Question
的用法示例。
在下文中一共展示了Question::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editQuestionAction
/**
* Edits a question for the question manager
*
* @param Application $app
* @param int $id
* @return Response
*/
public function editQuestionAction(Application $app, $id)
{
$extraJS = array();
//@todo improve this JS includes should be added using twig
$extraJS[] = '<link href="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$extraJS[] = '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$app['extraJS'] = $extraJS;
// Setting exercise obj.
$exercise = new \Exercise();
$exercise->edit_exercise_in_lp = true;
// Setting question obj.
/** @var \Question $question */
$question = \Question::read($id, null, $exercise);
$question->submitClass = "btn save";
$question->submitText = get_lang('ModifyQuestion');
$question->setDefaultValues = true;
// Generating edit URL.
$url = $app['url_generator']->generate('admin_questions_edit', array('id' => $id));
// Creating a new form
$form = new \FormValidator('edit_question', 'post', $url);
$extraFields = new \ExtraField('question');
$extraFields->addElements($form, $id);
// Validating if there are extra fields to modify.
if (count($form->_elements) > 1) {
$form->addElement('button', 'submit', get_lang('Update'));
$app['template']->assign('question', $question);
$app['template']->assign('form', $form->toHtml());
} else {
$app['template']->assign('message', \Display::return_message(get_lang('ThereAreNotExtrafieldsAvailable'), 'warning'));
}
// If form was submitted.
if ($form->validate()) {
$field_value = new \ExtraFieldValue('question');
$params = $form->exportValues();
$params['question_id'] = $id;
$field_value->save_field_values($params);
$app['template']->assign('message', \Display::return_message(get_lang('ItemUpdated'), 'success'));
$url = $app['url_generator']->generate('admin_questions_edit', array('id' => $id));
return $app->redirect($url);
}
$response = $app['template']->render_template('admin/questionmanager/edit_question.tpl');
return new Response($response, 200, array());
}
示例2: editQuestionAction
/**
* Edits a question for the question manager
*
* @Route("/edit")
* @Method({"GET"})
* @param int $id
* @return Response
*/
public function editQuestionAction($id)
{
// Setting exercise obj.
$exercise = new \Exercise();
$exercise->edit_exercise_in_lp = true;
// Setting question obj.
/** @var \Question $question */
$question = \Question::read($id, null, $exercise);
$question->submitClass = "btn save";
$question->submitText = get_lang('ModifyQuestion');
$question->setDefaultValues = true;
// Generating edit URL.
$url = $this->generateControllerUrl('editQuestionAction', array('id' => $id));
// Creating a new form
$form = new \FormValidator('edit_question', 'post', $url);
$extraFields = new \ExtraField('question');
$extraFields->addElements($form, $id);
// Validating if there are extra fields to modify.
if (count($form->_elements) > 1) {
$form->addElement('button', 'submit', get_lang('Update'));
$this->getTemplate()->assign('question', $question);
$this->getTemplate()->assign('form', $form->toHtml());
} else {
$this->addFlash('warning', get_lang('ThereAreNotExtrafieldsAvailable'));
}
// If form was submitted.
if ($form->validate()) {
$field_value = new \ExtraFieldValue('question');
$params = $form->exportValues();
$params['question_id'] = $id;
$field_value->save_field_values($params);
$this->addFlash('success', get_lang('ItemUpdated'));
$url = $this->generateControllerUrl('editQuestionAction', array('id' => $id));
return $this->redirect($url);
}
$response = $this->renderTemplate('edit_question.tpl');
return new Response($response, 200, array());
}
示例3: foreach
foreach ($row_table as $cell) {
$table->setCellContents($row, $column, $cell);
$table->updateCellAttributes($row, $column, 'align="center"');
$column++;
}
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
$row++;
}
$content = $table->toHtml();
// Format B
$headers = array(get_lang('Question'), get_lang('Answer'), get_lang('Correct'), get_lang('NumberStudentWhoSelectedIt'));
$data = array();
if (!empty($question_list)) {
$id = 0;
foreach ($question_list as $question_id) {
$question_obj = Question::read($question_id);
$exercise_stats = get_student_stats_by_question($question_id, $exercise_id, $courseCode, $sessionId);
$answer = new Answer($question_id);
$answer_count = $answer->selectNbrAnswers();
for ($answer_id = 1; $answer_id <= $answer_count; $answer_id++) {
$answer_info = $answer->selectAnswer($answer_id);
$is_correct = $answer->isCorrect($answer_id);
$correct_answer = $is_correct == 1 ? get_lang('Yes') : get_lang('No');
$real_answer_id = $answer->selectAutoId($answer_id);
// Overwriting values depending of the question
switch ($question_obj->type) {
case FILL_IN_BLANKS:
$answer_info_db = $answer_info;
$answer_info = substr($answer_info, 0, strpos($answer_info, '::'));
$correct_answer = $is_correct;
$answers = $objExercise->fill_in_blank_answer_to_array($answer_info);
示例4: scoreAttemptAction
/**
* @Route("/score-attempt/{exeId}/jury/{juryId}")
* @Method({"GET"})
*/
public function scoreAttemptAction($exeId, $juryId)
{
$userId = $this->getUser()->getUserId();
$trackExercise = \ExerciseLib::get_exercise_track_exercise_info($exeId);
if (empty($trackExercise)) {
$this->createNotFoundException();
}
/** @var \Chamilo\CoreBundle\Entity\Jury $jury */
$jury = $this->getRepository()->find($juryId);
if (empty($jury)) {
$this->createNotFoundException('Jury does not exists');
}
if ($jury->getExerciseId() != $trackExercise['exe_exo_id']) {
$this->createNotFoundException('Exercise attempt is not related with this jury.');
}
$members = $jury->getMembers();
$criteria = Criteria::create()->where(Criteria::expr()->eq("userId", $userId))->setFirstResult(0)->setMaxResults(1);
/** @var JuryMembers $member */
$member = $members->matching($criteria)->first();
if (empty($member)) {
$this->createNotFoundException('You are not part of the jury.');
}
$students = $member->getStudents();
$criteria = Criteria::create()->where(Criteria::expr()->eq("userId", $trackExercise['exe_user_id']))->setFirstResult(0)->setMaxResults(1);
/** @var JuryMembers $member */
$student = $students->matching($criteria)->first();
if (empty($student)) {
$this->createNotFoundException('You are not assigned to this user.');
}
// Setting member only for president.
if ($this->isGranted('ROLE_JURY_PRESIDENT')) {
// Relating user with president
if ($member) {
$this->getManager()->getRepository('Chamilo\\CoreBundle\\Entity\\JuryMembers')->assignUserToJuryMember($trackExercise['exe_user_id'], $member->getId());
}
}
$questionScoreTypeModel = array();
$criteria = array('exeId' => $exeId, 'juryUserId' => $userId);
$trackJury = $this->getManager()->getRepository('Chamilo\\CoreBundle\\Entity\\TrackAttemptJury')->findBy($criteria);
if ($trackJury) {
$this->get('session')->getFlashBag()->add('info', "You already review this exercise attempt.");
/** @var TrackAttemptJury $track */
foreach ($trackJury as $track) {
$questionScoreTypeModel[$track->getQuestionId()] = $track->getQuestionScoreNameId();
}
}
$questionList = explode(',', $trackExercise['data_tracking']);
$exerciseResult = \ExerciseLib::getExerciseResult($trackExercise);
$counter = 1;
$objExercise = new \Exercise($trackExercise['c_id']);
$objExercise->read($trackExercise['exe_exo_id']);
$totalScore = $totalWeighting = 0;
$show_media = true;
$tempParentId = null;
$mediaCounter = 0;
$media_list = array();
$modelType = $objExercise->getScoreTypeModel();
$options = array();
if ($modelType) {
/** @var \Chamilo\CoreBundle\Entity\QuestionScore $questionScoreName */
$questionScore = $this->get('orm.em')->getRepository('Chamilo\\CoreBundle\\Entity\\QuestionScore')->find($modelType);
if ($questionScore) {
$items = $questionScore->getItems();
/** @var \Chamilo\CoreBundle\Entity\QuestionScoreName $score */
foreach ($items as $score) {
$options[$score->getId() . ':' . $score->getScore()] = $score;
}
}
} else {
return $this->createNotFoundException('The exercise does not contain a model type.');
}
$exerciseContent = null;
foreach ($questionList as $questionId) {
ob_start();
$choice = isset($exerciseResult[$questionId]) ? $exerciseResult[$questionId] : null;
// Creates a temporary Question object
/** @var \Question $objQuestionTmp */
$objQuestionTmp = \Question::read($questionId);
if ($objQuestionTmp->parent_id != 0) {
if (!in_array($objQuestionTmp->parent_id, $media_list)) {
$media_list[] = $objQuestionTmp->parent_id;
$show_media = true;
}
if ($tempParentId == $objQuestionTmp->parent_id) {
$mediaCounter++;
} else {
$mediaCounter = 0;
}
$counterToShow = chr(97 + $mediaCounter);
$tempParentId = $objQuestionTmp->parent_id;
}
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
$question_result = $objExercise->manageAnswers($exeId, $questionId, $choice, 'exercise_show', array(), false, true, true);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
//.........这里部分代码省略.........
示例5: Question
$objQuestionTmp = new Question();
// if the question exists
if ($objQuestionTmp->read($delete)) {
// deletes the question from all exercises
$objQuestionTmp->delete();
}
// destruction of the Question object
unset($objQuestionTmp);
//Session::set_flashdata($message, $class);
redirect_to_home_page("modules/exercise/question_pool.php?course={$course_code}" . (isset($fromExercise) ? "&fromExercise={$fromExercise}" : "") . "&exerciseId={$exerciseId}");
} elseif (isset($_GET['recup']) && isset($fromExercise)) {
$recup = intval($_GET['recup']);
// construction of the Question object
$objQuestionTmp = new Question();
// if the question exists
if ($objQuestionTmp->read($recup)) {
// adds the exercise ID into the list of exercises for the current question
$objQuestionTmp->addToList($fromExercise);
}
// destruction of the Question object
unset($objQuestionTmp);
// adds the question ID into the list of questions for the current exercise
$objExercise->addToList($recup);
Session::Messages($langQuestionReused, 'alert-success');
redirect_to_home_page("modules/exercise/question_pool.php?course={$course_code}" . (isset($fromExercise) ? "&fromExercise={$fromExercise}" : "") . "&exerciseId={$exerciseId}");
}
if (isset($fromExercise)) {
$action_bar_options[] = array('title' => $langGoBackToEx, 'url' => "admin.php?course={$course_code}&exerciseId={$fromExercise}", 'icon' => 'fa-reply', 'level' => 'primary-label');
} else {
$action_bar_options = array(array('title' => $langNewQu, 'url' => "admin.php?course={$course_code}&newQuestion=yes", 'icon' => 'fa-plus-circle', 'level' => 'primary-label', 'button-class' => 'btn-success'), array('title' => $langImportQTI, 'url' => "admin.php?course={$course_code}&importIMSQTI=yes", 'icon' => 'fa-download', 'level' => 'primary-label', 'button-class' => 'btn-success'), array('title' => $langExportQTI, 'url' => "question_pool.php?" . $_SERVER['QUERY_STRING'] . "&exportIMSQTI=yes", 'icon' => 'fa-upload', 'level' => 'primary-label', 'button-class' => 'btn-success'));
}
示例6: createAnswersForm
/**
* function which redefines Question::createAnswersForm
* @param FormValidator $form
*/
public function createAnswersForm($form)
{
// Getting the exercise list
$obj_ex = $_SESSION['objExercise'];
$editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
//this line defines how many questions by default appear when creating a choice question
// The previous default value was 2. See task #1759.
$nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4;
$nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
/*
Types of Feedback
$feedback_option[0]=get_lang('Feedback');
$feedback_option[1]=get_lang('DirectFeedback');
$feedback_option[2]=get_lang('NoFeedback');
*/
$feedback_title = '';
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
//Scenario
$editor_config['Width'] = '250';
$editor_config['Height'] = '110';
$comment_title = '<th width="500px" >' . get_lang('Comment') . '</th>';
$feedback_title = '<th width="350px" >' . get_lang('Scenario') . '</th>';
} else {
$comment_title = '<th>' . get_lang('Comment') . '</th>';
}
$html = '<table class="data_table">
<tr style="text-align: center;">
<th width="10px">
' . get_lang('Number') . '
</th>
<th width="10px" >
' . get_lang('True') . '
</th>
<th width="50%">
' . get_lang('Answer') . '
</th>
' . $comment_title . '
' . $feedback_title . '
<th width="50px">
' . get_lang('Weighting') . '
</th>
</tr>';
$form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html);
$defaults = array();
$correct = 0;
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$form->addElement('hidden', 'nb_answers');
//Feedback SELECT
$question_list = $obj_ex->selectQuestionList();
$select_question = array();
$select_question[0] = get_lang('SelectTargetQuestion');
require_once '../newscorm/learnpathList.class.php';
if (is_array($question_list)) {
foreach ($question_list as $key => $questionid) {
//To avoid warning messages
if (!is_numeric($questionid)) {
continue;
}
$question = Question::read($questionid);
$select_question[$questionid] = 'Q' . $key . ' :' . cut($question->selectTitle(), 20);
}
}
$select_question[-1] = get_lang('ExitTest');
$list = new LearnpathList(api_get_user_id());
$flat_list = $list->get_flat_list();
$select_lp_id = array();
$select_lp_id[0] = get_lang('SelectTargetLP');
foreach ($flat_list as $id => $details) {
$select_lp_id[$id] = cut($details['lp_name'], 20);
}
$temp_scenario = array();
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_answers; ++$i) {
$form->addElement('html', '<tr>');
if (isset($answer) && is_object($answer)) {
if ($answer->correct[$i]) {
$correct = $i;
}
$defaults['answer[' . $i . ']'] = $answer->answer[$i];
$defaults['comment[' . $i . ']'] = $answer->comment[$i];
$defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
$item_list = explode('@@', $answer->destination[$i]);
$try = $item_list[0];
$lp = $item_list[1];
$list_dest = $item_list[2];
$url = $item_list[3];
if ($try == 0) {
//.........这里部分代码省略.........
示例7: api_get_course_info
$form->setDefaults(array('course_code' => (string) $course_code));
$course_info = api_get_course_info($course_code);
if (!empty($course_info)) {
$list = new LearnpathList('', $course_code);
$lp_list = $list->get_flat_list();
$_course = $course_info;
$main_question_list = array();
foreach ($lp_list as $lp_id => $lp) {
$exercise_list = ExerciseLib::get_all_exercises_from_lp($lp_id, $course_info['real_id']);
foreach ($exercise_list as $exercise) {
$my_exercise = new Exercise();
$my_exercise->read($exercise['path']);
$question_list = $my_exercise->selectQuestionList();
$exercise_stats = get_all_exercise_event_from_lp($exercise['path'], $course_info['real_id'], $session_id);
foreach ($question_list as $question_id) {
$question_data = Question::read($question_id);
$main_question_list[$question_id] = $question_data;
$quantity_exercises = 0;
$question_result = 0;
foreach ($exercise_stats as $stats) {
if (!empty($stats['question_list'])) {
foreach ($stats['question_list'] as $my_question_stat) {
if ($question_id == $my_question_stat['question_id']) {
$question_result = $question_result + $my_question_stat['marks'];
$quantity_exercises++;
}
}
}
}
if (!empty($quantity_exercises)) {
$main_question_list[$question_id]->results = $question_result / $quantity_exercises;
示例8: get_max_score
/**
* Calculate the max_score of the quiz, depending of question inside, and quiz advanced option
*/
public function get_max_score()
{
$out_max_score = 0;
$tab_question_list = $this->selectQuestionList(true);
// list of question's id !!! the array key start at 1 !!!
// test is randomQuestions - see field random of test
if ($this->random > 0 && $this->randomByCat == 0) {
$nb_random_questions = $this->random;
$tab_questions_score = array();
for ($i = 1; $i <= count($tab_question_list); $i++) {
$tmpobj_question = Question::read($tab_question_list[$i]);
$tab_questions_score[] = $tmpobj_question->weighting;
}
rsort($tab_questions_score);
// add the first $nb_random_questions value of score array to get max_score
for ($i = 0; $i < min($nb_random_questions, count($tab_questions_score)); $i++) {
$out_max_score += $tab_questions_score[$i];
}
} else {
if ($this->random > 0 && $this->randomByCat > 0) {
$nb_random_questions = $this->random;
$tab_categories_scores = array();
for ($i = 1; $i <= count($tab_question_list); $i++) {
$question_category_id = TestCategory::getCategoryForQuestion($tab_question_list[$i]);
if (!is_array($tab_categories_scores[$question_category_id])) {
$tab_categories_scores[$question_category_id] = array();
}
$tmpobj_question = Question::read($tab_question_list[$i]);
$tab_categories_scores[$question_category_id][] = $tmpobj_question->weighting;
}
// here we've got an array with first key, the category_id, second key, score of question for this cat
while (list($key, $tab_scores) = each($tab_categories_scores)) {
rsort($tab_scores);
for ($i = 0; $i < min($nb_random_questions, count($tab_scores)); $i++) {
$out_max_score += $tab_scores[$i];
}
}
} else {
for ($i = 1; $i <= count($tab_question_list); $i++) {
$tmpobj_question = Question::read($tab_question_list[$i]);
$out_max_score += $tmpobj_question->weighting;
}
}
}
return $out_max_score;
}
示例9: Question
// probaloume th dikia mas forma me to diko mas action
// kai me to katallhlo hidden pedio
echo "<form method='GET' action='backFromExercise.php'><input type='hidden' name='course' value='$course_code'>" .
"<input type='hidden' name='op' value='finish'>";
$i = $totalScore = $totalWeighting = 0;
// for each question
foreach ($_SESSION['questionList'][$exerciseId] as $questionId) {
// gets the student choice for this question
$choice = @$_SESSION['exerciseResult'][$exerciseId][$questionId];
// creates a temporary Question object
$objQuestionTmp = new Question();
$objQuestionTmp->read($questionId);
$questionName = $objQuestionTmp->selectTitle();
$questionDescription = $objQuestionTmp->selectDescription();
$questionDescription_temp = nl2br(make_clickable($questionDescription));
$questionDescription_temp = mathfilter($questionDescription_temp, 12, "$webDir/courses/mathimg/");
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
// destruction of the Question object
unset($objQuestionTmp);
if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == TRUE_FALSE) {
$colspan = 4;
} elseif ($answerType == MATCHING) {
$colspan = 2;
示例10: header
} else {
$my_cid = null;
}
if (!empty($_POST['action'])) {
$action = $_POST['action'];
} else {
$action = '';
}
if (empty($my_qst) or empty($my_usr) or empty($my_cid) or empty($my_exe)) {
header('Location: exercice.php');
exit;
}
if (!$is_courseTutor) {
api_not_allowed();
}
$obj_question = Question::read($my_qst);
if (isset($_SESSION['gradebook'])) {
$gradebook = $_SESSION['gradebook'];
}
if (!empty($gradebook) && $gradebook == 'view') {
$interbreadcrumb[] = array('url' => '../gradebook/' . $_SESSION['gradebook_dest'], 'name' => get_lang('ToolGradebook'));
}
$nameTools = get_lang('Exercice');
$interbreadcrumb[] = array("url" => "exercice.php", "name" => get_lang('Exercices'));
$my_msg = 'No change.';
if ($action == 'mark') {
if (!empty($_POST['score']) and $_POST['score'] < $obj_question->selectWeighting() and $_POST['score'] >= 0) {
//mark the user mark into the database using something similar to the following function:
$exercise_table = Database::get_statistic_table('track_e_exercices');
#global $origin, $tbl_learnpath_user, $learnpath_id, $learnpath_item_id;
$sql = "SELECT * FROM {$exercise_table}\n\t\t\t WHERE exe_user_id = " . intval($my_usr) . " AND exe_cours_id = '" . Database::escape_string($my_cid) . "' AND exe_exo_id = " . intval($my_exe) . "\n\t\t\t ORDER BY exe_date DESC";
示例11: isset
if (in_array($_GET['message'], array('ExerciseStored', 'ItemUpdated', 'ItemAdded'))) {
Display::display_confirmation_message(get_lang($_GET['message']));
}
}
if ($newQuestion || $editQuestion) {
// Question management
$type = isset($_REQUEST['answerType']) ? Security::remove_XSS($_REQUEST['answerType']) : null;
echo '<input type="hidden" name="Type" value="' . $type . '" />';
if ($newQuestion == 'yes') {
$objExercise->edit_exercise_in_lp = true;
}
require 'question_admin.inc.php';
}
if (isset($_GET['hotspotadmin'])) {
if (!is_object($objQuestion)) {
$objQuestion = Question::read($_GET['hotspotadmin']);
}
if (!$objQuestion) {
api_not_allowed();
}
require 'hotspot_admin.inc.php';
}
if (!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspotadmin'])) {
// question list management
require 'question_list_admin.inc.php';
}
// if we are in question authoring, display warning to user is feedback not shown at the end of the test -ref #6619
// this test to display only message in the question authoring page and not in the question list page too
// if (is_object($objQuestion) && $objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_EXAM && ($newQuestion || $modifyQuestion || $editQuestion)) {
if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_EXAM) {
Display::display_normal_message(get_lang("TestFeedbackNotShown"));
示例12: update_answer_records
/**
* Update user answers
*/
private function update_answer_records($key, $value)
{
// construction of the Question object
$objQuestionTmp = new Question();
// reads question informations
$objQuestionTmp->read($key);
$question_type = $objQuestionTmp->selectType();
$id = $this->id;
$eurid = $_SESSION['exerciseUserRecordID'][$id];
if ($question_type == FREE_TEXT) {
if (!empty($value)) {
Database::get()->query("UPDATE exercise_answer_record SET answer = ?s, answer_id = 1, weight = NULL,\n is_answered = 1 WHERE eurid = ?d AND question_id = ?d", $value, $eurid, $key);
} else {
Database::get()->query("UPDATE exercise_answer_record SET answer = ?s, \n answer_id = 0, weight = 0, is_answered = 1 WHERE eurid = ?d AND question_id = ?d", $value, $eurid, $key);
}
} elseif ($question_type == FILL_IN_BLANKS) {
$objAnswersTmp = new Answer($key);
$answer_field = $objAnswersTmp->selectAnswer(1);
//splits answer string from weighting string
list($answer, $answerWeighting) = explode('::', $answer_field);
// splits weightings that are joined with a comma
$rightAnswerWeighting = explode(',', $answerWeighting);
//getting all matched strings between [ and ] delimeters
preg_match_all('#\\[(.*?)\\]#', $answer, $match);
foreach ($value as $row_key => $row_choice) {
//if user's choice is right assign rightAnswerWeight else 0
$weight = $row_choice == $match[1][$row_key - 1] ? $rightAnswerWeighting[$row_key - 1] : 0;
Database::get()->query("UPDATE exercise_answer_record SET answer = ?s, weight = ?f, is_answered = 1 \n WHERE eurid = ?d AND question_id = ?d AND answer_id = ?d", $row_choice, $weight, $eurid, $key, $row_key);
}
} elseif ($question_type == MULTIPLE_ANSWER) {
if ($value == 0) {
$row_key = 0;
$answer_weight = 0;
Database::get()->query("UPDATE exercise_answer_record SET is_answered= 1 WHERE eurid = ?d AND question_id = ?d", $eurid, $key);
} else {
$objAnswersTmp = new Answer($key);
$i = 1;
// the first time in the loop we should update in order to keep question position in the DB
// and then insert a new record if there are more than one answers
foreach ($value as $row_key => $row_choice) {
$answer_weight = $objAnswersTmp->selectWeighting($row_key);
if ($i == 1) {
Database::get()->query("UPDATE exercise_answer_record SET answer_id = ?d, weight = ?f , is_answered = 1 WHERE eurid = ?d AND question_id = ?d", $row_key, $answer_weight, $eurid, $key);
} else {
Database::get()->query("INSERT INTO exercise_answer_record (eurid, question_id, answer_id, weight, is_answered)\n VALUES (?d, ?d, ?d, ?f, 1)", $eurid, $key, $row_key, $answer_weight);
}
unset($answer_weight);
$i++;
}
unset($objAnswersTmp);
}
} elseif ($question_type == MATCHING) {
$objAnswersTmp = new Answer($key);
foreach ($value as $row_key => $row_choice) {
// In matching questions isCorrect() returns position of left column answers while $row_key returns right column position
$correct_match = $objAnswersTmp->isCorrect($row_key);
if ($correct_match == $row_choice) {
$answer_weight = $objAnswersTmp->selectWeighting($row_key);
} else {
$answer_weight = 0;
}
Database::get()->query("UPDATE exercise_answer_record SET answer_id = ?d, weight = ?f , is_answered = 1\n WHERE eurid = ?d AND question_id = ?d AND answer = ?d", $row_choice, $answer_weight, $eurid, $key, $row_key);
unset($answer_weight);
}
} else {
if ($value != 0) {
$objAnswersTmp = new Answer($key);
$answer_weight = $objAnswersTmp->selectWeighting($value);
} else {
$answer_weight = 0;
}
Database::get()->query("UPDATE exercise_answer_record SET answer_id = ?d, weight = ?f , is_answered = 1\n WHERE eurid = ?d AND question_id = ?d", $value, $answer_weight, $eurid, $key);
}
unset($objQuestionTmp);
}
示例13: getAnsweredQuestionsFromAttempt
/**
* @param $exe_id
* @param $objExercise
* @return array
*/
public static function getAnsweredQuestionsFromAttempt($exe_id, $objExercise)
{
$attempt_list = self::getAllExerciseEventByExeId($exe_id);
$exercise_result = array();
if (!empty($attempt_list)) {
foreach ($attempt_list as $question_id => $options) {
foreach ($options as $item) {
$question_obj = Question::read($item['question_id']);
switch ($question_obj->type) {
case FILL_IN_BLANKS:
$item['answer'] = $objExercise->fill_in_blank_answer_to_string($item['answer']);
break;
case HOT_SPOT:
break;
}
if ($item['answer'] != '0' && !empty($item['answer'])) {
$exercise_result[] = $question_id;
break;
}
}
}
}
return $exercise_result;
}
示例14: build_quiz_questions
/**
* Build the Quiz-Questions
*/
public function build_quiz_questions($course_code = null)
{
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$table_qui = Database::get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
// Building normal tests.
$sql = "SELECT * FROM {$table_que} WHERE c_id = {$course_id} ";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$categories = Testcategory::getCategoryForQuestionWithCategoryData($obj->iid, $course_id, true);
$parent_info = array();
if (isset($obj->parent_id) && !empty($obj->parent_id)) {
$parent_info = (array) Question::read($obj->parent_id, $course_id);
}
$question = new QuizQuestion($obj->iid, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra, $parent_info, $categories);
$sql = 'SELECT * FROM ' . $table_ans . ' WHERE question_id = ' . $obj->iid;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer($obj2->iid, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) {
$table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$sql = 'SELECT * FROM ' . $table_options . ' WHERE c_id = ' . $course_id . ' AND question_id = ' . $obj->iid;
$db_result3 = Database::query($sql);
while ($obj3 = Database::fetch_object($db_result3)) {
$question_option = new QuizQuestionOption($obj3);
$question->add_option($question_option);
}
}
}
$this->course->add_resource($question);
}
// Building a fictional test for collecting orphan questions.
$build_orphan_questions = !empty($_POST['recycle_option']);
// When a course is emptied this option should be activated (true).
//1st union gets the orphan questions from deleted exercises
//2nd union gets the orphan questions from question that were deleted in a exercise.
$sql = " (\n SELECT q.* FROM {$table_que} q INNER JOIN {$table_rel} r\n ON (q.c_id = r.c_id AND q.iid = r.question_id)\n INNER JOIN {$table_qui} ex\n ON (ex.iid = r.exercice_id AND ex.c_id = r.c_id )\n WHERE ex.c_id = {$course_id} AND ex.active = '-1'\n )\n UNION\n (\n SELECT q.* FROM {$table_que} q left\n OUTER JOIN {$table_rel} r\n ON (q.c_id = r.c_id AND q.iid = r.question_id)\n WHERE q.c_id = {$course_id} AND r.question_id is null\n )\n UNION\n (\n SELECT q.* FROM {$table_que} q\n INNER JOIN {$table_rel} r\n ON (q.c_id = r.c_id AND q.iid = r.question_id)\n WHERE r.c_id = {$course_id} AND (r.exercice_id = '-1' OR r.exercice_id = '0')\n )\n ";
$db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0) {
$build_orphan_questions = true;
$orphanQuestionIds = array();
while ($obj = Database::fetch_object($db_result)) {
$categories = Testcategory::getCategoryForQuestionWithCategoryData($obj->iid, $course_id, true);
$parent_info = array();
if (isset($obj->parent_id) && !empty($obj->parent_id)) {
$parent_info = (array) Question::read($obj->parent_id, $course_id);
}
//Avoid adding the same question twice
if (!isset($this->course->resources[$obj->iid])) {
$question = new QuizQuestion($obj->iid, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra, $parent_info, $categories);
$sql = "SELECT * FROM {$table_ans} WHERE c_id = {$course_id} AND question_id = " . $obj->iid;
$db_result2 = Database::query($sql);
if (Database::num_rows($db_result2)) {
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer($obj2->iid, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
}
$orphanQuestionIds[] = $obj->iid;
}
$this->course->add_resource($question);
}
}
}
if ($build_orphan_questions) {
$obj = array('iid' => -1, 'title' => get_lang('OrphanQuestions', ''), 'type' => 2);
$newQuiz = new Quiz((object) $obj);
if (!empty($orphanQuestionIds)) {
foreach ($orphanQuestionIds as $index => $orphanId) {
$order = $index + 1;
$newQuiz->add_question($orphanId, $order);
}
}
$this->course->add_resource($newQuiz);
}
}
示例15: unset
/* For licensing terms, see /license.txt */
/**
* Code library for HotPotatoes integration.
* @package chamilo.exercise
*/
/**
* QUESTION LIST ADMINISTRATION
*
* This script allows to manage the question list
* It is included from the script admin.php
*
*/
// deletes a question from the exercise (not from the data base)
if ($deleteQuestion) {
// If the question exists
if ($objQuestionTmp = Question::read($deleteQuestion)) {
$objQuestionTmp->delete($exerciseId);
// if the question has been removed from the exercise
if ($objExercise->removeFromList($deleteQuestion)) {
$nbrQuestions--;
}
}
// destruction of the Question object
unset($objQuestionTmp);
}
$token = Security::get_token();
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH) . 'model.ajax.php?a=get_question_list&exerciseId=' . $exerciseId;
//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('Questions'), get_lang('Type'), get_lang('Category'), get_lang('Difficulty'), get_lang('Score'), get_lang('Actions'));
//$columns = array(get_lang('Questions'), get_lang('Type'), get_lang('Category'), get_lang('Score'));