Commit 5b7b2927 authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon
Browse files

Add sortorder for blocktypes in categories

Bug 1236102. Also sorting the "text" and "image" blocks while I'm at it.

Change-Id: I09c3a1bec1ec9a7ddf0b3f1cfca735759dd2bbbe
parent 385afd23
......@@ -22,7 +22,7 @@ class PluginBlocktypeImage extends PluginBlocktype {
}
public static function get_categories() {
return array('shortcut');
return array('shortcut' => 2000);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
......
......@@ -11,6 +11,6 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010090802;
$config->release = '1.0.2';
$config = new stdClass();
$config->version = 2010090803;
$config->release = '1.0.3';
......@@ -2,6 +2,7 @@
<FIELDS>
<FIELD NAME="blocktype" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="category" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="sortorder" TYPE="INT" LENGTH="10" NOTNULL="true" DEFAULT="100000" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="blocktype" />
......
......@@ -20,6 +20,33 @@ interface IPluginBlocktype {
public static function get_description();
/**
* Should be an array of blocktype categories that this block should be included in,
* for determining how it shows up in the page editor's pallette of blocks.
* See the function get_blocktype_categories() in lib/upgrade.php for the full list.
*
* A block can belong to multiple categories.
*
* The special category "shortcut" will make the blocktype show up on the top of the
* block pallette instead of in a category.
*
* Blocktypes can have a sortorder in each category, that determines how they are
* ordered in the category. To give a sortorder, put the category as the array key,
* and the sortorder as the array value, like so:
*
* return array(
* 'shortcut' => 1000,
* 'general' => 500,
* );
*
* If no sortorder is provided, the blocktype's sortorder will default to 100,000.
* Core blocktypes should have sortorders separated by 1,000 to give space for 3rd-party
* blocks in between.
*
* Blocktypess with the same sortorder are sorted by blocktype name.
*
* @return array
*/
public static function get_categories();
public static function render_instance(BlockInstance $instance, $editing=false);
......@@ -49,6 +76,14 @@ interface IPluginBlocktype {
*/
abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
/**
* Default sortorder for a blocktype that has no sortorder defined for a
* particular blocktype category that it's in. See IPluginBlocktype::get_categories()
* for a full explanation of blocktype sortorder.
* @var int
*/
public static $DEFAULT_SORTORDER = 100000;
public static function get_plugintype_name() {
return 'blocktype';
}
......@@ -201,7 +236,7 @@ abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
JOIN {blocktype_installed_category} btic ON btic.blocktype = bti.name
JOIN {blocktype_installed_viewtype} btiv ON btiv.blocktype = bti.name
WHERE btic.category = ? AND bti.active = 1 AND btiv.viewtype = ?
ORDER BY bti.name';
ORDER BY btic.sortorder, bti.name';
if (!$bts = get_records_sql_array($sql, array($category, $view->get('type')))) {
return false;
}
......
......@@ -22,7 +22,7 @@ class PluginBlocktypeText extends SystemBlocktype {
}
public static function get_categories() {
return array('shortcut');
return array('shortcut' => 1000);
}
public static function get_artefacts(BlockInstance $instance) {
......
......@@ -11,6 +11,6 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2014082202;
$config->release = '1.0.2';
$config = new stdClass();
$config->version = 2014082203;
$config->release = '1.0.3';
......@@ -589,7 +589,7 @@ function xmldb_core_upgrade($oldversion=0) {
GROUP BY u.id
HAVING COUNT(a.id) != 1";
$manyblogusers = get_records_sql_array($sql, array());
$manyblogusers = get_records_sql_array($sql, null);
if ($manyblogusers) {
foreach($manyblogusers as $u) {
......@@ -3140,60 +3140,7 @@ function xmldb_core_upgrade($oldversion=0) {
}
if ($oldversion < 2014032600) {
set_config('watchlistnotification_delay', 20);
if (!table_exists(new XMLDBTable('watchlist_queue'))) {
$table = new XMLDBTable('watchlist_queue');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('usr', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('block', XMLDB_TYPE_INTEGER, 10, null, false);
$table->addFieldInfo('view', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('changed_on', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
$table->addKeyInfo('viewfk', XMLDB_KEY_FOREIGN, array('view'), 'view', array('id'));
$table->addKeyInfo('blockfk', XMLDB_KEY_FOREIGN, array('block'), 'block_instance', array('id'));
$table->addKeyInfo('usrfk', XMLDB_KEY_FOREIGN, array('usr'), 'usr', array('id'));
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
create_table($table);
}
// new event type: delete blockinstance
$e = new stdClass();
$e->name = 'deleteblockinstance';
ensure_record_exists('event_type', $e, $e);
// install the core event subscriptions
$subs = array(
array(
'event' => 'blockinstancecommit',
'callfunction' => 'watchlist_record_changes',
),
array(
'event' => 'deleteblockinstance',
'callfunction' => 'watchlist_block_deleted',
),
array(
'event' => 'saveartefact',
'callfunction' => 'watchlist_record_changes',
),
array(
'event' => 'saveview',
'callfunction' => 'watchlist_record_changes',
),
);
foreach ($subs as $sub) {
ensure_record_exists('event_subscription', (object)$sub, (object)$sub);
}
// install the cronjobs...
$cron = new stdClass();
$cron->callfunction = 'watchlist_process_notifications';
$cron->minute = '*';
$cron->hour = '*';
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
ensure_record_exists('cron', $cron, $cron);
install_watchlist_notification();
}
if ($oldversion < 2014032700) {
......@@ -3326,42 +3273,28 @@ function xmldb_core_upgrade($oldversion=0) {
// Set all artefacts to the path they'd have if they have no parent.
log_debug('Filling in parent artefact paths');
execute_sql("UPDATE {artefact} SET path = '/' || id WHERE parent IS NULL");
$newcount = count_records_select('artefact', 'path IS NULL');
if ($newcount) {
$childlevel = 0;
do {
$childlevel++;
$lastcount = $newcount;
log_debug("Filling in level-{$childlevel} child artefact paths");
if (is_postgres()) {
execute_sql("
UPDATE {artefact}
SET path = p.path || '/' || {artefact}.id
FROM {artefact} p
WHERE
{artefact}.parent=p.id
AND {artefact}.path IS NULL
AND p.path IS NOT NULL
");
}
else {
execute_sql("
UPDATE
{artefact} a
INNER JOIN {artefact} p
ON a.parent = p.id
SET a.path=p.path || '/' || a.id
WHERE
a.path IS NULL
AND p.path IS NOT NULL
");
log_debug('Filling in child artefact paths');
set_time_limit(300);
$artefacts = get_records_select_menu('artefact', 'parent IS NOT NULL', null, '', 'id, parent');
set_time_limit(30);
if ($artefacts) {
$total = count($artefacts);
$done = 0;
foreach ($artefacts as $artefactid => $parent) {
$path = '/' . implode('/', artefact_get_lineage($artefacts, $artefactid));
$todb = new stdClass();
$todb->id = $artefactid;
$todb->path = $path;
update_record('artefact', $todb);
$done++;
if ($done % 10000 == 0) {
log_debug("Filling in child artefact paths: {$done}/{$total}");
set_time_limit(30);
}
$newcount = count_records_select('artefact', 'path IS NULL');
// There may be some bad records whose paths can't be filled in,
// so stop looping if the count stops going down.
} while ($newcount > 0 && $newcount < $lastcount);
log_debug("Done filling in child artefact paths");
}
log_debug("Filling in child artefact paths: {$done}/{$total}");
}
set_time_limit(300);
}
// Make objectionable independent of view_access page.
......@@ -3955,5 +3888,14 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2015013000) {
// Add a sortorder column to blocktype_installed_category
$table = new XMLDBTable('blocktype_installed_category');
$field = new XMLDBField('sortorder');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, null, null, null, 100000, 'category');
add_field($table, $field);
}
return $status;
}
......@@ -1136,11 +1136,22 @@ function install_blocktype_categories_for_plugin($blocktype) {
db_begin();
delete_records('blocktype_installed_category', 'blocktype', $blocktype);
if ($cats = call_static_method(generate_class_name('blocktype', $blocktype), 'get_categories')) {
foreach ($cats as $cat) {
foreach ($cats as $k=>$v) {
if (is_string($k) && is_int($v)) {
// New block with name => sortorder array.
$cat = $k;
$sortorder = $v;
}
else {
// Legacy block with just categories, no sortorders. Give it the default sortorder.
$cat = $v;
$sortorder = PluginBlocktype::$DEFAULT_SORTORDER;
}
if (in_array($cat, $catsinstalled)) {
insert_record('blocktype_installed_category', (object)array(
'blocktype' => $blocktype,
'category' => $cat
'category' => $cat,
'sortorder' => $sortorder,
));
}
}
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2015012700;
$config->version = 2015013000;
$config->series = '15.04';
$config->release = '15.04dev';
$config->minupgradefrom = 2009022600;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment