Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 299... Línea 299...
299
    // enrolment.
299
    // enrolment.
300
    $onecourse = $courseid ? "AND e.courseid = :courseid" : "";
300
    $onecourse = $courseid ? "AND e.courseid = :courseid" : "";
301
    list($enabled, $params) = $DB->get_in_or_equal(explode(',', $CFG->enrol_plugins_enabled), SQL_PARAMS_NAMED, 'e');
301
    list($enabled, $params) = $DB->get_in_or_equal(explode(',', $CFG->enrol_plugins_enabled), SQL_PARAMS_NAMED, 'e');
302
    $params['courseid'] = $courseid;
302
    $params['courseid'] = $courseid;
303
    $sql = "SELECT pue.userid, e.id AS enrolid, MIN(pue.status + pe.status) AS status,
303
    $sql = "SELECT pue.userid, e.id AS enrolid, MIN(pue.status + pe.status) AS status,
304
                      MIN(CASE WHEN (pue.status + pe.status = 0) THEN pue.timestart ELSE 9999999999 END) AS timestart,
304
                      MIN(CASE WHEN (pue.status + pe.status = 0) THEN pue.timestart ELSE " . SQL_INT_MAX . " END) AS timestart,
305
                      MAX(CASE WHEN (pue.status + pe.status = 0) THEN
305
                      MAX(CASE WHEN (pue.status + pe.status = 0) THEN
306
                                (CASE WHEN pue.timeend = 0 THEN 9999999999 ELSE pue.timeend END)
306
                                (CASE WHEN pue.timeend = 0 THEN " . SQL_INT_MAX . " ELSE pue.timeend END)
307
                                ELSE 0 END) AS timeend
307
                                ELSE 0 END) AS timeend
308
              FROM {user_enrolments} pue
308
              FROM {user_enrolments} pue
309
              JOIN {enrol} pe ON (pe.id = pue.enrolid AND pe.enrol <> 'meta' AND pe.enrol $enabled)
309
              JOIN {enrol} pe ON (pe.id = pue.enrolid AND pe.enrol <> 'meta' AND pe.enrol $enabled)
310
              JOIN {enrol} e ON (e.customint1 = pe.courseid AND e.enrol = 'meta' AND e.status = :enrolstatus $onecourse)
310
              JOIN {enrol} e ON (e.customint1 = pe.courseid AND e.enrol = 'meta' AND e.status = :enrolstatus $onecourse)
311
              JOIN {user} u ON (u.id = pue.userid AND u.deleted = 0)
311
              JOIN {user} u ON (u.id = pue.userid AND u.deleted = 0)
Línea 339... Línea 339...
339
 
339
 
340
        // So now we have aggregated values that we will use for the meta enrolment status, timeend and timestart.
340
        // So now we have aggregated values that we will use for the meta enrolment status, timeend and timestart.
341
        // Again, we use the fact that active=0 and disabled/suspended=1. Only when MIN(pue.status + pe.status)=0 the enrolment is active:
341
        // Again, we use the fact that active=0 and disabled/suspended=1. Only when MIN(pue.status + pe.status)=0 the enrolment is active:
342
        $ue->status = ($ue->status == ENROL_USER_ACTIVE + ENROL_INSTANCE_ENABLED) ? ENROL_USER_ACTIVE : ENROL_USER_SUSPENDED;
342
        $ue->status = ($ue->status == ENROL_USER_ACTIVE + ENROL_INSTANCE_ENABLED) ? ENROL_USER_ACTIVE : ENROL_USER_SUSPENDED;
343
        // Timeend 9999999999 was used instead of 0 in the "MAX()" function:
343
        // Timeend 9999999999 was used instead of 0 in the "MAX()" function:
344
        $ue->timeend = ($ue->timeend == 9999999999) ? 0 : (int)$ue->timeend;
344
        $ue->timeend = ($ue->timeend == SQL_INT_MAX) ? 0 : (int)$ue->timeend;
345
        // Timestart 9999999999 is only possible when there are no active enrolments:
345
        // Timestart 9999999999 is only possible when there are no active enrolments:
Línea 346... Línea 346...
346
        $ue->timestart = ($ue->timestart == 9999999999) ? 0 : (int)$ue->timestart;
346
        $ue->timestart = ($ue->timestart == SQL_INT_MAX) ? 0 : (int)$ue->timestart;
347
 
347
 
348
        $meta->enrol_user($instance, $ue->userid, null, $ue->timestart, $ue->timeend, $ue->status);
348
        $meta->enrol_user($instance, $ue->userid, null, $ue->timestart, $ue->timeend, $ue->status);
349
        if ($instance->customint2 && $group = $DB->get_record('groups', ['id' => $instance->customint2])) {
349
        if ($instance->customint2 && $group = $DB->get_record('groups', ['id' => $instance->customint2])) {
Línea 416... Línea 416...
416
    //
416
    //
417
    // The last two case statements in the HAVING clause are designed to ignore any inactive child records when calculating
417
    // The last two case statements in the HAVING clause are designed to ignore any inactive child records when calculating
418
    // the start and end time.
418
    // the start and end time.
419
    $sql = "SELECT ue.userid, ue.enrolid,
419
    $sql = "SELECT ue.userid, ue.enrolid,
420
                   MIN(xpue.status + xpe.status) AS pstatus,
420
                   MIN(xpue.status + xpe.status) AS pstatus,
421
                   MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE 9999999999 END) AS ptimestart,
421
                   MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE " . SQL_INT_MAX . " END) AS ptimestart,
