当前位置: 首页>>代码示例>>PHP>>正文


PHP rating_manager::delete_ratings方法代码示例

本文整理汇总了PHP中rating_manager::delete_ratings方法的典型用法代码示例。如果您正苦于以下问题:PHP rating_manager::delete_ratings方法的具体用法?PHP rating_manager::delete_ratings怎么用?PHP rating_manager::delete_ratings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rating_manager的用法示例。


在下文中一共展示了rating_manager::delete_ratings方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: forum_reset_userdata

/**
 * This function is used by the reset_course_userdata function in moodlelib.
 * This function will remove all posts from the specified forum
 * and clean up any related data.
 *
 * @global object
 * @global object
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function forum_reset_userdata($data) {
    global $CFG, $DB;
    require_once($CFG->dirroot.'/rating/lib.php');

    $componentstr = get_string('modulenameplural', 'forum');
    $status = array();

    $params = array($data->courseid);

    $removeposts = false;
    $typesql     = "";
    if (!empty($data->reset_forum_all)) {
        $removeposts = true;
        $typesstr    = get_string('resetforumsall', 'forum');
        $types       = array();
    } else if (!empty($data->reset_forum_types)){
        $removeposts = true;
        $typesql     = "";
        $types       = array();
        $forum_types_all = forum_get_forum_types_all();
        foreach ($data->reset_forum_types as $type) {
            if (!array_key_exists($type, $forum_types_all)) {
                continue;
            }
            $typesql .= " AND f.type=?";
            $types[] = $forum_types_all[$type];
            $params[] = $type;
        }
        $typesstr = get_string('resetforums', 'forum').': '.implode(', ', $types);
    }
    $alldiscussionssql = "SELECT fd.id
                            FROM {forum_discussions} fd, {forum} f
                           WHERE f.course=? AND f.id=fd.forum";

    $allforumssql      = "SELECT f.id
                            FROM {forum} f
                           WHERE f.course=?";

    $allpostssql       = "SELECT fp.id
                            FROM {forum_posts} fp, {forum_discussions} fd, {forum} f
                           WHERE f.course=? AND f.id=fd.forum AND fd.id=fp.discussion";

    $forumssql = $forums = $rm = null;

    if( $removeposts || !empty($data->reset_forum_ratings) ) {
        $forumssql      = "$allforumssql $typesql";
        $forums = $forums = $DB->get_records_sql($forumssql, $params);
        $rm = new rating_manager();
        $ratingdeloptions = new stdClass;
        $ratingdeloptions->component = 'mod_forum';
        $ratingdeloptions->ratingarea = 'post';
    }

    if ($removeposts) {
        $discussionssql = "$alldiscussionssql $typesql";
        $postssql       = "$allpostssql $typesql";

        // now get rid of all attachments
        $fs = get_file_storage();
        if ($forums) {
            foreach ($forums as $forumid=>$unused) {
                if (!$cm = get_coursemodule_from_instance('forum', $forumid)) {
                    continue;
                }
                $context = context_module::instance($cm->id);
                $fs->delete_area_files($context->id, 'mod_forum', 'attachment');
                $fs->delete_area_files($context->id, 'mod_forum', 'post');

                //remove ratings
                $ratingdeloptions->contextid = $context->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }

        // first delete all read flags
        $DB->delete_records_select('forum_read', "forumid IN ($forumssql)", $params);

        // remove tracking prefs
        $DB->delete_records_select('forum_track_prefs', "forumid IN ($forumssql)", $params);

        // remove posts from queue
        $DB->delete_records_select('forum_queue', "discussionid IN ($discussionssql)", $params);

        // all posts - initial posts must be kept in single simple discussion forums
        $DB->delete_records_select('forum_posts', "discussion IN ($discussionssql) AND parent <> 0", $params); // first all children
        $DB->delete_records_select('forum_posts', "discussion IN ($discussionssql AND f.type <> 'single') AND parent = 0", $params); // now the initial posts for non single simple

        // finally all discussions except single simple forums
        $DB->delete_records_select('forum_discussions', "forum IN ($forumssql AND f.type <> 'single')", $params);

//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:lib.php

示例2: delete_content

 /**
  * Delete all data linked to content, do not delete the context record itself
  */
 public function delete_content()
 {
     global $CFG, $DB;
     blocks_delete_all_for_context($this->_id);
     filter_delete_all_for_context($this->_id);
     require_once $CFG->dirroot . '/comment/lib.php';
     comment::delete_comments(array('contextid' => $this->_id));
     require_once $CFG->dirroot . '/rating/lib.php';
     $delopt = new stdclass();
     $delopt->contextid = $this->_id;
     $rm = new rating_manager();
     $rm->delete_ratings($delopt);
     // delete all files attached to this context
     $fs = get_file_storage();
     $fs->delete_area_files($this->_id);
     // delete all advanced grading data attached to this context
     require_once $CFG->dirroot . '/grade/grading/lib.php';
     grading_manager::delete_all_for_context($this->_id);
     // now delete stuff from role related tables, role_unassign_all
     // and unenrol should be called earlier to do proper cleanup
     $DB->delete_records('role_assignments', array('contextid' => $this->_id));
     $DB->delete_records('role_capabilities', array('contextid' => $this->_id));
     $DB->delete_records('role_names', array('contextid' => $this->_id));
 }
