<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AQuestiontype_class</id>
	<title>Development:Questiontype class - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AQuestiontype_class"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Questiontype_class&amp;action=history"/>
	<updated>2026-05-07T07:06:09Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Questiontype_class&amp;diff=11638&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Questiontype_class&amp;diff=11638&amp;oldid=prev"/>
		<updated>2024-10-21T08:53:00Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:53, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Questiontype_class&amp;diff=11637&amp;oldid=prev</id>
		<title>1&gt;TimHunt в 01:43, 9 сентября 2008</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Questiontype_class&amp;diff=11637&amp;oldid=prev"/>
		<updated>2008-09-09T01:43:52Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Convert question bank}}&lt;br /&gt;
{{Questiontype class}}&lt;br /&gt;
==The actual (before moving to activity module) question type class.==&lt;br /&gt;
The definitions will be put here and the code in the various supplementary page see menu &amp;#039;&amp;#039;&amp;#039;Questiontype class&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
first draw [[User:Pierre Pichet|Pierre Pichet]] 10:53, 17 March 2007 (CDT)&lt;br /&gt;
&lt;br /&gt;
The proposed modifications could be indicated here so they could be discussed before CVS...&lt;br /&gt;
/**&lt;br /&gt;
* The default questiontype class.&lt;br /&gt;
*&lt;br /&gt;
* @version $Id: questiontype.php,v 1.45 2007/03/06 18:00:26 tjhunt Exp $&lt;br /&gt;
* @author Martin Dougiamas and many others. This has recently been completely&lt;br /&gt;
*         rewritten by Alex Smith, Julian Sedding and Gustav Delius as part of&lt;br /&gt;
*         the Serving Mathematics project&lt;br /&gt;
*         {@link http://maths.york.ac.uk/serving_maths}&lt;br /&gt;
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License&lt;br /&gt;
* @package quiz&lt;br /&gt;
*//** */&lt;br /&gt;
&lt;br /&gt;
require_once($CFG-&amp;gt;libdir . &amp;#039;/questionlib.php&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
==class default_questiontype {==&lt;br /&gt;
/**&lt;br /&gt;
 * This is the base class for Moodle question types.&lt;br /&gt;
 *&lt;br /&gt;
 * There are detailed comments on each method, explaining what the method is&lt;br /&gt;
 * for, and the circumstances under which you might need to override it.&lt;br /&gt;
 *&lt;br /&gt;
 * Note: the questiontype API should NOT be considered stable yet. Very few&lt;br /&gt;
 * question tyeps have been produced yet, so we do not yet know all the places&lt;br /&gt;
 * where the current API is insufficient. I would rather learn from the&lt;br /&gt;
 * experiences of the first few question type implementors, and improve the&lt;br /&gt;
 * interface to meet their needs, rather the freeze the API prematurely and&lt;br /&gt;
 * condem everyone to working round a clunky interface for ever afterwards.&lt;br /&gt;
 */&lt;br /&gt;
  class default_questiontype {&lt;br /&gt;
==function name()==&lt;br /&gt;
    /**&lt;br /&gt;
     * Name of the question type&lt;br /&gt;
     *&lt;br /&gt;
     * The name returned should coincide with the name of the directory&lt;br /&gt;
     * in which this questiontype is located&lt;br /&gt;
     *&lt;br /&gt;
     * @return string the name of this question type.&lt;br /&gt;
     */&lt;br /&gt;
    function name() {&lt;br /&gt;
        return &amp;#039;default&amp;#039;;&lt;br /&gt;
    }&lt;br /&gt;
==function menu_name==&lt;br /&gt;
    /**&lt;br /&gt;
     * The name this question should appear as in the create new question&lt;br /&gt;
     * dropdown.&lt;br /&gt;
     *&lt;br /&gt;
     * @return mixed the desired string, or false to hide this question type in the menu.&lt;br /&gt;
     */&lt;br /&gt;
    function menu_name() {&lt;br /&gt;
        $name = $this-&amp;gt;name();&lt;br /&gt;
        ...&lt;br /&gt;
        return $menu_name;&lt;br /&gt;
    }&lt;br /&gt;
==function is_manual_graded()==&lt;br /&gt;
    /**&lt;br /&gt;
     * @return boolean true if this question can only be graded manually.&lt;br /&gt;
     */&lt;br /&gt;
    function is_manual_graded() {&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
==function is_usable_by_random()==&lt;br /&gt;
    /**&lt;br /&gt;
     * @return boolean true if this question type can be used by the random question type.&lt;br /&gt;
     */&lt;br /&gt;
    function is_usable_by_random() {&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
==function create_editing_form($submiturl, $question)==&lt;br /&gt;
    /**&lt;br /&gt;
     * Return an instance of the question editing form definition. This looks for a&lt;br /&gt;
     * class called edit_{$this-&amp;gt;name()}_question_form in the file&lt;br /&gt;
     * {$CFG-&amp;gt;docroot}/question/type/{$this-&amp;gt;name()}/edit_{$this-&amp;gt;name()}_question_form.php&lt;br /&gt;
     * and if it exists returns an instance of it.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $submiturl passed on to the constructor call.&lt;br /&gt;
     * @return object an instance of the form definition, or null if one could not be found.&lt;br /&gt;
     */&lt;br /&gt;
    function create_editing_form($submiturl, $question) {&lt;br /&gt;
        global $CFG;&lt;br /&gt;
        require_once(&amp;quot;{$CFG-&amp;gt;dirroot}/question/type/edit_question_form.php&amp;quot;);&lt;br /&gt;
        .....&lt;br /&gt;
        return new $classname($submiturl, $question);&lt;br /&gt;
    }&lt;br /&gt;
==function display_question_editing_page(&amp;amp;$mform, $question, $wizardnow)==&lt;br /&gt;
    /**&lt;br /&gt;
     * This method should be overriden if you want to include a special heading or some other&lt;br /&gt;
     * html on a question editing page besides the question editing form.&lt;br /&gt;
     *&lt;br /&gt;
     * @param question_edit_form $mform a child of question_edit_form&lt;br /&gt;
     * @param object $question&lt;br /&gt;
     * @param string $wizardnow is &amp;#039;&amp;#039; for first page.&lt;br /&gt;
     */&lt;br /&gt;
    function display_question_editing_page(&amp;amp;$mform, $question, $wizardnow){&lt;br /&gt;
&lt;br /&gt;
        print_heading_with_help(get_string(&amp;quot;editing&amp;quot;.$question-&amp;gt;qtype, &amp;quot;quiz&amp;quot;), $question-&amp;gt;qtype, &amp;quot;quiz&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        $mform-&amp;gt;display();&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
==function save_question($question, $form, $course)==&lt;br /&gt;
    /**&lt;br /&gt;
    * Saves or updates a question after editing by a teacher&lt;br /&gt;
    *&lt;br /&gt;
    * Given some question info and some data about the answers&lt;br /&gt;
    * this function parses, organises and saves the question&lt;br /&gt;
    * It is used by {@link question.php} when saving new data from&lt;br /&gt;
    * a form, and also by {@link import.php} when importing questions&lt;br /&gt;
    * This function in turn calls {@link save_question_options}&lt;br /&gt;
    * to save question-type specific options&lt;br /&gt;
    * @param object $question the question object which should be updated&lt;br /&gt;
    * @param object $form the form submitted by the teacher&lt;br /&gt;
    * @param object $course the course we are in&lt;br /&gt;
    * @return object On success, return the new question object. On failure,&lt;br /&gt;
    *       return an object as follows. If the error object has an errors field,&lt;br /&gt;
    *       display that as an error message. Otherwise, the editing form will be&lt;br /&gt;
    *       redisplayed with validation errors, from validation_errors field, which&lt;br /&gt;
    *       is itself an object, shown next to the form fields.&lt;br /&gt;
    */&lt;br /&gt;
    function save_question($question, $form, $course) {&lt;br /&gt;
        // This default implementation is suitable for most&lt;br /&gt;
        ....&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        return $question;&lt;br /&gt;
    }&lt;br /&gt;
==function save_question_options($question)==&lt;br /&gt;
    /**&lt;br /&gt;
    * Saves question-type specific options&lt;br /&gt;
    *&lt;br /&gt;
    * This is called by {@link save_question()} to save the question-type specific data&lt;br /&gt;
    * @return object $result-&amp;gt;error or $result-&amp;gt;noticeyesno or $result-&amp;gt;notice&lt;br /&gt;
    * @param object $question  This holds the information from the editing form,&lt;br /&gt;
    *                          it is not a standard question object.&lt;br /&gt;
    */&lt;br /&gt;
    function save_question_options($question) {&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
==function replace_question_in_attempts($oldquestionid, $newquestion, $attemtps)==&lt;br /&gt;
    /**&lt;br /&gt;
    * Changes all states for the given attempts over to a new question&lt;br /&gt;
    *&lt;br /&gt;
    * This is used by the versioning code if the teacher requests that a question&lt;br /&gt;
    * gets replaced by the new version. In order for the attempts to be regraded&lt;br /&gt;
    * properly all data in the states referring to the old question need to be&lt;br /&gt;
    * changed to refer to the new version instead. In particular for question types&lt;br /&gt;
    * that use the answers table the answers belonging to the old question have to&lt;br /&gt;
    * be changed to those belonging to the new version.&lt;br /&gt;
    *&lt;br /&gt;
    * @param integer $oldquestionid  The id of the old question&lt;br /&gt;
    * @param object $newquestion    The new question&lt;br /&gt;
    * @param array  $attempts       An array of all attempt objects in whose states&lt;br /&gt;
    *                               replacement should take place&lt;br /&gt;
    */&lt;br /&gt;
    function replace_question_in_attempts($oldquestionid, $newquestion, $attemtps) {&lt;br /&gt;
        echo &amp;#039;Not yet implemented&amp;#039;;&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
==function get_question_options(&amp;amp;$question)==&lt;br /&gt;
    /**&lt;br /&gt;
    * Loads the question type specific options for the question.&lt;br /&gt;
    *&lt;br /&gt;
    * This function loads any question type specific options for the&lt;br /&gt;
    * question from the database into the question object. This information&lt;br /&gt;
    * is placed in the $question-&amp;gt;options field. A question type is&lt;br /&gt;
    * free, however, to decide on a internal structure of the options field.&lt;br /&gt;
    * @return bool            Indicates success or failure.&lt;br /&gt;
    * @param object $question The question object for the question. This object&lt;br /&gt;
    *                         should be updated to include the question type&lt;br /&gt;
    *                         specific information (it is passed by reference).&lt;br /&gt;
    */&lt;br /&gt;
    function get_question_options(&amp;amp;$question) {&lt;br /&gt;
        if (!isset($question-&amp;gt;options)) {&lt;br /&gt;
            $question-&amp;gt;options = new object;&lt;br /&gt;
        }&lt;br /&gt;
        // The default implementation attaches all answers for this question&lt;br /&gt;
        $question-&amp;gt;options-&amp;gt;answers = get_records(&amp;#039;question_answers&amp;#039;, &amp;#039;question&amp;#039;, $question-&amp;gt;id, &amp;#039;id ASC&amp;#039;);&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
==function delete_states($stateslist)==&lt;br /&gt;
    /**&lt;br /&gt;
    * Deletes states from the question-type specific tables&lt;br /&gt;
    *&lt;br /&gt;
    * @param string $stateslist  Comma separated list of state ids to be deleted&lt;br /&gt;
    */&lt;br /&gt;
    function delete_states($stateslist) {&lt;br /&gt;
        /// The default question type does not have any tables of its own&lt;br /&gt;
        // therefore there is nothing to delete&lt;br /&gt;
&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
==function delete_question($questionid)==&lt;br /&gt;
    /**&lt;br /&gt;
    * Deletes a question from the question-type specific tables&lt;br /&gt;
    *&lt;br /&gt;
    * @return boolean Success/Failure&lt;br /&gt;
    * @param object $question  The question being deleted&lt;br /&gt;
    */&lt;br /&gt;
    function delete_question($questionid) {&lt;br /&gt;
        /// The default question type does not have any tables of its own&lt;br /&gt;
        // therefore there is nothing to delete&lt;br /&gt;
&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
==function actual_number_of_questions($question)==&lt;br /&gt;
    /**&lt;br /&gt;
    * Returns the number of question numbers which are used by the question&lt;br /&gt;
    *&lt;br /&gt;
    * This function returns the number of question numbers to be assigned&lt;br /&gt;
    * to the question. Most question types will have length one; they will be&lt;br /&gt;
    * assigned one number. The &amp;#039;description&amp;#039; type, however does not use up a&lt;br /&gt;
    * number and so has a length of zero. Other question types may wish to&lt;br /&gt;
    * handle a bundle of questions and hence return a number greater than one.&lt;br /&gt;
    * @return integer         The number of question numbers which should be&lt;br /&gt;
    *                         assigned to the question.&lt;br /&gt;
    * @param object $question The question whose length is to be determined.&lt;br /&gt;
    *                         Question type specific information is included.&lt;br /&gt;
    */&lt;br /&gt;
    function actual_number_of_questions($question) {&lt;br /&gt;
        // By default, each question is given one number&lt;br /&gt;
        return 1;&lt;br /&gt;
    }&lt;br /&gt;
==function create_session_and_responses(&amp;amp;$question, &amp;amp;$state, $cmoptions, $attempt)==&lt;br /&gt;
    /**&lt;br /&gt;
    * Creates empty session and response information for the question&lt;br /&gt;
    *&lt;br /&gt;
    * This function is called to start a question session. Empty question type&lt;br /&gt;
    * specific session data (if any) and empty response data will be added to the&lt;br /&gt;
    * state object. Session data is any data which must persist throughout the&lt;br /&gt;
    * attempt possibly with updates as the user interacts with the&lt;br /&gt;
    * question. This function does NOT create new entries in the database for&lt;br /&gt;
    * the session; a call to the {@link save_session_and_responses} member will&lt;br /&gt;
    * occur to do this.&lt;br /&gt;
    * @return bool            Indicates success or failure.&lt;br /&gt;
    * @param object $question The question for which the session is to be&lt;br /&gt;
    *                         created. Question type specific information is&lt;br /&gt;
    *                         included.&lt;br /&gt;
    * @param object $state    The state to create the session for. Note that&lt;br /&gt;
    *                         this will not have been saved in the database so&lt;br /&gt;
    *                         there will be no id. This object will be updated&lt;br /&gt;
    *                         to include the question type specific information&lt;br /&gt;
    *                         (it is passed by reference). In particular, empty&lt;br /&gt;
    *                         responses will be created in the -&amp;gt;responses&lt;br /&gt;
    *                         field.&lt;br /&gt;
    * @param object $cmoptions&lt;br /&gt;
    * @param object $attempt  The attempt for which the session is to be&lt;br /&gt;
    *                         started. Questions may wish to initialize the&lt;br /&gt;
    *                         session in different ways depending on the user id&lt;br /&gt;
    *                         or time available for the attempt.&lt;br /&gt;
    */&lt;br /&gt;
    function create_session_and_responses(&amp;amp;$question, &amp;amp;$state, $cmoptions, $attempt) {&lt;br /&gt;
        // The default implementation should work for the legacy question types.&lt;br /&gt;
        // Most question types with only a single form field for the student&amp;#039;s response&lt;br /&gt;
        // will use the empty string &amp;#039;&amp;#039; as the index for that one response. This will&lt;br /&gt;
        // automatically be stored in and restored from the answer field in the&lt;br /&gt;
        // question_states table.&lt;br /&gt;
        $state-&amp;gt;responses = array(&lt;br /&gt;
                &amp;#039;&amp;#039; =&amp;gt; &amp;#039;&amp;#039;,&lt;br /&gt;
        );&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
/// BACKUP FUNCTIONS ////////////////////////////&lt;br /&gt;
&lt;br /&gt;
    /*&lt;br /&gt;
     * Backup the data in the question&lt;br /&gt;
     *&lt;br /&gt;
     * This is used in question/backuplib.php&lt;br /&gt;
     */&lt;br /&gt;
    function backup($bf,$preferences,$question,$level=6) {&lt;br /&gt;
        // The default type has nothing to back up&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
/// RESTORE FUNCTIONS /////////////////&lt;br /&gt;
&lt;br /&gt;
    /*&lt;br /&gt;
     * Restores the data in the question&lt;br /&gt;
     *&lt;br /&gt;
     * This is used in question/restorelib.php&lt;br /&gt;
     */&lt;br /&gt;
    function restore($old_question_id,$new_question_id,$info,$restore) {&lt;br /&gt;
        // The default question type has nothing to restore&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    function restore_map($old_question_id,$new_question_id,$info,$restore) {&lt;br /&gt;
        // There is nothing to decode&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    function restore_recode_answer($state, $restore) {&lt;br /&gt;
        // There is nothing to decode&lt;br /&gt;
        return $state-&amp;gt;answer;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //This function restores the question_rqp_states&lt;br /&gt;
    function restore_state($state_id,$info,$restore) {&lt;br /&gt;
        // The default question type does not keep its own state information&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;/div&gt;</summary>
		<author><name>1&gt;TimHunt</name></author>
	</entry>
</feed>