コード例 #1
0
 /**
  * Reads question information from the database
  *
  * @author Olivier Brouckaert
  * @param int $id - question ID
  * @param int $course_id
  * @param Exercise
  *
  * @return boolean - true if question exists, otherwise false
  */
 public static function read($id, $course_id = null, Exercise $exercise = null)
 {
     $id = intval($id);
     if (!empty($course_id)) {
         $course_info = api_get_course_info_by_id($course_id);
     } else {
         $course_info = api_get_course_info();
     }
     $course_id = $course_info['real_id'];
     if (empty($course_id) || $course_id == -1) {
         //return false;
     }
     $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
     $sql = "SELECT * FROM {$TBL_QUESTIONS} WHERE iid = {$id}";
     $result = Database::query($sql);
     // if the question has been found
     if ($object = Database::fetch_object($result)) {
         $objQuestion = Question::getInstance($object->type);
         if (!empty($objQuestion)) {
             $objQuestion->id = $id;
             $objQuestion->question = $object->question;
             $objQuestion->description = $object->description;
             $objQuestion->weighting = $object->ponderation;
             $objQuestion->position = $object->position;
             $objQuestion->type = $object->type;
             $objQuestion->picture = $object->picture;
             $objQuestion->level = (int) $object->level;
             $objQuestion->extra = $object->extra;
             $objQuestion->course = $course_info;
             $objQuestion->parent_id = $object->parent_id;
             $objQuestion->category_list = Testcategory::getCategoryForQuestion($id);
             $objQuestion->exercise = $exercise;
             $objQuestion->c_id = $object->c_id;
             $sql = "SELECT exercice_id FROM {$TBL_EXERCICE_QUESTION} WHERE question_id = {$id}";
             $result_exercise_list = Database::query($sql);
             // fills the array with the exercises which this question is in
             if ($result_exercise_list) {
                 while ($obj = Database::fetch_object($result_exercise_list)) {
                     $objQuestion->exerciseList[] = $obj->exercice_id;
                 }
             }
             return $objQuestion;
         }
     }
     // question not found
     return false;
 }
コード例 #2
0
 /**
  * Reads question information from the data base
  *
  * @param int $id - question ID
  * @param int $course_id
  *
  * @return Question
  *
  * @author Olivier Brouckaert
  */
 public static function read($id, $course_id = null)
 {
     $id = intval($id);
     if (!empty($course_id)) {
         $course_info = api_get_course_info_by_id($course_id);
     } else {
         $course_info = api_get_course_info();
     }
     $course_id = $course_info['real_id'];
     if (empty($course_id) || $course_id == -1) {
         return false;
     }
     $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
     $sql = "SELECT question, description, ponderation, position, type, picture, level, extra\n                FROM {$TBL_QUESTIONS}\n                WHERE c_id = {$course_id} AND id = {$id} ";
     $result = Database::query($sql);
     // if the question has been found
     if ($object = Database::fetch_object($result)) {
         $objQuestion = Question::getInstance($object->type);
         if (!empty($objQuestion)) {
             $objQuestion->id = $id;
             $objQuestion->question = $object->question;
             $objQuestion->description = $object->description;
             $objQuestion->weighting = $object->ponderation;
             $objQuestion->position = $object->position;
             $objQuestion->type = $object->type;
             $objQuestion->picture = $object->picture;
             $objQuestion->level = (int) $object->level;
             $objQuestion->extra = $object->extra;
             $objQuestion->course = $course_info;
             $objQuestion->category = TestCategory::getCategoryForQuestion($id);
             $tblQuiz = Database::get_course_table(TABLE_QUIZ_TEST);
             $sql = "SELECT DISTINCT q.exercice_id\n                        FROM {$TBL_EXERCISE_QUESTION} q\n                        INNER JOIN {$tblQuiz} e\n                        ON e.c_id = q.c_id AND e.id = q.exercice_id\n                        WHERE\n                            q.c_id = {$course_id} AND\n                            q.question_id = {$id} AND\n                            e.active >= 0";
             $result = Database::query($sql);
             // fills the array with the exercises which this question is in
             if ($result) {
                 while ($obj = Database::fetch_object($result)) {
                     $objQuestion->exerciseList[] = $obj->exercice_id;
                 }
             }
             return $objQuestion;
         }
     }
     // question not found
     return false;
 }
