コード例 #1
0
ファイル: lib.php プロジェクト: rohitshriwas/moodle
/**
 * @global object
 * @param array $attemptids
 * @param object $choice Choice main table row
 * @param object $cm Course-module object
 * @param object $course Course object
 * @return bool
 */
function choice_delete_responses($attemptids, $choice, $cm, $course) {
    global $DB, $CFG, $USER;
    require_once($CFG->libdir.'/completionlib.php');

    if(!is_array($attemptids) || empty($attemptids)) {
        return false;
    }

    foreach($attemptids as $num => $attemptid) {
        if(empty($attemptid)) {
            unset($attemptids[$num]);
        }
    }

    $context = context_module::instance($cm->id);
    $completion = new completion_info($course);
    foreach($attemptids as $attemptid) {
        if ($todelete = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'id' => $attemptid))) {
            // Trigger the event answer deleted.
            $eventdata = array();
            $eventdata['objectid'] = $todelete->id;
            $eventdata['context'] = $context;
            $eventdata['userid'] = $USER->id;
            $eventdata['courseid'] = $course->id;
            $eventdata['relateduserid'] = $todelete->userid;
            $eventdata['other'] = array();
            $eventdata['other']['choiceid'] = $choice->id;
            $eventdata['other']['optionid'] = $todelete->optionid;
            $event = \mod_choice\event\answer_deleted::create($eventdata);
            $event->add_record_snapshot('course', $course);
            $event->add_record_snapshot('course_modules', $cm);
            $event->add_record_snapshot('choice', $choice);
            $event->add_record_snapshot('choice_answers', $todelete);
            $event->trigger();

            $DB->delete_records('choice_answers', array('choiceid' => $choice->id, 'id' => $attemptid));
        }
    }

    // Update completion state.
    if ($completion->is_enabled($cm) && $choice->completionsubmit) {
        $completion->update_state($cm, COMPLETION_INCOMPLETE);
    }

    return true;
}
コード例 #2
0
ファイル: lib.php プロジェクト: dg711/moodle
/**
 * @global object
 * @param array $attemptids
 * @param object $choice Choice main table row
 * @param object $cm Course-module object
 * @param object $course Course object
 * @return bool
 */
function choice_delete_responses($attemptids, $choice, $cm, $course)
{
    global $DB, $CFG, $USER;
    require_once $CFG->libdir . '/completionlib.php';
    if (!is_array($attemptids) || empty($attemptids)) {
        return false;
    }
    foreach ($attemptids as $num => $attemptid) {
        if (empty($attemptid)) {
            unset($attemptids[$num]);
        }
    }
    $completion = new completion_info($course);
    foreach ($attemptids as $attemptid) {
        if ($todelete = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'id' => $attemptid))) {
            // Trigger the event answer deleted.
            \mod_choice\event\answer_deleted::create_from_object($todelete, $choice, $cm, $course)->trigger();
            $DB->delete_records('choice_answers', array('choiceid' => $choice->id, 'id' => $attemptid));
        }
    }
    // Update completion state.
    if ($completion->is_enabled($cm) && $choice->completionsubmit) {
        $completion->update_state($cm, COMPLETION_INCOMPLETE);
    }
    return true;
}