本文整理汇总了PHP中Exercise::addQuestion方法的典型用法代码示例。如果您正苦于以下问题:PHP Exercise::addQuestion方法的具体用法?PHP Exercise::addQuestion怎么用?PHP Exercise::addQuestion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exercise
的用法示例。
在下文中一共展示了Exercise::addQuestion方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: substr
}
$categoryId = substr($filter, 0, 10) == 'categoryId' && is_numeric(substr($filter, 10)) ? substr($filter, 10) : null;
/*
* Init other vars
*/
$exercise = new Exercise();
if (!is_null($exId)) {
$exercise->load($exId);
}
$dialogBox = new DialogBox();
/*
* Execute commands
*/
// use question in exercise
if ($cmd == 'rqUse' && !is_null($quId) && !is_null($exId)) {
if ($exercise->addQuestion($quId)) {
// TODO show confirmation and back link
header('Location: ' . Url::Contextualize('edit_exercise.php?exId=' . $exId));
}
}
// delete question
if ($cmd == 'delQu' && !is_null($quId)) {
$question = new Question();
if ($question->load($quId)) {
if (!$question->delete()) {
// TODO show confirmation and list
}
}
}
// export question
if ($cmd == 'exExport' && get_conf('enableExerciseExportQTI')) {
示例2: import_exercise
//.........这里部分代码省略.........
$tbl_quiz_exercise = $tbl_cdb_names['qwz_exercise'];
$tbl_quiz_question = $tbl_cdb_names['qwz_question'];
// paths
$baseWorkDir = get_path('rootSys') . get_conf('tmpPathSys') . 'upload/';
// create temp dir for upload
if (!file_exists($baseWorkDir)) {
claro_mkdir($baseWorkDir, CLARO_FILE_PERMISSIONS);
}
$uploadDir = claro_mkdir_tmp($baseWorkDir);
// this function should return the dir name and not the full path ...
$uploadPath = str_replace($baseWorkDir, '', $uploadDir);
// set some default values for the new exercise
$exercise_info = array();
$exercise_info['name'] = preg_replace('/.zip$/i', '', $file);
$exercise_info['description'] = '';
$exercise_info['question'] = array();
// create parser and array to retrieve info from manifest
$element_pile = array();
//pile to known the depth in which we are
$module_info = array();
//array to store the info we need
// if file is not a .zip, then we cancel all
if (!preg_match('/.zip$/i', $_FILES['uploadedExercise']['name'])) {
$backlog->failure(get_lang('You must upload a zip file'));
return false;
}
//unzip the uploaded file in a tmp directory
if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) {
$backlog->failure(get_lang('Upload failed'));
return false;
}
// find the different manifests for each question and parse them.
$exerciseHandle = opendir($uploadDir);
$question_number = 0;
$file_found = false;
// parse every subdirectory to search xml question files
while (false !== ($file = readdir($exerciseHandle))) {
if (is_dir($uploadDir . '/' . $file) && $file != "." && $file != "..") {
//find each manifest for each question repository found
$questionHandle = opendir($uploadDir . '/' . $file);
while (false !== ($questionFile = readdir($questionHandle))) {
if (preg_match('/.xml$/i', $questionFile)) {
list($parsingBacklog, $success) = parse_file($uploadDir, $file, $questionFile);
$backlog->append($parsingBacklog);
$file_found = true;
}
}
} elseif (preg_match('/.xml$/i', $file)) {
list($parsingBacklog, $success) = parse_file($uploadDir, '', $file);
$backlog->append($parsingBacklog);
$file_found = true;
}
// else ignore file
}
if (!$file_found) {
$backlog->failure(get_lang('No XML file found in the zip'));
return false;
}
//---------------------
//add exercise in tool
//---------------------
//1.create exercise
$exercise = new Exercise();
$exercise->setTitle($exercise_info['name']);
$exercise->setDescription($exercise_info['description']);
if ($exercise->validate()) {
$exercise_id = $exercise->save();
} else {
$backlog->failure(get_lang('There is an error in exercise data of imported file.'));
return false;
}
ksort($exercise_info['question'], SORT_NUMERIC);
//For each question found...
foreach ($exercise_info['question'] as $key => $question_array) {
//2.create question
$question = new Qti2Question();
$question->import($question_array);
if ($question->validate()) {
// I need to save the question after the answer because I need question id in answers
$question_id = $question->save();
//3.create answers
$question->setAnswer();
$question->answer->import($question_array);
if ($question->answer->validate()) {
$question->setGrade($question->answer->getGrade());
$question->save();
// save computed grade
$question->answer->save();
$exercise->addQuestion($question_id);
} else {
$backlog->failure(get_lang('Invalid answer') . ' : ' . $key);
}
} else {
$backlog->failure(get_lang('Invalid question') . ' : ' . $key);
}
}
// delete the temp dir where the exercise was unzipped
claro_delete_file($uploadDir);
return $exercise_id;
}
示例3: header
* Execute commands
*/
if ($cmd == 'exEdit') {
// add or remove answer, change step,...
// should return true if form is really submitted
if ($question->answer->handleForm()) {
// form has to be saved, check input validity
if ($question->answer->validate()) {
if (count_exercise_using_question($quId) > 1 && !is_null($quId) && !is_null($exId) && isset($_REQUEST['duplicate']) && $_REQUEST['duplicate'] == 'true') {
// duplicate object if used in several exercises
$duplicated = $question->duplicate();
// make exercise use the new created question object instead of the new one
$exercise->removeQuestion($quId);
$quId = $duplicated->getId();
// and reset $quId
$exercise->addQuestion($quId);
$question = $duplicated;
}
if ($question->answer->save()) {
// update grade in question
$question->setGrade($question->answer->getGrade());
$question->save();
header("Location: " . Url::Contextualize("./edit_question.php?exId=" . $exId . "&quId=" . $quId));
exit;
}
}
}
if ($question->answer->getErrorList()) {
$dialogBox->error(implode('<br />' . "\n", $question->answer->getErrorList()));
}
// if we were not redirected it means form must be displayed
示例4: DialogBox
// quId and exId have been specified and load operations worked
if (!is_null($quId) && !is_null($exId)) {
// do not duplicate when there is no $exId,
// it means that we modify the question from pool
// do not duplicate when there is no $quId,
// it means that question is a new one
// check that question is used in several exercises
if (count_exercise_using_question($quId) > 1) {
if (isset($_REQUEST['duplicate']) && $_REQUEST['duplicate'] == 'true') {
// duplicate object if used in several exercises
$duplicated = $question->duplicate();
// make exercise use the new created question object instead of the new one
$exercise->removeQuestion($quId);
$quId = $duplicated->getId();
// and reset $quId
$exercise->addQuestion($quId);
$question = $duplicated;
} else {
$askDuplicate = true;
}
}
}
$dialogBox = new DialogBox();
$displayForm = false;
/*
* Execute commands
*/
if ($cmd == 'exEdit') {
// if quId is null it means that we create a new question
$question->setTitle($_REQUEST['title']);
$question->setDescription($_REQUEST['description']);