コード例 #3
0
 function search_engine_delete()
 {
     // remove from search engine if enabled
     if (api_get_setting('search.search_enabled') == 'true' && extension_loaded('xapian')) {
         $course_id = api_get_course_id();
         $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
         $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level IS NULL LIMIT 1';
         $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
         $res = Database::query($sql);
         if (Database::num_rows($res) > 0) {
             $row = Database::fetch_array($res);
             require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php';
             $di = new ChamiloIndexer();
             $di->remove_document((int) $row['search_did']);
             unset($di);
             $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
             foreach ($this->questionList as $question_i) {
                 $sql = 'SELECT type FROM %s WHERE id=%s';
                 $sql = sprintf($sql, $tbl_quiz_question, $question_i);
                 $qres = Database::query($sql);
                 if (Database::num_rows($qres) > 0) {
                     $qrow = Database::fetch_array($qres);
                     $objQuestion = Question::getInstance($qrow['type']);
                     $objQuestion = Question::read((int) $question_i);
                     $objQuestion->search_engine_edit($this->id, FALSE, TRUE);
                     unset($objQuestion);
                 }
             }
         }
         $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level IS NULL LIMIT 1';
         $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
         Database::query($sql);
         // remove terms from db
         require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
         delete_all_values_for_item($course_id, TOOL_QUIZ, $this->id);
     }
 }
コード例 #4
0
 function search_engine_delete()
 {
     // remove from search engine if enabled
     if (api_get_setting('search.search_enabled') == 'true' && extension_loaded('xapian')) {
         $em = Database::getManager();
         $course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
         $res = $em->createQuery('
                 SELECT ser FROM ChamiloCoreBundle:SearchEngineRef ser
                 WHERE ser.course = ?1 AND ser.toolId = ?2 AND ser.refIdHighLevel = ?3 AND ser.refIdSecondLevel IS NULL
             ')->setMaxResults(1)->execute([1 => $course, 2 => TOOL_QUIZ, 3 => $this->id]);
         if (count($res) > 0) {
             $row = current($res);
             require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php';
             $di = new ChamiloIndexer();
             $di->remove_document($row->getSearchDid());
             unset($di);
             $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
             foreach ($this->questionList as $question_i) {
                 $sql = 'SELECT type FROM %s WHERE id=%s';
                 $sql = sprintf($sql, $tbl_quiz_question, $question_i);
                 $qres = Database::query($sql);
                 if (Database::num_rows($qres) > 0) {
                     $qrow = Database::fetch_array($qres);
                     $objQuestion = Question::getInstance($qrow['type']);
                     $objQuestion = Question::read((int) $question_i);
                     $objQuestion->search_engine_edit($this->id, FALSE, TRUE);
                     unset($objQuestion);
                 }
             }
         }
         $em->createQuery('
                 DELETE FROM ChamiloCoreBundle:SearchEngineRef ser
                 WHERE ser.course = ?1 AND ser.toolId = ?2 AND
                     ser.refIdHighLevel = ?3 AND ser.refIdSecondLevel IS NULL
             ')->setMaxResults(1)->execute([1 => $course, 2 => TOOL_QUIZ, 3 => $this->id]);
         // remove terms from db
         require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
         delete_all_values_for_item($course->getCode(), TOOL_QUIZ, $this->id);
     }
 }
コード例 #5
0
<?php

/* For licensing terms, see /license.txt */
/**
 *	Statement (?) administration
 *	This script allows to manage the statements of questions.
 * 	It is included from the script admin.php
 *	@package chamilo.exercise
 * 	@author Olivier Brouckaert
 * 	@version $Id: question_admin.inc.php 22126 2009-07-15 22:38:39Z juliomontoya $
 */
if (isset($_GET['editQuestion'])) {
    $objQuestion = Question::read($_GET['editQuestion']);
    $action = api_get_self() . "?" . api_get_cidreq() . "&myid=1&modifyQuestion=" . $modifyQuestion . "&editQuestion=" . $objQuestion->id;
} else {
    $objQuestion = Question::getInstance($_REQUEST['answerType']);
    $action = api_get_self() . "?" . api_get_cidreq() . "&modifyQuestion=" . $modifyQuestion . "&newQuestion=" . $newQuestion;
}
if (is_object($objQuestion)) {
    // FORM CREATION
    $form = new FormValidator('question_admin_form', 'post', $action);
    if (isset($_GET['editQuestion'])) {
        $class = "btn btn-default";
        $text = get_lang('ModifyQuestion');
        $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null;
    } else {
        $class = "btn btn-default";
        $text = get_lang('AddQuestionToExercise');
        $type = $_REQUEST['answerType'];
    }
    $typesInformation = Question::get_question_type_list();
コード例 #6
0
ファイル: media.php プロジェクト: ragebat/chamilo-lms
// including the global library
//require_once '../inc/global.inc.php';
// Access control
api_protect_course_script(true);
$course_id = api_get_course_int_id();
//Add the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();
$interbreadcrumb[] = array("url" => "exercice.php", "name" => get_lang('Exercices'));
Display::display_header(get_lang('Media'));
$action = isset($_GET['action']) ? $_GET['action'] : null;
$page_url = "media.php?" . api_get_cidreq();
$token = Security::get_token();
switch ($action) {
    case 'add':
        $url = $page_url . '&action=' . Security::remove_XSS($_GET['action']);
        $objQuestion = Question::getInstance(MEDIA_QUESTION);
        $form = new FormValidator('question_admin_form', 'post', $url);
        // question form elements
        $objQuestion->createForm($form);
        $objQuestion->createAnswersForm($form);
        if ($form->validate()) {
            // question
            $objQuestion->processCreation($form, null);
            // answers
            $objQuestion->processAnswersCreation($form);
        } else {
            $form->display();
        }
        break;
    case 'edit':
        $url = $page_url . '&action=' . Security::remove_XSS($_GET['action']) . '&id=' . intval($_GET['id']);
コード例 #7
0
 * It is included from the script admin.php
 * @package chamilo.exercise
 * @author Olivier Brouckaert
 * @author Julio Montoya
 */
/**
 * Code
 */
$course_id = api_get_course_int_id();
$urlMainExercise = api_get_path(WEB_CODE_PATH) . 'exercice/';
// INIT QUESTION
if (isset($_GET['editQuestion'])) {
    $objQuestion = Question::read($_GET['editQuestion'], null, $objExercise);
    $action = api_get_self() . "?" . api_get_cidreq() . "&myid=1&modifyQuestion=" . $modifyQuestion . "&editQuestion=" . $objQuestion->id . "&exerciseId={$objExercise->id}";
} else {
    $objQuestion = Question::getInstance($_REQUEST['answerType'], $objExercise);
    $action = api_get_self() . "?" . api_get_cidreq() . "&modifyQuestion=" . $modifyQuestion . "&newQuestion=" . $newQuestion . "&exerciseId={$objExercise->id}";
}
/** @var Question $objQuestion */
if (is_object($objQuestion)) {
    //Form creation
    $form = new FormValidator('question_admin_form', 'post', $action);
    if (isset($_GET['editQuestion'])) {
        $objQuestion->submitClass = "btn save";
        $objQuestion->submitText = get_lang('ModifyQuestion');
    } else {
        $objQuestion->submitClass = "btn add";
        $objQuestion->submitText = get_lang('AddQuestionToExercise');
    }
    /*if (!isset($_GET['fromExercise'])) {
          $objQuestion->setDefaultQuestionValues = true;
コード例 #8
0
/**
 * 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;
}