Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 1103... Línea 1103...
1103
        return $FILTERLIB_PRIVATE->active[$context->id];
1103
        return $FILTERLIB_PRIVATE->active[$context->id];
1104
    }
1104
    }
Línea 1105... Línea 1105...
1105
 
1105
 
Línea -... Línea 1106...
-
 
1106
    $contextids = str_replace('/', ',', trim($context->path, '/'));
-
 
1107
 
-
 
1108
    // Postgres recordset performance is much better with a limit.
1106
    $contextids = str_replace('/', ',', trim($context->path, '/'));
1109
    // This should be much larger than anything needed in practice. The code below checks we don't hit this limit.
-
 
1110
    $maxpossiblerows = 10000;
-
 
1111
    // The key line in the following query is the HAVING clause.
-
 
1112
    // If a filter is disabled at system context, then there is a row with active -9999 and depth 1,
1107
 
1113
    // so the -MIN is always large, and the MAX will be smaller than that and this filter won't be returned.
-
 
1114
    // Otherwise, there will be a bunch of +/-1s at various depths,
1108
    // The following SQL is tricky. It is explained on
1115
    // and this clause verifies there is a +1 that deeper than any -1.
-
 
1116
    $rows = $DB->get_recordset_sql("
-
 
1117
            SELECT active.filter, fc.name, fc.value
1109
    // http://docs.moodle.org/dev/Filter_enable/disable_by_context.
1118
 
1110
    $sql = "SELECT active.filter, fc.name, fc.value
1119
              FROM (
1111
         FROM (SELECT f.filter, MAX(f.sortorder) AS sortorder
1120
                    SELECT fa.filter, MAX(fa.sortorder) AS sortorder
1112
             FROM {filter_active} f
1121
                      FROM {filter_active} fa
1113
             JOIN {context} ctx ON f.contextid = ctx.id
1122
                      JOIN {context} ctx ON fa.contextid = ctx.id
1114
             WHERE ctx.id IN ($contextids)
1123
                     WHERE ctx.id IN ($contextids)
1115
             GROUP BY filter
1124
                  GROUP BY fa.filter
1116
             HAVING MAX(f.active * ctx.depth) > -MIN(f.active * ctx.depth)
1125
                    HAVING MAX(fa.active * ctx.depth) > -MIN(fa.active * ctx.depth)
-
 
1126
                   ) active
1117
         ) active
1127
         LEFT JOIN {filter_config} fc ON fc.filter = active.filter AND fc.contextid = ?
1118
         LEFT JOIN {filter_config} fc ON fc.filter = active.filter AND fc.contextid = $context->id
1128
 
Línea 1119... Línea 1129...
1119
         ORDER BY active.sortorder";
1129
          ORDER BY active.sortorder
1120
    $rs = $DB->get_recordset_sql($sql);
1130
        ", [$context->id], 0, $maxpossiblerows);
-
 
1131
 
1121
 
1132
    // Massage the data into the specified format to return.
-
 
1133
    $filters = [];
1122
    // Massage the data into the specified format to return.
1134
    $rowcount = 0;
1123
    $filters = array();
1135
    foreach ($rows as $row) {
1124
    foreach ($rs as $row) {
1136
        $rowcount += 1;
1125
        if (!isset($filters[$row->filter])) {
1137
        if (!isset($filters[$row->filter])) {
1126
            $filters[$row->filter] = array();
1138
            $filters[$row->filter] = [];
1127
        }
1139
        }
1128
        if (!is_null($row->name)) {
1140
        if (!is_null($row->name)) {
-
 
1141
            $filters[$row->filter][$row->name] = $row->value;
Línea 1129... Línea 1142...
1129
            $filters[$row->filter][$row->name] = $row->value;
1142
        }
-
 
1143
    }
-
 
1144
    $rows->close();
-
 
1145
 
-
 
1146
    if ($rowcount >= $maxpossiblerows) {
Línea 1130... Línea 1147...
1130
        }
1147
        // If this ever did happen, which seems essentially impossible, then it would lead to very subtle and
1131
    }
1148
        // hard to understand bugs, so ensure it leads to an unmissable error.
Línea 1132... Línea 1149...
1132
 
1149
        throw new coding_exception('Hit the row limit that should never be hit in filter_get_active_in_context.');