开发者ID:rolandovanegas,项目名称:moodle,代码行数:27,代码来源:accesslib.php

示例3: data_reset_userdata

/**
 * Actual implementation of the reset course functionality, delete all the
 * data responses for course $data->courseid.
 *
 * @global object
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function data_reset_userdata($data) {
    global $CFG, $DB;
    require_once($CFG->libdir.'/filelib.php');
    require_once($CFG->dirroot.'/rating/lib.php');

    $componentstr = get_string('modulenameplural', 'data');
    $status = array();

    $allrecordssql = "SELECT r.id
                        FROM {data_records} r
                             INNER JOIN {data} d ON r.dataid = d.id
                       WHERE d.course = ?";

    $alldatassql = "SELECT d.id
                      FROM {data} d
                     WHERE d.course=?";

    $rm = new rating_manager();
    $ratingdeloptions = new stdClass;
    $ratingdeloptions->component = 'mod_data';
    $ratingdeloptions->ratingarea = 'entry';

    // delete entries if requested
    if (!empty($data->reset_data)) {
        $DB->delete_records_select('comments', "itemid IN ($allrecordssql) AND commentarea='database_entry'", array($data->courseid));
        $DB->delete_records_select('data_content', "recordid IN ($allrecordssql)", array($data->courseid));
        $DB->delete_records_select('data_records', "dataid IN ($alldatassql)", array($data->courseid));

        if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
            foreach ($datas as $dataid=>$unused) {
                fulldelete("$CFG->dataroot/$data->courseid/moddata/data/$dataid");

                if (!$cm = get_coursemodule_from_instance('data', $dataid)) {
                    continue;
                }
                $datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);

                $ratingdeloptions->contextid = $datacontext->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }

        if (empty($data->reset_gradebook_grades)) {
            // remove all grades from gradebook
            data_reset_gradebook($data->courseid);
        }
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallentries', 'data'), 'error'=>false);
    }

    // remove entries by users not enrolled into course
    if (!empty($data->reset_data_notenrolled)) {
        $recordssql = "SELECT r.id, r.userid, r.dataid, u.id AS userexists, u.deleted AS userdeleted
                         FROM {data_records} r
                              JOIN {data} d ON r.dataid = d.id
                              LEFT JOIN {user} u ON r.userid = u.id
                        WHERE d.course = ? AND r.userid > 0";

        $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
        $notenrolled = array();
        $fields = array();
        $rs = $DB->get_recordset_sql($recordssql, array($data->courseid));
        foreach ($rs as $record) {
            if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted
              or !is_enrolled($course_context, $record->userid)) {
                //delete ratings
                if (!$cm = get_coursemodule_from_instance('data', $record->dataid)) {
                    continue;
                }
                $datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);
                $ratingdeloptions->contextid = $datacontext->id;
                $ratingdeloptions->itemid = $record->id;
                $rm->delete_ratings($ratingdeloptions);

                $DB->delete_records('comments', array('itemid'=>$record->id, 'commentarea'=>'database_entry'));
                $DB->delete_records('data_content', array('recordid'=>$record->id));
                $DB->delete_records('data_records', array('id'=>$record->id));
                // HACK: this is ugly - the recordid should be before the fieldid!
                if (!array_key_exists($record->dataid, $fields)) {
                    if ($fs = $DB->get_records('data_fields', array('dataid'=>$record->dataid))) {
                        $fields[$record->dataid] = array_keys($fs);
                    } else {
                        $fields[$record->dataid] = array();
                    }
                }
                foreach($fields[$record->dataid] as $fieldid) {
                    fulldelete("$CFG->dataroot/$data->courseid/moddata/data/$record->dataid/$fieldid/$record->id");
                }
                $notenrolled[$record->userid] = true;
            }
        }
        $rs->close();
//.........这里部分代码省略.........
开发者ID:nottmoo,项目名称:moodle,代码行数:101,代码来源:lib.php

示例4: rating

    $ratingoptions->component = $component;
    $ratingoptions->ratingarea = $ratingarea;
    $ratingoptions->itemid = $itemid;
    $ratingoptions->scaleid = $scaleid;
    $ratingoptions->userid = $USER->id;
    $rating = new rating($ratingoptions);
    $rating->update_rating($userrating);
} else {
    //delete the rating if the user set to Rate...
    $options = new stdClass();
    $options->contextid = $context->id;
    $options->component = $component;
    $options->ratingarea = $ratingarea;
    $options->userid = $USER->id;
    $options->itemid = $itemid;
    $rm->delete_ratings($options);
}
//todo add a setting to turn grade updating off for those who don't want them in gradebook
//note that this needs to be done in both rate.php and rate_ajax.php
if (!empty($cm) && $context->contextlevel == CONTEXT_MODULE) {
    //tell the module that its grades have changed
    $modinstance = $DB->get_record($cm->modname, array('id' => $cm->instance), '*', MUST_EXIST);
    $modinstance->cmidnumber = $cm->id;
    //MDL-12961
    $functionname = $cm->modname . '_update_grades';
    require_once $CFG->dirroot . "/mod/{$cm->modname}/lib.php";
    if (function_exists($functionname)) {
        $functionname($modinstance, $rateduserid);
    }
}
redirect($returnurl);
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:31,代码来源:rate.php

示例5: data_reset_userdata

/**
 * Actual implementation of the reset course functionality, delete all the
 * data responses for course $data->courseid.
 *
 * @global object
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function data_reset_userdata($data)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/filelib.php';
    require_once $CFG->dirroot . '/rating/lib.php';
    $componentstr = get_string('modulenameplural', 'data');
    $status = array();
    $allrecordssql = "SELECT r.id\n                        FROM {data_records} r\n                             INNER JOIN {data} d ON r.dataid = d.id\n                       WHERE d.course = ?";
    $alldatassql = "SELECT d.id\n                      FROM {data} d\n                     WHERE d.course=?";
    $rm = new rating_manager();
    $ratingdeloptions = new stdClass();
    $ratingdeloptions->component = 'mod_data';
    $ratingdeloptions->ratingarea = 'entry';
    // Set the file storage - may need it to remove files later.
    $fs = get_file_storage();
    // delete entries if requested
    if (!empty($data->reset_data)) {
        $DB->delete_records_select('comments', "itemid IN ({$allrecordssql}) AND commentarea='database_entry'", array($data->courseid));
        $DB->delete_records_select('data_content', "recordid IN ({$allrecordssql})", array($data->courseid));
        $DB->delete_records_select('data_records', "dataid IN ({$alldatassql})", array($data->courseid));
        if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
            foreach ($datas as $dataid => $unused) {
                if (!($cm = get_coursemodule_from_instance('data', $dataid))) {
                    continue;
                }
                $datacontext = context_module::instance($cm->id);
                // Delete any files that may exist.
                $fs->delete_area_files($datacontext->id, 'mod_data', 'content');
                $ratingdeloptions->contextid = $datacontext->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }
        if (empty($data->reset_gradebook_grades)) {
            // remove all grades from gradebook
            data_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallentries', 'data'), 'error' => false);
    }
    // remove entries by users not enrolled into course
    if (!empty($data->reset_data_notenrolled)) {
        $recordssql = "SELECT r.id, r.userid, r.dataid, u.id AS userexists, u.deleted AS userdeleted\n                         FROM {data_records} r\n                              JOIN {data} d ON r.dataid = d.id\n                              LEFT JOIN {user} u ON r.userid = u.id\n                        WHERE d.course = ? AND r.userid > 0";
        $course_context = context_course::instance($data->courseid);
        $notenrolled = array();
        $fields = array();
        $rs = $DB->get_recordset_sql($recordssql, array($data->courseid));
        foreach ($rs as $record) {
            if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted or !is_enrolled($course_context, $record->userid)) {
                //delete ratings
                if (!($cm = get_coursemodule_from_instance('data', $record->dataid))) {
                    continue;
                }
                $datacontext = context_module::instance($cm->id);
                $ratingdeloptions->contextid = $datacontext->id;
                $ratingdeloptions->itemid = $record->id;
                $rm->delete_ratings($ratingdeloptions);
                // Delete any files that may exist.
                if ($contents = $DB->get_records('data_content', array('recordid' => $record->id), '', 'id')) {
                    foreach ($contents as $content) {
                        $fs->delete_area_files($datacontext->id, 'mod_data', 'content', $content->id);
                    }
                }
                $notenrolled[$record->userid] = true;
                $DB->delete_records('comments', array('itemid' => $record->id, 'commentarea' => 'database_entry'));
                $DB->delete_records('data_content', array('recordid' => $record->id));
                $DB->delete_records('data_records', array('id' => $record->id));
            }
        }
        $rs->close();
        $status[] = array('component' => $componentstr, 'item' => get_string('deletenotenrolled', 'data'), 'error' => false);
    }
    // remove all ratings
    if (!empty($data->reset_data_ratings)) {
        if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
            foreach ($datas as $dataid => $unused) {
                if (!($cm = get_coursemodule_from_instance('data', $dataid))) {
                    continue;
                }
                $datacontext = context_module::instance($cm->id);
                $ratingdeloptions->contextid = $datacontext->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }
        if (empty($data->reset_gradebook_grades)) {
            // remove all grades from gradebook
            data_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallratings'), 'error' => false);
    }
    // remove all comments
    if (!empty($data->reset_data_comments)) {
        $DB->delete_records_select('comments', "itemid IN ({$allrecordssql}) AND commentarea='database_entry'", array($data->courseid));
//.........这里部分代码省略.........
开发者ID:gabrielrosset,项目名称:moodle,代码行数:101,代码来源:lib.php

示例6: remove_course_contents


//.........这里部分代码省略.........
    foreach ($cleanuplugintypes as $type) {
        if (!empty($callbacks[$type])) {
            foreach ($callbacks[$type] as $pluginfunction) {
                debugging("Callback delete_course is deprecated. Function {$pluginfunction} should be converted " . 'to observer of event \\core\\event\\course_content_deleted', DEBUG_DEVELOPER);
                $pluginfunction($course->id, $showfeedback);
            }
            if ($showfeedback) {
                echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess');
            }
        }
    }
    // Delete questions and question categories.
    question_delete_course($course, $showfeedback);
    if ($showfeedback) {
        echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess');
    }
    // Make sure there are no subcontexts left - all valid blocks and modules should be already gone.
    $childcontexts = $coursecontext->get_child_contexts();
    // Returns all subcontexts since 2.2.
    foreach ($childcontexts as $childcontext) {
        $childcontext->delete();
    }
    unset($childcontexts);
    // Remove all roles and enrolments by default.
    if (empty($options['keep_roles_and_enrolments'])) {
        // This hack is used in restore when deleting contents of existing course.
        role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true);
        enrol_course_delete($course);
        if ($showfeedback) {
            echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess');
        }
    }
    // Delete any groups, removing members and grouping/course links first.
    if (empty($options['keep_groups_and_groupings'])) {
        groups_delete_groupings($course->id, $showfeedback);
        groups_delete_groups($course->id, $showfeedback);
    }
    // Filters be gone!
    filter_delete_all_for_context($coursecontext->id);
    // Notes, you shall not pass!
    note_delete_all($course->id);
    // Die comments!
    comment::delete_comments($coursecontext->id);
    // Ratings are history too.
    $delopt = new stdclass();
    $delopt->contextid = $coursecontext->id;
    $rm = new rating_manager();
    $rm->delete_ratings($delopt);
    // Delete course tags.
    core_tag_tag::remove_all_item_tags('core', 'course', $course->id);
    // Notify the competency subsystem.
    \core_competency\api::hook_course_deleted($course);
    // Delete calendar events.
    $DB->delete_records('event', array('courseid' => $course->id));
    $fs->delete_area_files($coursecontext->id, 'calendar');
    // Delete all related records in other core tables that may have a courseid
    // This array stores the tables that need to be cleared, as
    // table_name => column_name that contains the course id.
    $tablestoclear = array('backup_courses' => 'courseid', 'user_lastaccess' => 'courseid');
    foreach ($tablestoclear as $table => $col) {
        $DB->delete_records($table, array($col => $course->id));
    }
    // Delete all course backup files.
    $fs->delete_area_files($coursecontext->id, 'backup');
    // Cleanup course record - remove links to deleted stuff.
    $oldcourse = new stdClass();
    $oldcourse->id = $course->id;
    $oldcourse->summary = '';
    $oldcourse->cacherev = 0;
    $oldcourse->legacyfiles = 0;
    if (!empty($options['keep_groups_and_groupings'])) {
        $oldcourse->defaultgroupingid = 0;
    }
    $DB->update_record('course', $oldcourse);
    // Delete course sections.
    $DB->delete_records('course_sections', array('course' => $course->id));
    // Delete legacy, section and any other course files.
    $fs->delete_area_files($coursecontext->id, 'course');
    // Files from summary and section.
    // Delete all remaining stuff linked to context such as files, comments, ratings, etc.
    if (empty($options['keep_roles_and_enrolments']) and empty($options['keep_groups_and_groupings'])) {
        // Easy, do not delete the context itself...
        $coursecontext->delete_content();
    } else {
        // Hack alert!!!!
        // We can not drop all context stuff because it would bork enrolments and roles,
        // there might be also files used by enrol plugins...
    }
    // Delete legacy files - just in case some files are still left there after conversion to new file api,
    // also some non-standard unsupported plugins may try to store something there.
    fulldelete($CFG->dataroot . '/' . $course->id);
    // Delete from cache to reduce the cache size especially makes sense in case of bulk course deletion.
    $cachemodinfo = cache::make('core', 'coursemodinfo');
    $cachemodinfo->delete($courseid);
    // Trigger a course content deleted event.
    $event = \core\event\course_content_deleted::create(array('objectid' => $course->id, 'context' => $coursecontext, 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname, 'options' => $options)));
    $event->add_record_snapshot('course', $course);
    $event->trigger();
    return true;
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:101,代码来源:moodlelib.php

示例7: remove_course_contents


//.........这里部分代码省略.........
    if ($showfeedback) {
        echo $OUTPUT->notification($strdeleted . get_string('type_mod_plural', 'plugin'), 'notifysuccess');
    }
    // Cleanup the rest of plugins
    $cleanuplugintypes = array('report', 'coursereport', 'format');
    foreach ($cleanuplugintypes as $type) {
        $plugins = get_plugin_list_with_function($type, 'delete_course', 'lib.php');
        foreach ($plugins as $plugin => $pluginfunction) {
            $pluginfunction($course->id, $showfeedback);
        }
        if ($showfeedback) {
            echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess');
        }
    }
    // Delete questions and question categories
    question_delete_course($course, $showfeedback);
    if ($showfeedback) {
        echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess');
    }
    // Make sure there are no subcontexts left - all valid blocks and modules should be already gone
    $childcontexts = $coursecontext->get_child_contexts();
    // returns all subcontexts since 2.2
    foreach ($childcontexts as $childcontext) {
        $childcontext->delete();
    }
    unset($childcontexts);
    // Remove all roles and enrolments by default
    if (empty($options['keep_roles_and_enrolments'])) {
        // this hack is used in restore when deleting contents of existing course
        role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true);
        enrol_course_delete($course);
        if ($showfeedback) {
            echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess');
        }
    }
    // Delete any groups, removing members and grouping/course links first.
    if (empty($options['keep_groups_and_groupings'])) {
        groups_delete_groupings($course->id, $showfeedback);
        groups_delete_groups($course->id, $showfeedback);
    }
    // filters be gone!
    filter_delete_all_for_context($coursecontext->id);
    // die comments!
    comment::delete_comments($coursecontext->id);
    // ratings are history too
    $delopt = new stdclass();
    $delopt->contextid = $coursecontext->id;
    $rm = new rating_manager();
    $rm->delete_ratings($delopt);
    // Delete course tags
    coursetag_delete_course_tags($course->id, $showfeedback);
    // Delete calendar events
    $DB->delete_records('event', array('courseid' => $course->id));
    $fs->delete_area_files($coursecontext->id, 'calendar');
    // Delete all related records in other core tables that may have a courseid
    // This array stores the tables that need to be cleared, as
    // table_name => column_name that contains the course id.
    $tablestoclear = array('log' => 'course', 'backup_courses' => 'courseid', 'user_lastaccess' => 'courseid');
    foreach ($tablestoclear as $table => $col) {
        $DB->delete_records($table, array($col => $course->id));
    }
    // delete all course backup files
    $fs->delete_area_files($coursecontext->id, 'backup');
    // cleanup course record - remove links to deleted stuff
    $oldcourse = new stdClass();
    $oldcourse->id = $course->id;
    $oldcourse->summary = '';
    $oldcourse->modinfo = NULL;
    $oldcourse->legacyfiles = 0;
    $oldcourse->enablecompletion = 0;
    if (!empty($options['keep_groups_and_groupings'])) {
        $oldcourse->defaultgroupingid = 0;
    }
    $DB->update_record('course', $oldcourse);
    // Delete course sections and availability options.
    $DB->delete_records_select('course_sections_availability', 'coursesectionid IN (SELECT id from {course_sections} WHERE course=?)', array($course->id));
    $DB->delete_records('course_sections', array('course' => $course->id));
    // delete legacy, section and any other course files
    $fs->delete_area_files($coursecontext->id, 'course');
    // files from summary and section
    // Delete all remaining stuff linked to context such as files, comments, ratings, etc.
    if (empty($options['keep_roles_and_enrolments']) and empty($options['keep_groups_and_groupings'])) {
        // Easy, do not delete the context itself...
        $coursecontext->delete_content();
    } else {
        // Hack alert!!!!
        // We can not drop all context stuff because it would bork enrolments and roles,
        // there might be also files used by enrol plugins...
    }
    // Delete legacy files - just in case some files are still left there after conversion to new file api,
    // also some non-standard unsupported plugins may try to store something there
    fulldelete($CFG->dataroot . '/' . $course->id);
    // Finally trigger the event
    $course->context = $coursecontext;
    // you can not access context in cron event later after course is deleted
    $course->options = $options;
    // not empty if we used any crazy hack
    events_trigger('course_content_removed', $course);
    return true;
}
开发者ID:nmicha,项目名称:moodle,代码行数:101,代码来源:moodlelib.php

示例8: glossary_reset_userdata

/**
 * Actual implementation of the reset course functionality, delete all the
 * glossary responses for course $data->courseid.
 *
 * @global object
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function glossary_reset_userdata($data) {
    global $CFG, $DB;
    require_once($CFG->dirroot.'/rating/lib.php');

    $componentstr = get_string('modulenameplural', 'glossary');
    $status = array();

    $allentriessql = "SELECT e.id
                        FROM {glossary_entries} e
                             JOIN {glossary} g ON e.glossaryid = g.id
                       WHERE g.course = ?";

    $allglossariessql = "SELECT g.id
                           FROM {glossary} g
                          WHERE g.course = ?";

    $params = array($data->courseid);

    $fs = get_file_storage();

    $rm = new rating_manager();
    $ratingdeloptions = new stdClass;
    $ratingdeloptions->component = 'mod_glossary';
    $ratingdeloptions->ratingarea = 'entry';

    // delete entries if requested
    if (!empty($data->reset_glossary_all)
         or (!empty($data->reset_glossary_types) and in_array('main', $data->reset_glossary_types) and in_array('secondary', $data->reset_glossary_types))) {

        $params[] = 'glossary_entry';
        $DB->delete_records_select('comments', "itemid IN ($allentriessql) AND commentarea=?", $params);
        $DB->delete_records_select('glossary_alias',    "entryid IN ($allentriessql)", $params);
        $DB->delete_records_select('glossary_entries', "glossaryid IN ($allglossariessql)", $params);

        // now get rid of all attachments
        if ($glossaries = $DB->get_records_sql($allglossariessql, $params)) {
            foreach ($glossaries as $glossaryid=>$unused) {
                if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
                    continue;
                }
                $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                $fs->delete_area_files($context->id, 'mod_glossary', 'attachment');

                //delete ratings
                $ratingdeloptions->contextid = $context->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }

        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            glossary_reset_gradebook($data->courseid);
        }

        $status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossariesall', 'glossary'), 'error'=>false);

    } else if (!empty($data->reset_glossary_types)) {
        $mainentriessql         = "$allentries AND g.mainglossary=1";
        $secondaryentriessql    = "$allentries AND g.mainglossary=0";

        $mainglossariessql      = "$allglossariessql AND g.mainglossary=1";
        $secondaryglossariessql = "$allglossariessql AND g.mainglossary=0";

        if (in_array('main', $data->reset_glossary_types)) {
            $params[] = 'glossary_entry';
            $DB->delete_records_select('comments', "itemid IN ($mainentriessql) AND commentarea=?", $params);
            $DB->delete_records_select('glossary_entries', "glossaryid IN ($mainglossariessql)", $params);

            if ($glossaries = $DB->get_records_sql($mainglossariessql, $params)) {
                foreach ($glossaries as $glossaryid=>$unused) {
                    if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
                        continue;
                    }
                    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                    $fs->delete_area_files($context->id, 'mod_glossary', 'attachment');

                    //delete ratings
                    $ratingdeloptions->contextid = $context->id;
                    $rm->delete_ratings($ratingdeloptions);
                }
            }

            // remove all grades from gradebook
            if (empty($data->reset_gradebook_grades)) {
                glossary_reset_gradebook($data->courseid, 'main');
            }

            $status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossaries', 'glossary'), 'error'=>false);

        } else if (in_array('secondary', $data->reset_glossary_types)) {
            $params[] = 'glossary_entry';
            $DB->delete_records_select('comments', "itemid IN ($secondaryentriessql) AND commentarea=?", $params);
//.........这里部分代码省略.........
开发者ID:rolandovanegas,项目名称:moodle,代码行数:101,代码来源:lib.php

示例9: array

        $DB->delete_records("glossary_alias", array("entryid" => $entry->id));
        $DB->delete_records("glossary_entries", array("id" => $entry->id));
        // Update completion state
        $completion = new completion_info($course);
        if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries) {
            $completion->update_state($cm, COMPLETION_INCOMPLETE, $entry->userid);
        }
        //delete glossary entry ratings
        require_once $CFG->dirroot . '/rating/lib.php';
        $delopt = new stdClass();
        $delopt->contextid = $context->id;
        $delopt->component = 'mod_glossary';
        $delopt->ratingarea = 'entry';
        $delopt->itemid = $entry->id;
        $rm = new rating_manager();
        $rm->delete_ratings($delopt);
    }
    add_to_log($course->id, "glossary", "delete entry", "view.php?id={$cm->id}&amp;mode={$prevmode}&amp;hook={$hook}", $entry->id, $cm->id);
    redirect("view.php?id={$cm->id}&amp;mode={$prevmode}&amp;hook={$hook}");
} else {
    // the operation has not been confirmed yet so ask the user to do so
    $PAGE->navbar->add(get_string('delete'));
    $PAGE->set_title(format_string($glossary->name));
    $PAGE->set_heading($course->fullname);
    echo $OUTPUT->header();
    $areyousure = "<b>" . format_string($entry->concept) . "</b><p>{$strareyousuredelete}</p>";
    $linkyes = 'deleteentry.php';
    $linkno = 'view.php';
    $optionsyes = array('id' => $cm->id, 'entry' => $entry->id, 'confirm' => 1, 'sesskey' => sesskey(), 'prevmode' => $prevmode, 'hook' => $hook);
    $optionsno = array('id' => $cm->id, 'mode' => $prevmode, 'hook' => $hook);
    echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:31,代码来源:deleteentry.php

示例10: delete_context

/**
 * Remove a context record and any dependent entries,
 * removes context from static context cache too
 *
 * @param int $level
 * @param int $instanceid
 * @param bool $deleterecord false means keep record for now
 * @return bool returns true or throws an exception
 */
