/** * Rebuild context paths and depths at ELIS course context level. * * @static * @param bool $force Set to false to include records whose path is null or depth is zero */ protected static function build_paths($force) { global $DB; $contextlevel = \local_eliscore\context\helper::get_level_from_class_name(get_called_class()); if ($force or $DB->record_exists_select('context', "contextlevel = " . $contextlevel . " AND (depth = 0 OR path IS NULL)")) { $emptyclause = $force ? '' : "AND ({context}.path IS NULL OR {context}.depth = 0)"; $base = '/' . SYSCONTEXTID; // Normal top level categories $sql = "UPDATE {context}\n SET depth = 2,\n path = " . $DB->sql_concat("'{$base}/'", 'id') . "\n WHERE contextlevel = " . $contextlevel . "\n AND EXISTS (SELECT 'x'\n FROM {local_elisprogram_crs} ep\n WHERE ep.id = {context}.instanceid)\n {$emptyclause}"; $DB->execute($sql); } }
/** * Rebuild context paths and depths at ELIS User Set context level. * * @static * @param bool $force Set to false to include records whose path is null or depth is zero */ protected static function build_paths($force) { global $DB; $contextlevel = \local_eliscore\context\helper::get_level_from_class_name(get_called_class()); if ($force or $DB->record_exists_select('context', "contextlevel = " . $contextlevel . " AND (depth = 0 OR path IS NULL)")) { if ($force) { $ctxemptyclause = $emptyclause = ''; } else { $ctxemptyclause = "AND (ctx.path IS NULL OR ctx.depth = 0)"; $emptyclause = "AND ({context}.path IS NULL OR {context}.depth = 0)"; } $base = '/' . SYSCONTEXTID; // Normal top level user sets $sql = "UPDATE {context}\n SET depth = 2,\n path = " . $DB->sql_concat("'{$base}/'", 'id') . "\n WHERE contextlevel = " . $contextlevel . "\n AND EXISTS (SELECT 'x'\n FROM {" . \userset::TABLE . "} eu\n WHERE eu.id = {context}.instanceid AND eu.depth = 1)\n {$emptyclause}"; $DB->execute($sql); // Deeper categories - one query per depthlevel $maxdepth = $DB->get_field_sql("SELECT MAX(depth) FROM {" . \userset::TABLE . "}"); for ($n = 2; $n <= $maxdepth; $n++) { $sql = "INSERT INTO {context_temp} (id, path, depth)\n SELECT ctx.id, " . $DB->sql_concat('pctx.path', "'/'", 'ctx.id') . ", pctx.depth+1\n FROM {context} ctx\n JOIN {" . \userset::TABLE . "} eu ON (eu.id = ctx.instanceid AND ctx.contextlevel = " . $contextlevel . " AND eu.depth = {$n})\n JOIN {context} pctx ON (pctx.instanceid = eu.parent AND pctx.contextlevel = " . $contextlevel . ")\n WHERE pctx.path IS NOT NULL AND pctx.depth > 0\n {$ctxemptyclause}"; $trans = $DB->start_delegated_transaction(); $DB->delete_records('context_temp'); $DB->execute($sql); \local_eliscore\context\base::merge_context_temp_table(); $DB->delete_records('context_temp'); $trans->allow_commit(); } } }
/** * Rebuild context paths and depths at ELIS track context level. * * @static * @param bool $force Set to false to include records whose path is null or depth is zero */ protected static function build_paths($force) { global $DB; $contextlevel = \local_eliscore\context\helper::get_level_from_class_name(get_called_class()); if ($force or $DB->record_exists_select('context', "contextlevel = " . $contextlevel . " AND (depth = 0 OR path IS NULL)")) { $ctxemptyclause = $force ? '' : "AND (ctx.path IS NULL OR ctx.depth = 0)"; $parentcontextlevel = \local_eliscore\context\helper::get_level_from_class_name('\\local_elisprogram\\context\\program'); $sql = "INSERT INTO {context_temp} (id, path, depth)\n SELECT ctx.id, " . $DB->sql_concat('pctx.path', "'/'", 'ctx.id') . ", pctx.depth+1\n FROM {context} ctx\n JOIN {local_elisprogram_trk} trk ON (trk.id = ctx.instanceid AND ctx.contextlevel = " . $contextlevel . ")\n JOIN {context} pctx ON (pctx.instanceid = trk.curid AND pctx.contextlevel = " . $parentcontextlevel . ")\n WHERE pctx.path IS NOT NULL AND pctx.depth > 0\n {$ctxemptyclause}"; $trans = $DB->start_delegated_transaction(); $DB->delete_records('context_temp'); $DB->execute($sql); \local_eliscore\context\base::merge_context_temp_table(); $DB->delete_records('context_temp'); $trans->allow_commit(); } }
/** * Rebuild context paths and depths at user context level. * * @static * @param bool $force Set to false to include records whose path is null or depth is zero */ protected static function build_paths($force) { global $DB; $contextlevel = \local_eliscore\context\helper::get_level_from_class_name(get_called_class()); // first update normal users $sql = "UPDATE {context}\n SET depth = 2,\n path = " . $DB->sql_concat("'/" . SYSCONTEXTID . "/'", 'id') . "\n WHERE contextlevel = " . $contextlevel; $DB->execute($sql); }