/** * @param Application $app * @param int $exerciseId * @param int $questionId * @return Response */ public function reuseQuestionAction(Application $app, $exerciseId, $questionId) { /** @var \Question $question */ $question = \Question::read($questionId); if ($question) { // adds the exercise ID represented by $fromExercise into the list of exercises for the current question $question->addToList($exerciseId); $objExercise = new \Exercise(); $objExercise->read($exerciseId); // adds the question ID represented by $recup into the list of questions for the current exercise $objExercise->addToList($exerciseId); Session::write('objExercise', $objExercise); /*$params = array( 'cidReq' => api_get_course_id(), 'id_session' => api_get_session_id(), 'id' => $questionId, 'exerciseId' => $exerciseId ); $url = $app['url_generator']->generate('exercise_question_pool', $params); return $app->redirect($url);*/ $response = \Display::return_message(get_lang('QuestionReused') . ": " . $question->question); return new Response($response, 200, array()); } }
/** * function which process the creation of questions * @param FormValidator $form the formvalidator instance * @param Exercise $objExercise the Exercise instance */ public function processCreation($form, $objExercise = null) { $this->updateParentId($form->getSubmitValue('parent_id')); $this->updateTitle($form->getSubmitValue('questionName')); $this->updateDescription($form->getSubmitValue('questionDescription')); $this->updateLevel($form->getSubmitValue('questionLevel')); $this->updateCategory($form->getSubmitValue('questionCategory')); // Save normal question if NOT media if ($this->type != MEDIA_QUESTION) { $this->save($objExercise->id); $field_value = new ExtraFieldValue('question'); $params = $form->getSubmitValues(); $params['question_id'] = $this->id; $field_value->save_field_values($params); if ($objExercise) { // modify the exercise $objExercise->addToList($this->id); $objExercise->update_question_positions(); } } }
// gets an existing question and copies it into a new exercise $objQuestionTmp = Question::read($recup); // if the question exists if ($objQuestionTmp) { /* Adds the exercise ID represented by $fromExercise into the list of exercises for the current question */ $objQuestionTmp->addToList($fromExercise); } // destruction of the Question object unset($objQuestionTmp); if (!$objExercise instanceof Exercise) { $objExercise = new Exercise(); $objExercise->read($fromExercise); } // Adds the question ID represented by $recup into the list of questions for the current exercise $objExercise->addToList($recup); Session::write('objExercise', $objExercise); } else { if (isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) { $list_recup = $_POST['recup']; foreach ($list_recup as $course_id => $question_data) { $origin_course_id = intval($course_id); $origin_course_info = api_get_course_info_by_id($origin_course_id); $current_course = api_get_course_info(); foreach ($question_data as $old_question_id) { //Reading the source question $old_question_obj = Question::read($old_question_id, $origin_course_id); if ($old_question_obj) { $old_question_obj->updateTitle($old_question_obj->selectTitle() . ' - ' . get_lang('Copy')); //Duplicating the source question, in the current course $new_id = $old_question_obj->duplicate($current_course);
/** * function which process the creation of questions * @param FormValidator $form * @param Exercise $objExercise */ public function processCreation($form, $objExercise = null) { $this->updateTitle($form->getSubmitValue('questionName')); $this->updateDescription($form->getSubmitValue('questionDescription')); $this->updateLevel($form->getSubmitValue('questionLevel')); $this->updateCategory($form->getSubmitValue('questionCategory')); //Save normal question if NOT media if ($this->type != MEDIA_QUESTION) { $this->save($objExercise->id); // modify the exercise $objExercise->addToList($this->id); $objExercise->update_question_positions(); } }
Session::Messages($langQuestionNotFound); redirect_to_home_page("modules/exercise/admin.php?course={$course_code}&exerciseId={$exerciseId}"); } if (isset($_GET['editQuestion'])) { //clone and redirect to edit if (isset($_GET['clone'])) { //if user comes from an exercise page if (isset($exerciseId)) { // duplicates the question $new_question_id = $objQuestion->duplicate(); // deletes the old question from the specific exercise $objQuestion->delete($exerciseId); // removes the old question ID from the question list of the Exercise object $objExercise->removeFromList($question_id); // adds the new question ID into the question list of the Exercise object $objExercise->addToList($new_question_id); // construction of the duplicated Question $objQuestion = new Question(); $objQuestion->read($new_question_id); // adds the exercise ID into the exercise list of the Question object $objQuestion->addToList($exerciseId); // copies answers from the old qustion to the new $objAnswer = new Answer($question_id); $objAnswer->duplicate($new_question_id); redirect_to_home_page("modules/exercise/admin.php?course={$course_code}&exerciseId={$exerciseId}&editQuestion={$new_question_id}"); //if the user comes from question pool } else { $new_question_id = $objQuestion->duplicate(); $objAnswer = new Answer($question_id); $objAnswer->duplicate($new_question_id); redirect_to_home_page("modules/exercise/admin.php?course={$course_code}&editQuestion={$question_id}");
/** * Loads the data and injects it into the Chamilo database, using the Chamilo * internal functions. * @return array List of user IDs for the users that have just been inserted */ function fill_exe() { $qc = 5000; //how many questions to create per exercise $eol = PHP_EOL; $courses = array(); //declare only to avoid parsing notice $qst = array(); require_once 'data_exe.php'; //fill the $users array $output = array(); $output[] = array('title' => 'Exe Filling Report: '); $i = 1; $lib = api_get_path(SYS_CODE_PATH); require_once $lib . 'exercice/exercise.class.php'; require_once $lib . 'exercice/question.class.php'; require_once $lib . 'exercice/answer.class.php'; foreach ($courses as $i => $course) { //first check that the first item doesn't exist already $output[$i]['line-init'] = $course['title']; $res = CourseManager::create_course($course); $output[$i]['line-info'] = $res ? $res : get_lang('NotInserted'); $i++; if (is_array($res)) { //now insert an exercise foreach ($course['exes'] as $exe) { $objExercise = new Exercise($res['real_id']); $objExercise->id = 0; $objExercise->course_id = $res['real_id']; $objExercise->exercise = $exe['title']; $objExercise->type = 1; $objExercise->attempts = $exe['attempts']; $objExercise->random = $exe['random']; $objExercise->active = 1; $objExercise->propagate_neg = 0; $objExercise->pass_percentage = $exe['pass_percentage']; $objExercise->session_id = 0; $objExercise->results_disabled = 0; $objExercise->expired_time = $exe['time']; $objExercise->review_answers = $exe['review_answers']; $objExercise->save(); $id = $objExercise->id; if (!empty($id)) { $qi = 0; while ($qi < $qc) { foreach ($qst as $q) { error_log('Created ' . $qi . ' questions'); $question = Question::getInstance($q['type']); $question->id = 0; $question->question = $q['title'] . ' ' . $qi; $question->description = $q['desc']; $question->type = $q['type']; $question->course = $res; $r = $question->save($id); if ($r === false) { continue; } $qid = $question->id; $objExercise->addToList($qid); $objExercise->update_question_positions(); $aid = 1; foreach ($q['answers'] as $asw) { $answer = new UniqueAnswer($qid); $answer->create_answer($aid, $qid, $asw['title'], '', $asw['score'], $asw['correct'], $res['real_id']); $aid++; } $qi++; } } } } } } return $output; }