function delete_context($contextlevel, $instanceid, $deleterecord = true)
{
    global $DB, $ACCESSLIB_PRIVATE, $CFG;
    // do not use get_context_instance(), because the related object might not exist,
    // or the context does not exist yet and it would be created now
    if ($context = $DB->get_record('context', array('contextlevel' => $contextlevel, 'instanceid' => $instanceid))) {
        // delete these first because they might fetch the context and try to recreate it!
        blocks_delete_all_for_context($context->id);
        filter_delete_all_for_context($context->id);
        require_once $CFG->dirroot . '/comment/lib.php';
        comment::delete_comments(array('contextid' => $context->id));
        require_once $CFG->dirroot . '/rating/lib.php';
        $delopt = new stdclass();
        $delopt->contextid = $context->id;
        $rm = new rating_manager();
        $rm->delete_ratings($delopt);
        // delete all files attached to this context
        $fs = get_file_storage();
        $fs->delete_area_files($context->id);
        // now delete stuff from role related tables, role_unassign_all
        // and unenrol should be called earlier to do proper cleanup
        $DB->delete_records('role_assignments', array('contextid' => $context->id));
        $DB->delete_records('role_capabilities', array('contextid' => $context->id));
        $DB->delete_records('role_names', array('contextid' => $context->id));
        // and finally it is time to delete the context record if requested
        if ($deleterecord) {
            $DB->delete_records('context', array('id' => $context->id));
            // purge static context cache if entry present
            $ACCESSLIB_PRIVATE->contexcache->remove($context);
        }
        // do not mark dirty contexts if parents unknown
        if (!is_null($context->path) and $context->depth > 0) {
            mark_context_dirty($context->path);
        }
    }
    return true;
}
开发者ID:LMSeXT,项目名称:SAWEE-WS_server-lib,代码行数:46,代码来源:accesslib.php

