コード例 #1
0
ファイル: upgrade.php プロジェクト: veritech/pare-project
/**
 * @param $result the result object that can be modified.
 * @return null if the test is irrelevant, or true or false depending on whether the test passes.
 */
function question_random_check($result)
{
    global $CFG;
    if (!empty($CFG->running_installer) || $CFG->version >= 2007081000) {
        //no test after upgrade seperates question cats into contexts.
        return null;
    }
    if (!($toupdate = question_cwqpfs_to_update())) {
        $result->setStatus(true);
        //pass test
    } else {
        //set the feedback string here and not in xml file since we need something
        //more complex than just a string picked from admin.php lang file
        $a = new object();
        $a->reporturl = "{$CFG->wwwroot}/{$CFG->admin}/report/question/";
        $lang = str_replace('_utf8', '', current_language());
        $a->docsurl = "{$CFG->docroot}/{$lang}/admin/report/question/index";
        $result->setFeedbackStr(array('questioncwqpfscheck', 'admin', $a));
        $result->setStatus(false);
        //fail test
    }
    return $result;
}
コード例 #2
0
ファイル: upgrade.php プロジェクト: r007/PMoodle
function question_upgrade_context_etc()
{
    global $CFG;
    $result = true;
    $result = $result && question_delete_unused_random();
    $question_categories = get_records('question_categories');
    if ($question_categories) {
        //prepare content for new db structure
        $tofix = question_cwqpfs_to_update($question_categories);
        foreach ($tofix as $catid => $publish) {
            $question_categories[$catid]->publish = $publish;
        }
        foreach ($question_categories as $id => $question_category) {
            $course = $question_categories[$id]->course;
            unset($question_categories[$id]->course);
            if ($question_categories[$id]->publish) {
                $context = get_context_instance(CONTEXT_SYSTEM);
                //new name with old course name in brackets
                $coursename = get_field('course', 'shortname', 'id', $course);
                $question_categories[$id]->name .= " ({$coursename})";
            } else {
                $context = get_context_instance(CONTEXT_COURSE, $course);
            }
            $question_categories[$id]->contextid = $context->id;
            unset($question_categories[$id]->publish);
        }
        $question_categories = question_category_checking($question_categories);
    }
    /// Define index course (not unique) to be dropped form question_categories
    $table = new XMLDBTable('question_categories');
    $index = new XMLDBIndex('course');
    $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
    /// Launch drop index course
    $result = $result && drop_index($table, $index);
    /// Define field course to be dropped from question_categories
    $field = new XMLDBField('course');
    /// Launch drop field course
    $result = $result && drop_field($table, $field);
    /// Define field context to be added to question_categories
    $field = new XMLDBField('contextid');
    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'name');
    $field->comment = 'context that this category is shared in';
    /// Launch add field context
    $result = $result && add_field($table, $field);
    /// Define index context (not unique) to be added to question_categories
    $index = new XMLDBIndex('contextid');
    $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid'));
    $index->comment = 'links to context table';
    /// Launch add index context
    $result = $result && add_index($table, $index);
    $field = new XMLDBField('publish');
    /// Launch drop field publish
    $result = $result && drop_field($table, $field);
    /// update table contents with previously calculated new contents.
    if ($question_categories) {
        foreach ($question_categories as $question_category) {
            $question_category->name = addslashes($question_category->name);
            $question_category->info = addslashes($question_category->info);
            if (!($result = update_record('question_categories', $question_category))) {
                notify('Couldn\'t update question_categories "' . $question_category->name . '"!');
            }
        }
    }
    /// Define field timecreated to be added to question
    $table = new XMLDBTable('question');
    $field = new XMLDBField('timecreated');
    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'hidden');
    /// Launch add field timecreated
    $result = $result && add_field($table, $field);
    /// Define field timemodified to be added to question
    $table = new XMLDBTable('question');
    $field = new XMLDBField('timemodified');
    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timecreated');
    /// Launch add field timemodified
    $result = $result && add_field($table, $field);
    /// Define field createdby to be added to question
    $table = new XMLDBTable('question');
    $field = new XMLDBField('createdby');
    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'timemodified');
    /// Launch add field createdby
    $result = $result && add_field($table, $field);
    /// Define field modifiedby to be added to question
    $table = new XMLDBTable('question');
    $field = new XMLDBField('modifiedby');
    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'createdby');
    /// Launch add field modifiedby
    $result = $result && add_field($table, $field);
    /// Define key createdby (foreign) to be added to question
    $table = new XMLDBTable('question');
    $key = new XMLDBKey('createdby');
    $key->setAttributes(XMLDB_KEY_FOREIGN, array('createdby'), 'user', array('id'));
    /// Launch add key createdby
    $result = $result && add_key($table, $key);
    /// Define key modifiedby (foreign) to be added to question
    $table = new XMLDBTable('question');
    $key = new XMLDBKey('modifiedby');
    $key->setAttributes(XMLDB_KEY_FOREIGN, array('modifiedby'), 'user', array('id'));
    /// Launch add key modifiedby
    $result = $result && add_key($table, $key);
    return $result;
}
コード例 #3
0
ファイル: index.php プロジェクト: veritech/pare-project
<?php

// $Id$
require_once '../../../config.php';
require_once $CFG->dirroot . '/question/upgrade.php';
require_once $CFG->libdir . '/adminlib.php';
$adminroot = admin_get_root();
admin_externalpage_setup('reportquestion', $adminroot);
admin_externalpage_print_header($adminroot);
print_heading(page_doc_link(get_string('adminreport', 'question')));
$probstr = '';
$contextupgradeversion = 2007081000;
if ($CFG->version < $contextupgradeversion) {
    ///cwrqpfs issue
    $probstr = print_heading(get_string('cwrqpfs', 'question'), '', 3, 'main', true);
    if ($updates = question_cwqpfs_to_update()) {
        $probstr .= get_string('cwrqpfsinfo', 'question');
        $probstr .= '<ul>';
        $catlist = join(array_keys($updates), ',');
        //get info about cateogries and no of questions used outside category's course
        $categories = get_records_sql('SELECT qc.*, c.fullname as coursename FROM ' . $CFG->prefix . 'question_categories as qc, ' . $CFG->prefix . 'course as c WHERE qc.course = c.id AND qc.id IN (' . $catlist . ')');
        foreach ($updates as $id => $publish) {
            $categories[$id]->caturl = "{$CFG->wwwroot}/question/category.php?sesskey=" . sesskey() . "&amp;edit={$id}&amp;id=" . $categories[$id]->course;
            if ($categories[$id]->publish) {
                $categories[$id]->changefrom = get_string('published', 'question');
                $categories[$id]->changeto = get_string('unpublished', 'question');
            } else {
                $categories[$id]->changefrom = get_string('unpublished', 'question');
                $categories[$id]->changeto = get_string('published', 'question');
            }
            $probstr .= '<li>' . get_string('changepublishstatuscat', 'question', $categories[$id]);