422
                   MAX(CASE WHEN (xpue.status + xpe.status = 0) THEN
422
                   MAX(CASE WHEN (xpue.status + xpe.status = 0) THEN
423
                                 (CASE WHEN xpue.timeend = 0 THEN 9999999999 ELSE xpue.timeend END)
423
                                 (CASE WHEN xpue.timeend = 0 THEN " . SQL_INT_MAX . " ELSE xpue.timeend END)
424
                            ELSE 0 END) AS ptimeend
424
                            ELSE 0 END) AS ptimeend
425
              FROM {user_enrolments} ue
425
              FROM {user_enrolments} ue
426
              JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'meta' $onecourse)
426
              JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'meta' $onecourse)
427
              JOIN {user_enrolments} xpue ON (xpue.userid = ue.userid)
427
              JOIN {user_enrolments} xpue ON (xpue.userid = ue.userid)
428
              JOIN {enrol} xpe ON (xpe.id = xpue.enrolid AND xpe.enrol <> 'meta'
428
              JOIN {enrol} xpe ON (xpe.id = xpue.enrolid AND xpe.enrol <> 'meta'
429
                   AND xpe.enrol $enabled AND xpe.courseid = e.customint1)
429
                   AND xpe.enrol $enabled AND xpe.courseid = e.customint1)
430
          GROUP BY ue.userid, ue.enrolid
430
          GROUP BY ue.userid, ue.enrolid
431
            HAVING (MIN(xpue.status + xpe.status) = 0 AND MIN(ue.status) > 0)
431
            HAVING (MIN(xpue.status + xpe.status) = 0 AND MIN(ue.status) > 0)
432
                   OR (MIN(xpue.status + xpe.status) > 0 AND MIN(ue.status) = 0)
432
                   OR (MIN(xpue.status + xpe.status) > 0 AND MIN(ue.status) = 0)
433
                   OR ((CASE WHEN
433
                   OR ((CASE WHEN
434
                                  MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE 9999999999 END) = 9999999999
434
                            MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE " . SQL_INT_MAX . " END) = " .
-
 
435
                                SQL_INT_MAX . "
435
                             THEN 0
436
                        THEN 0
436
                             ELSE
437
                        ELSE
437
                                  MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE 9999999999 END)
438
                            MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE " . SQL_INT_MAX . " END)
438
                              END) <> MIN(ue.timestart))
439
                        END) <> MIN(ue.timestart))
439
                   OR ((CASE
440
                   OR ((CASE
440
                         WHEN MAX(CASE WHEN (xpue.status + xpe.status = 0)
441
                         WHEN MAX(CASE WHEN (xpue.status + xpe.status = 0)
441
                                       THEN (CASE WHEN xpue.timeend = 0 THEN 9999999999 ELSE xpue.timeend END)
442
                                       THEN (CASE WHEN xpue.timeend = 0 THEN " . SQL_INT_MAX . " ELSE xpue.timeend END)
442
                                       ELSE 0 END) = 9999999999
443
                                       ELSE 0 END) = " . SQL_INT_MAX . "
443
                         THEN 0 ELSE MAX(CASE WHEN (xpue.status + xpe.status = 0)
444
                         THEN 0 ELSE MAX(CASE WHEN (xpue.status + xpe.status = 0)
444
                                              THEN (CASE WHEN xpue.timeend = 0 THEN 9999999999 ELSE xpue.timeend END)
445
                                              THEN (CASE WHEN xpue.timeend = 0 THEN " . SQL_INT_MAX . " ELSE xpue.timeend END)
445
                                              ELSE 0 END)
446
                                              ELSE 0 END)
446
                          END) <> MAX(ue.timeend))";
447
                          END) <> MAX(ue.timeend))";
447
    $rs = $DB->get_recordset_sql($sql, $params);
448
    $rs = $DB->get_recordset_sql($sql, $params);
448
    foreach($rs as $ue) {
449
    foreach($rs as $ue) {
449
        if (!isset($instances[$ue->enrolid])) {
450
        if (!isset($instances[$ue->enrolid])) {
450
            $instances[$ue->enrolid] = $DB->get_record('enrol', array('id'=>$ue->enrolid));
451
            $instances[$ue->enrolid] = $DB->get_record('enrol', array('id'=>$ue->enrolid));
451
        }
452
        }
452
        $instance = $instances[$ue->enrolid];
453
        $instance = $instances[$ue->enrolid];
453
        $ue->pstatus = ($ue->pstatus == ENROL_USER_ACTIVE + ENROL_INSTANCE_ENABLED) ? ENROL_USER_ACTIVE : ENROL_USER_SUSPENDED;
454
        $ue->pstatus = ($ue->pstatus == ENROL_USER_ACTIVE + ENROL_INSTANCE_ENABLED) ? ENROL_USER_ACTIVE : ENROL_USER_SUSPENDED;
454
        $ue->ptimeend = ($ue->ptimeend == 9999999999) ? 0 : (int)$ue->ptimeend;
455
        $ue->ptimeend = ($ue->ptimeend == SQL_INT_MAX) ? 0 : (int)$ue->ptimeend;
455
        $ue->ptimestart = ($ue->ptimestart == 9999999999) ? 0 : (int)$ue->ptimestart;
456
        $ue->ptimestart = ($ue->ptimestart == SQL_INT_MAX) ? 0 : (int)$ue->ptimestart;
Línea 456... Línea 457...
456
 
457
 
457
        if ($ue->pstatus == ENROL_USER_ACTIVE and (!$ue->ptimeend || $ue->ptimeend > time())
458
        if ($ue->pstatus == ENROL_USER_ACTIVE and (!$ue->ptimeend || $ue->ptimeend > time())
458
                and !$syncall and $unenrolaction != ENROL_EXT_REMOVED_UNENROL) {
459
                and !$syncall and $unenrolaction != ENROL_EXT_REMOVED_UNENROL) {
459
            // this may be slow if very many users are ignored in sync
460
            // this may be slow if very many users are ignored in sync