Ejemplo n.º 1
0
Archivo: lib.php Proyecto: rrusso/EARS
 function before_delete()
 {
     $hook = CoursePrefsHook::findByUnique($this->cpsName());
     if ($hook && $hook->delete()) {
         $a->name = $hook->getName();
         $a->type = $hook->getType();
         mtrace(get_string('hook_delete', 'block_courseprefs', $a));
     }
 }
Ejemplo n.º 2
0
 public static function allHooks($logger = null)
 {
     $dbhooks = CoursePrefsHook::findAll();
     return new HookCollection(array_map(create_function('$dbhook', 'return $dbhook->hook();'), $dbhooks), $logger);
 }
Ejemplo n.º 3
0
Archivo: lib.php Proyecto: rrusso/EARS
/**
 * Courseprefs clean moved to an external function to be appended anywhere as necessary
 */
function courseprefs_cleanup($file = 'cleanup.php', $semester = 0, $logger = null, $web_report = false)
{
    global $CFG;
    if (!$logger) {
        $logger = new Logger(true);
    }
    $clean_children = array("block_courseprefs_teamteach", "block_courseprefs_crosslist", "block_courseprefs_split", "block_courseprefs_logs", "block_courseprefs_teachers", "block_courseprefs_students");
    if ($semester == 0) {
        $sql = "SELECT * FROM {$CFG->prefix}block_courseprefs_semesters \n                WHERE grades_due < " . time();
    } else {
        $sql = "SELECT * FROM {$CFG->prefix}block_courseprefs_semesters\n                WHERE id = {$semester}";
    }
    require_once $CFG->dirroot . '/blocks/courseprefs/classes/CoursePrefsHook.php';
    $hooks = CoursePrefsHook::allHooks($logger);
    // Parent semesters to remove
    $semesters = get_records_sql($sql);
    // If the result from query is not null, iterate
    if ($semesters) {
        foreach ($semesters as $semester) {
            $hooks->execute('cleanup', $semester->id);
            // For processing time's sake, we remove enroll here
            delete_records('block_courseprefs_enroll', 'semestersid', $semester->id);
            $str = "Removing {$semester->campus} {$semester->name} {$semester->year}" . " and all associated data.";
            $logger->log($str);
            if ($web_report) {
                mtrace($str);
            }
        }
        $semesterids = implode(',', array_keys($semesters));
        $sql = "SELECT * FROM {$CFG->prefix}block_courseprefs_sections\n                  WHERE semestersid IN ({$semesterids})";
        $sections = get_records_sql($sql);
        foreach ($sections as $section) {
            // Blow away the 'normal' cases first
            foreach ($clean_children as $table) {
                delete_records($table, 'sectionsid', $section->id);
            }
            // Remove the section entry
            delete_records('block_courseprefs_sections', 'id', $section->id);
            $str = "Removing section {$section->id} {$section->idnumber}";
            $logger->log($str);
        }
        // Remove the semesters
        delete_records_select('block_courseprefs_semesters', 'id IN (' . $semesterids . ')');
    } else {
        $str = "There are no semesters to remove.";
        $logger->log($str);
        if ($web_report) {
            mtrace($str);
        }
    }
    $header = get_string('cleanup_header', 'block_courseprefs');
    $logger->reportErrors($file, $header, $header);
}