Ejemplo n.º 1
0
function checklist_reset_userdata($data)
{
    global $DB;
    $status = array();
    $component = get_string('modulenameplural', 'checklist');
    $typestr = get_string('resetchecklistprogress', 'checklist');
    $status[] = array('component' => $component, 'item' => $typestr, 'error' => false);
    if (!empty($data->reset_checklist_progress)) {
        $checklists = $DB->get_records('checklist', array('course' => $data->courseid));
        if (!$checklists) {
            return $status;
        }
        list($csql, $cparams) = $DB->get_in_or_equal(array_keys($checklists));
        $items = $DB->get_records_select('checklist_item', 'checklist ' . $csql, $cparams);
        if (!$items) {
            return $status;
        }
        $itemids = array_keys($items);
        $DB->delete_records_list('checklist_check', 'item', $itemids);
        $DB->delete_records_list('checklist_comment', 'itemid', $itemids);
        $sql = "checklist {$csql} AND userid <> 0";
        $DB->delete_records_select('checklist_item', $sql, $cparams);
        // Reset the grades
        foreach ($checklists as $checklist) {
            checklist_grade_item_update($checklist, 'reset');
        }
    }
    return $status;
}
function checklist_reset_userdata($data)
{
    global $CFG;
    $status = array();
    $component = get_string('modulenameplural', 'checklist');
    $typestr = get_string('resetchecklistprogress', 'checklist');
    $status[] = array('component' => $component, 'item' => $typestr, 'error' => false);
    if (!empty($data->reset_checklist_progress)) {
        $checklists = get_records('checklist', 'course', $data->courseid);
        if (!$checklists) {
            return $status;
        }
        $checklistkeys = implode(',', array_keys($checklists));
        $items = get_records_select('checklist_item', 'checklist IN (' . $checklistkeys . ')');
        if (!$items) {
            return $status;
        }
        $items = implode(',', array_keys($items));
        delete_records_select('checklist_check', 'item IN (' . $items . ')');
        $sql = 'checklist IN (' . $checklistkeys . ') AND userid != 0';
        delete_records_select('checklist_item', $sql);
        // Reset the grades
        foreach ($checklists as $checklist) {
            checklist_grade_item_update($checklist, 'reset');
        }
    }
    return $status;
}