示例11: delete_all_data

 /**
  * Called by delete_instance. Deletes all the forum's data (but
  * not the actual forum record, delete_instance handles that).
  */
 public function delete_all_data()
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/tag/lib.php';
     // Delete per-post data
     $postquery = "\nSELECT\n    fp.id\nFROM\n    {forumng_discussions} fd\n    INNER JOIN {forumng_posts} fp on fp.discussionid = fd.id\nWHERE\n    fd.forumngid = ?";
     $postparams = array($this->forumfields->id);
     $DB->execute("DELETE FROM {forumng_ratings}\n            WHERE postid IN ({$postquery})", $postparams);
     $DB->execute("DELETE FROM {forumng_read_posts}\n                WHERE postid IN ({$postquery})", $postparams);
     // Delete per-discussion data
     $discussionquery = "SELECT id FROM {forumng_discussions}\n            WHERE forumngid = ?";
     $discussionparams = array($this->forumfields->id);
     $DB->execute("DELETE FROM {forumng_read}\n            WHERE discussionid IN ({$discussionquery})", $discussionparams);
     $DB->execute("DELETE FROM {forumng_posts}\n            WHERE discussionid IN ({$discussionquery})", $discussionparams);
     // Delete standard rating data.
     if ($this->get_enableratings() == mod_forumng::FORUMNG_STANDARD_RATING && !$this->is_clone()) {
         require_once $CFG->dirroot . '/rating/lib.php';
         $delopt = new stdClass();
         $delopt->contextid = $this->get_context(true)->id;
         $delopt->component = 'mod_forumng';
         $delopt->ratingarea = 'post';
         $rm = new rating_manager();
         $rm->delete_ratings($delopt);
     }
     // Delete per-forum data
     if ($this->is_clone()) {
         $DB->delete_records('forumng_subscriptions', array('clonecmid' => $this->get_course_module_id()));
     } else {
         $DB->delete_records('forumng_subscriptions', array('forumngid' => $this->forumfields->id));
     }
     $DB->delete_records('forumng_discussions', array('forumngid' => $this->forumfields->id));
     // Delete tag instances.
     tag_delete_instances('mod_forumng', $this->context->id);
 }
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:38,代码来源:mod_forumng.php

示例12: oublog_reset_userdata

/**
 * Actual implementation of the reset course functionality, delete all
 * oublog posts.
 *
 * @global object
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function oublog_reset_userdata($data)
{
    global $DB;
    $componentstr = get_string('modulenameplural', 'oublog');
    $status = array();
    if (!empty($data->reset_oublog)) {
        // Delete post-related data.
        $postidsql = "SELECT pst.id\n                        FROM {oublog_posts} pst\n                        JOIN {oublog_instances} ins ON (ins.id = pst.oubloginstancesid)\n                        JOIN {oublog} obl ON (obl.id = ins.oublogid)\n                       WHERE obl.course = ?";
        $params = array($data->courseid);
        $DB->delete_records_select('oublog_comments', "postid IN ({$postidsql})", $params);
        $DB->delete_records_select('oublog_comments_moderated', "postid IN ({$postidsql})", $params);
        $DB->delete_records_select('oublog_edits', "postid IN ({$postidsql})", $params);
        // Delete instance-related data.
        $insidsql = "SELECT ins.id\n                       FROM {oublog_instances} ins\n                       JOIN {oublog} obl ON (obl.id = ins.oublogid)\n                      WHERE obl.course = ?";
        $DB->delete_records_select('oublog_links', "oubloginstancesid IN ({$insidsql})", $params);
        $DB->delete_records_select('oublog_taginstances', "oubloginstancesid IN ({$insidsql})", $params);
        $DB->delete_records_select('oublog_posts', "oubloginstancesid IN ({$insidsql})", $params);
        $blogidsql = "SELECT obl.id\n                        FROM {oublog} obl\n                       WHERE obl.course = ?";
        // Delete instances:
        $DB->delete_records_select('oublog_instances', "oublogid IN ({$blogidsql})", $params);
        // Reset views:
        $DB->execute("UPDATE {oublog} SET views = 0 WHERE course = ?", $params);
        $rm = new rating_manager();
        $ratingdeloptions = new stdClass();
        $ratingdeloptions->component = 'mod_oublog';
        $ratingdeloptions->ratingarea = 'post';
        // Now get rid of all attachments and ratings.
        $fs = get_file_storage();
        $oublogs = get_coursemodules_in_course('oublog', $data->courseid);
        if ($oublogs) {
            foreach ($oublogs as $oublogid => $unused) {
                if (!($cm = get_coursemodule_from_instance('oublog', $oublogid))) {
                    continue;
                }
                $context = context_module::instance($cm->id);
                $fs->delete_area_files($context->id, 'mod_oublog', 'attachment');
                $fs->delete_area_files($context->id, 'mod_oublog', 'message');
                $fs->delete_area_files($context->id, 'mod_oublog', 'messagecomment');
                $ratingdeloptions->contextid = $context->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('removeblogs', 'oublog'), 'error' => false);
    }
    return $status;
}
开发者ID:eugeneventer,项目名称:moodle-mod_oublog,代码行数:55,代码来源:lib.php

示例13: pcast_reset_userdata

/**
 * Actual implementation of the rest coures functionality, delete all the
 * pcast responses for course $data->courseid.
 *
 * @global stdClass
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function pcast_reset_userdata($data)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/rating/lib.php';
    $componentstr = get_string('modulenameplural', 'pcast');
    $status = array();
    $allepisodessql = "SELECT e.id\n                        FROM {pcast_episodes} e\n                             JOIN {pcast} p ON e.pcastid = p.id\n                       WHERE p.course = ?";
    $allpcastssql = "SELECT p.id\n                           FROM {pcast} p\n                          WHERE p.course = ?";
    $params = array($data->courseid);
    $fs = get_file_storage();
    $rm = new rating_manager();
    $ratingdeloptions = new stdClass();
    $ratingdeloptions->component = 'mod_pcast';
    $ratingdeloptions->ratingarea = 'episode';
    // delete entries if requested
    if (!empty($data->reset_pcast_all)) {
        $params[] = 'pcast_episode';
        $DB->delete_records_select('comments', "itemid IN ({$allepisodessql}) AND commentarea=?", $params);
        $DB->delete_records_select('pcast_episodes', "pcastid IN ({$allpcastssql})", $params);
        // now get rid of all attachments
        if ($pcasts = $DB->get_records_sql($allpcastssql, $params)) {
            foreach ($pcasts as $pcastid => $unused) {
                if (!($cm = get_coursemodule_from_instance('pcast', $pcastid))) {
                    continue;
                }
                $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                $fs->delete_area_files($context->id, 'mod_pcast', 'episode');
                //delete ratings
                $ratingdeloptions->contextid = $context->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }
        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            pcast_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('resetpcastsall', 'pcast'), 'error' => false);
    } else {
        if (!empty($data->reset_pcast_notenrolled)) {
            $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
            // Get list of enrolled users
            $people = get_enrolled_users($course_context);
            $list = '';
            $list2 = '';
            foreach ($people as $person) {
                $list .= ' AND e.userid != ?';
                $list2 .= ' AND userid != ?';
                $params[] = $person->id;
            }
            // Construct SQL to episodes from users whe are no longer enrolled
            $unenrolledepisodessql = "SELECT e.id\n                                      FROM {pcast_episodes} e\n                                      WHERE e.course = ? " . $list;
            $params[] = 'pcast_episode';
            $DB->delete_records_select('comments', "itemid IN ({$unenrolledepisodessql}) AND commentarea=?", $params);
            $DB->delete_records_select('pcast_episodes', "course =? " . $list2, $params);
            // now get rid of all attachments
            if ($pcasts = $DB->get_records_sql($unenrolledepisodessql, $params)) {
                foreach ($pcasts as $pcastid => $unused) {
                    if (!($cm = get_coursemodule_from_instance('pcast', $pcastid))) {
                        continue;
                    }
                    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                    $fs->delete_area_files($context->id, 'mod_pcast', 'episode');
                    //delete ratings
                    $ratingdeloptions->contextid = $context->id;
                    $rm->delete_ratings($ratingdeloptions);
                }
            }
            // remove all grades from gradebook
            if (empty($data->reset_gradebook_grades)) {
                pcast_reset_gradebook($data->courseid);
            }
            $status[] = array('component' => $componentstr, 'item' => get_string('deletenotenrolled', 'pcast'), 'error' => false);
        }
    }
    // remove all ratings
    if (!empty($data->reset_pcast_ratings)) {
        //remove ratings
        if ($pcasts = $DB->get_records_sql($allpcastssql, $params)) {
            foreach ($pcasts as $pcastid => $unused) {
                if (!($cm = get_coursemodule_from_instance('pcast', $pcastid))) {
                    continue;
                }
                $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                //delete ratings
                $ratingdeloptions->contextid = $context->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }
        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            pcast_reset_gradebook($data->courseid);
        }
//.........这里部分代码省略.........
开发者ID:rtsfc,项目名称:moodle-mod_pcast,代码行数:101,代码来源:lib.php


注:本文中的rating_manager::delete_ratings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。