예제 #1
0
function xmldb_forum_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    /// And upgrade begins here. For each one, you'll need one
    /// block of code similar to the next one. Please, delete
    /// this comment lines once this file start handling proper
    /// upgrade code.
    /// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
    ///     $result = result of "/lib/ddllib.php" function calls
    /// }
    if ($result && $oldversion < 2007072200) {
        require_once $CFG->dirroot . '/mod/forum/lib.php';
        // too much debug output
        $db->debug = false;
        forum_update_grades();
        $db->debug = true;
    }
    if ($result && $oldversion < 2007101000) {
        /// Define field timemodified to be added to forum_queue
        $table = new XMLDBTable('forum_queue');
        $field = new XMLDBField('timemodified');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'postid');
        /// Launch add field timemodified
        $result = $result && add_field($table, $field);
    }
    return $result;
}
예제 #2
0
function xmldb_forum_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    /// And upgrade begins here. For each one, you'll need one
    /// block of code similar to the next one. Please, delete
    /// this comment lines once this file start handling proper
    /// upgrade code.
    /// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
    ///     $result = result of "/lib/ddllib.php" function calls
    /// }
    if ($result && $oldversion < 2007101000) {
        /// Define field timemodified to be added to forum_queue
        $table = new XMLDBTable('forum_queue');
        $field = new XMLDBField('timemodified');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'postid');
        /// Launch add field timemodified
        $result = $result && add_field($table, $field);
    }
    //===== 1.9.0 upgrade line ======//
    if ($result and $oldversion < 2007101511) {
        notify('Processing forum grades, this may take a while if there are many forums...', 'notifysuccess');
        //MDL-13866 - send forum ratins to gradebook again
        require_once $CFG->dirroot . '/mod/forum/lib.php';
        // too much debug output
        $db->debug = false;
        forum_update_grades();
        $db->debug = true;
    }
    if ($result && $oldversion < 2007101512) {
        /// Cleanup the forum subscriptions
        notify('Removing stale forum subscriptions', 'notifysuccess');
        $roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW);
        $roles = array_keys($roles);
        $roles = implode(',', $roles);
        $sql = "SELECT fs.userid, f.id AS forumid\n                  FROM {$CFG->prefix}forum f\n                       JOIN {$CFG->prefix}course c                 ON c.id = f.course\n                       JOIN {$CFG->prefix}context ctx              ON (ctx.instanceid = c.id AND ctx.contextlevel = " . CONTEXT_COURSE . ")\n                       JOIN {$CFG->prefix}forum_subscriptions fs   ON fs.forum = f.id\n                       LEFT JOIN {$CFG->prefix}role_assignments ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid IN ({$roles}))\n                 WHERE ra.id IS NULL";
        if ($rs = get_recordset_sql($sql)) {
            $db->debug = false;
            while ($remove = rs_fetch_next_record($rs)) {
                delete_records('forum_subscriptions', 'userid', $remove->userid, 'forum', $remove->forumid);
                echo '.';
            }
            $db->debug = true;
            rs_close($rs);
        }
    }
    if ($result && $oldversion < 2007101513) {
        delete_records('forum_ratings', 'post', 0);
        /// Clean existing wrong rates. MDL-18227
    }
    return $result;
}
예제 #3
0
function xmldb_forum_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    /// And upgrade begins here. For each one, you'll need one
    /// block of code similar to the next one. Please, delete
    /// this comment lines once this file start handling proper
    /// upgrade code.
    /// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
    ///     $result = result of "/lib/ddllib.php" function calls
    /// }
    if ($result && $oldversion < 2007072200) {
        require_once $CFG->dirroot . '/mod/forum/lib.php';
        // too much debug output
        $db->debug = false;
        forum_update_grades();
        $db->debug = true;
    }
    return $result;
}
예제 #4
0
파일: lib.php 프로젝트: Jtgadbois/Pedadida
/**
 * Update all grades in gradebook.
 * @global object
 */
function forum_upgrade_grades() {
    global $DB;

    $sql = "SELECT COUNT('x')
              FROM {forum} f, {course_modules} cm, {modules} m
             WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
    $count = $DB->count_records_sql($sql);

    $sql = "SELECT f.*, cm.idnumber AS cmidnumber, f.course AS courseid
              FROM {forum} f, {course_modules} cm, {modules} m
             WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
    $rs = $DB->get_recordset_sql($sql);
    if ($rs->valid()) {
        $pbar = new progress_bar('forumupgradegrades', 500, true);
        $i=0;
        foreach ($rs as $forum) {
            $i++;
            upgrade_set_timeout(60*5); // set up timeout, may also abort execution
            forum_update_grades($forum, 0, false);
            $pbar->update($i, $count, "Updating Forum grades ($i/$count).");
        }
    }
    $rs->close();
}
예제 #5
0
파일: lib.php 프로젝트: abhilash1994/moodle
/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will update an existing instance with new data.
 *
 * @global object
 * @param object $forum forum instance (with magic quotes)
 * @return bool success
 */
function forum_update_instance($forum, $mform)
{
    global $DB, $OUTPUT, $USER;
    $forum->timemodified = time();
    $forum->id = $forum->instance;
    if (empty($forum->assessed)) {
        $forum->assessed = 0;
    }
    if (empty($forum->ratingtime) or empty($forum->assessed)) {
        $forum->assesstimestart = 0;
        $forum->assesstimefinish = 0;
    }
    $oldforum = $DB->get_record('forum', array('id' => $forum->id));
    // MDL-3942 - if the aggregation type or scale (i.e. max grade) changes then recalculate the grades for the entire forum
    // if  scale changes - do we need to recheck the ratings, if ratings higher than scale how do we want to respond?
    // for count and sum aggregation types the grade we check to make sure they do not exceed the scale (i.e. max score) when calculating the grade
    if ($oldforum->assessed != $forum->assessed or $oldforum->scale != $forum->scale) {
        forum_update_grades($forum);
        // recalculate grades for the forum
    }
    if ($forum->type == 'single') {
        // Update related discussion and post.
        $discussions = $DB->get_records('forum_discussions', array('forum' => $forum->id), 'timemodified ASC');
        if (!empty($discussions)) {
            if (count($discussions) > 1) {
                echo $OUTPUT->notification(get_string('warnformorepost', 'forum'));
            }
            $discussion = array_pop($discussions);
        } else {
            // try to recover by creating initial discussion - MDL-16262
            $discussion = new stdClass();
            $discussion->course = $forum->course;
            $discussion->forum = $forum->id;
            $discussion->name = $forum->name;
            $discussion->assessed = $forum->assessed;
            $discussion->message = $forum->intro;
            $discussion->messageformat = $forum->introformat;
            $discussion->messagetrust = true;
            $discussion->mailnow = false;
            $discussion->groupid = -1;
            $message = '';
            forum_add_discussion($discussion, null, $message);
            if (!($discussion = $DB->get_record('forum_discussions', array('forum' => $forum->id)))) {
                print_error('cannotadd', 'forum');
            }
        }
        if (!($post = $DB->get_record('forum_posts', array('id' => $discussion->firstpost)))) {
            print_error('cannotfindfirstpost', 'forum');
        }
        $cm = get_coursemodule_from_instance('forum', $forum->id);
        $modcontext = context_module::instance($cm->id, MUST_EXIST);
        $post = $DB->get_record('forum_posts', array('id' => $discussion->firstpost), '*', MUST_EXIST);
        $post->subject = $forum->name;
        $post->message = $forum->intro;
        $post->messageformat = $forum->introformat;
        $post->messagetrust = trusttext_trusted($modcontext);
        $post->modified = $forum->timemodified;
        $post->userid = $USER->id;
        // MDL-18599, so that current teacher can take ownership of activities.
        if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) {
            // Ugly hack - we need to copy the files somehow.
            $options = array('subdirs' => true);
            // Use the same options as intro field!
            $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, $options, $post->message);
        }
        $DB->update_record('forum_posts', $post);
        $discussion->name = $forum->name;
        $DB->update_record('forum_discussions', $discussion);
    }
    $DB->update_record('forum', $forum);
    $modcontext = context_module::instance($forum->coursemodule);
    if ($forum->forcesubscribe == FORUM_INITIALSUBSCRIBE && $oldforum->forcesubscribe != $forum->forcesubscribe) {
        $users = \mod_forum\subscriptions::get_potential_subscribers($modcontext, 0, 'u.id, u.email', '');
        foreach ($users as $user) {
            \mod_forum\subscriptions::subscribe_user($user->id, $forum, $modcontext);
        }
    }
    forum_grade_item_update($forum);
    return true;
}
예제 #6
0
    /// Updating rate
} else {
    if ($oldrating = $DB->get_record('forum_ratings', array('userid' => $USER->id, 'post' => $post->id))) {
        if ($rate != $oldrating->rating) {
            $oldrating->rating = $rate;
            $oldrating->time = time();
            $DB->update_record('forum_ratings', $oldrating);
        }
        /// Inserting rate
    } else {
        $newrating = new object();
        $newrating->userid = $USER->id;
        $newrating->time = time();
        $newrating->post = $post->id;
        $newrating->rating = $rate;
        $DB->insert_record('forum_ratings', $newrating);
    }
}
/// Update grades
forum_update_grades($forum, $post->userid);
/// Check user can see any rate
$canviewanyrating = has_capability('mod/forum:viewanyrating', $context);
/// Decide if rates info is displayed
$rateinfo = '';
if ($canviewanyrating) {
    $rateinfo = forum_print_ratings($postid, $scale_values, $forum->assessed, true, NULL, true);
}
/// Calculate response
$response['status'] = 'Ok';
$response['message'] = $rateinfo;
echo json_encode($response);
예제 #7
0
파일: lib.php 프로젝트: r007/PMoodle
/**
 * Update grades by firing grade_updated event
 *
 * @param object $forum null means all forums
 * @param int $userid specific user only, 0 mean all
 * @param boolean $nullifnone return null if grade does not exist
 * @return void
 */
function forum_update_grades($forum = null, $userid = 0, $nullifnone = true)
{
    global $CFG;
    if ($forum != null) {
        require_once $CFG->libdir . '/gradelib.php';
        if ($grades = forum_get_user_grades($forum, $userid)) {
            forum_grade_item_update($forum, $grades);
        } else {
            if ($userid and $nullifnone) {
                $grade = new object();
                $grade->userid = $userid;
                $grade->rawgrade = NULL;
                forum_grade_item_update($forum, $grade);
            } else {
                forum_grade_item_update($forum);
            }
        }
    } else {
        $sql = "SELECT f.*, cm.idnumber as cmidnumber\n                  FROM {$CFG->prefix}forum f, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n                 WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
        if ($rs = get_recordset_sql($sql)) {
            while ($forum = rs_fetch_next_record($rs)) {
                if ($forum->assessed) {
                    forum_update_grades($forum, 0, false);
                } else {
                    forum_grade_item_update($forum);
                }
            }
            rs_close($rs);
        }
    }
}