Commit 9697d11a authored by Robert Lyon's avatar Robert Lyon Committed by Cecilia Vela Gurovic
Browse files

Bug 1791544 - creating a way to add sideblock menu items better



getting the sideblock data call to give the menu structure

behatnotneeded

Change-Id: Ic7f6aeacbc0af24b51298f77b0500f8040a54737
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 7479e5d7
...@@ -234,7 +234,7 @@ jQuery(function($) { ...@@ -234,7 +234,7 @@ jQuery(function($) {
}); });
EOF; EOF;
$smarty = smarty(); $smarty = smarty(array(), array(), array(), array('sideblocks' => array(progressbar_sideblock(true))));
setpageicon($smarty, 'icon-university'); setpageicon($smarty, 'icon-university');
$smarty->assign('progressbarform', $form); $smarty->assign('progressbarform', $form);
......
...@@ -209,13 +209,6 @@ $smarty = smarty(array(), array(), array(), array( ...@@ -209,13 +209,6 @@ $smarty = smarty(array(), array(), array(), array(
'tinymceconfig' => ' 'tinymceconfig' => '
image_filebrowser: "editpost_filebrowser", image_filebrowser: "editpost_filebrowser",
', ',
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
)); ));
$smarty->assign('INLINEJAVASCRIPT', $javascript); $smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('form', $form); $smarty->assign('form', $form);
......
...@@ -19,15 +19,7 @@ $fileid = param_integer('file'); ...@@ -19,15 +19,7 @@ $fileid = param_integer('file');
// @todo provide upload form when fileid not set. // @todo provide upload form when fileid not set.
$file = artefact_instance_from_id($fileid); $file = artefact_instance_from_id($fileid);
$smartyconfig = array( $smartyconfig = array('sideblocks' => array(quota_sideblock($file->get('group'))));
'sideblocks' => array(
array(
'name' => ($file->get('group') ? 'groupquota' : 'quota'),
'weight' => -10,
'data' => array(),
),
),
);
if ($group = $file->get('group')) { if ($group = $file->get('group')) {
require_once(get_config('libroot') . 'group.php'); require_once(get_config('libroot') . 'group.php');
......
...@@ -41,13 +41,7 @@ $smarty = smarty( ...@@ -41,13 +41,7 @@ $smarty = smarty(
array(), array(),
array(), array(),
array( array(
'sideblocks' => array( 'sideblocks' => array(quota_sideblock(true))
array(
'name' => 'groupquota',
'weight' => -10,
'data' => array(),
),
),
) )
); );
$smarty->assign('heading', $group->name); $smarty->assign('heading', $group->name);
......
...@@ -23,20 +23,7 @@ safe_require('artefact', 'file'); ...@@ -23,20 +23,7 @@ safe_require('artefact', 'file');
$form = pieform(ArtefactTypeFileBase::files_form(get_config('wwwroot') . 'artefact/file/index.php')); $form = pieform(ArtefactTypeFileBase::files_form(get_config('wwwroot') . 'artefact/file/index.php'));
$js = ArtefactTypeFileBase::files_js(); $js = ArtefactTypeFileBase::files_js();
$smarty = smarty( $smarty = smarty();
array(),
array(),
array(),
array(
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
)
);
setpageicon($smarty, 'icon-file-image-o'); setpageicon($smarty, 'icon-file-image-o');
$smarty->assign('form', $form); $smarty->assign('form', $form);
$smarty->assign('INLINEJAVASCRIPT', $js); $smarty->assign('INLINEJAVASCRIPT', $js);
......
...@@ -318,20 +318,7 @@ function settings_submit_delete(Pieform $form, $values) { ...@@ -318,20 +318,7 @@ function settings_submit_delete(Pieform $form, $values) {
redirect('/artefact/file/profileicons.php'); redirect('/artefact/file/profileicons.php');
} }
$smarty = smarty( $smarty = smarty(array('tablerenderer'));
array('tablerenderer'),
array(),
array(),
array(
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
)
);
setpageicon($smarty, 'icon-id-badge'); setpageicon($smarty, 'icon-id-badge');
$smarty->assign('INLINEJAVASCRIPT', $IJS); $smarty->assign('INLINEJAVASCRIPT', $IJS);
$smarty->assign('uploadform', $uploadform); $smarty->assign('uploadform', $uploadform);
......
...@@ -147,14 +147,7 @@ $othernotesmsg = '<div class="alert alert-info">' . get_string('textusedinothern ...@@ -147,14 +147,7 @@ $othernotesmsg = '<div class="alert alert-info">' . get_string('textusedinothern
$smarty = smarty(array(), array(), array(), array( $smarty = smarty(array(), array(), array(), array(
'tinymceconfig' => ' 'tinymceconfig' => '
image_filebrowser: "editnote_filebrowser", image_filebrowser: "editnote_filebrowser",
', '
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
)); ));
setpageicon($smarty, 'icon-pencil-square-o'); setpageicon($smarty, 'icon-pencil-square-o');
$smarty->assign('INLINEJAVASCRIPT', $javascript); $smarty->assign('INLINEJAVASCRIPT', $javascript);
......
...@@ -13,6 +13,7 @@ define('INTERNAL', true); ...@@ -13,6 +13,7 @@ define('INTERNAL', true);
define('MENUITEM', 'create/resume'); define('MENUITEM', 'create/resume');
define('SECTION_PLUGINTYPE', 'artefact'); define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'resume'); define('SECTION_PLUGINNAME', 'resume');
define('SECTION_PAGE', 'goalsandskills');
define('MENUITEM_SUBPAGE', 'goalsandskills'); define('MENUITEM_SUBPAGE', 'goalsandskills');
require_once(dirname(dirname(dirname(__FILE__))) . '/init.php'); require_once(dirname(dirname(dirname(__FILE__))) . '/init.php');
...@@ -130,13 +131,6 @@ $smarty = smarty(array(), array(), array(), array( ...@@ -130,13 +131,6 @@ $smarty = smarty(array(), array(), array(), array(
'tinymceconfig' => ' 'tinymceconfig' => '
image_filebrowser: "editgoalsandskills_filebrowser", image_filebrowser: "editgoalsandskills_filebrowser",
', ',
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
)); ));
$smarty->assign('INLINEJAVASCRIPT', $javascript); $smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items()); $smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
......
...@@ -158,3 +158,4 @@ $string['updatesitetimezone'] = 'The time zone for the site now needs to be set ...@@ -158,3 +158,4 @@ $string['updatesitetimezone'] = 'The time zone for the site now needs to be set
$string['pluginnotactive1'] = 'The plugin "%s" is not enabled. Please got to "Administration" → "Extensions" → "Plugin administration" to enable it.'; $string['pluginnotactive1'] = 'The plugin "%s" is not enabled. Please got to "Administration" → "Extensions" → "Plugin administration" to enable it.';
$string['fileuploadtoobig'] = 'The file upload is too big as it is bigger than "%s"'; $string['fileuploadtoobig'] = 'The file upload is too big as it is bigger than "%s"';
$string['sideblockmenuclash'] = 'Sideblock name "%s" is already in use. Please rename one of them';
...@@ -1274,10 +1274,12 @@ function pieform_element_filebrowser_update(Pieform $form, $element, $data) { ...@@ -1274,10 +1274,12 @@ function pieform_element_filebrowser_update(Pieform $form, $element, $data) {
); );
if ($updatetags && $form->submitted_by_js()) { if ($updatetags && $form->submitted_by_js()) {
$smarty = smarty_core();
$tagdata = tags_sideblock(); $tagdata = tags_sideblock();
$smarty->assign('sbdata', $tagdata); if ($tagdata) {
$returndata['tagblockhtml'] = $smarty->fetch('sideblocks/tags.tpl'); $smarty = smarty_core();
$smarty->assign('sbdata', $tagdata['data']);
$returndata['tagblockhtml'] = $smarty->fetch($tagdata['template']);
}
} }
return $returndata; return $returndata;
......
...@@ -3870,7 +3870,17 @@ function profile_sideblock() { ...@@ -3870,7 +3870,17 @@ function profile_sideblock() {
} }
} }
} }
return $data;
$sideblock = array(
'name' => 'profile',
'weight' => -20,
'id' => 'sb-profile',
'data' => $data,
'class' => 'user-panel',
'template' => 'sideblocks/profile.tpl',
'visible' => $USER->is_logged_in() && !in_admin_section(),
);
return $sideblock;
} }
/** /**
...@@ -3904,15 +3914,12 @@ function onlineusers_sideblock() { ...@@ -3904,15 +3914,12 @@ function onlineusers_sideblock() {
} }
} }
} }
if (!get_config('showonlineuserssideblock') || $showusers == 0) {
return null;
}
$maxonlineusers = get_config('onlineuserssideblockmaxusers'); $maxonlineusers = get_config('onlineuserssideblockmaxusers');
switch ($showusers) { switch ($showusers) {
case 0: // show none
return array(
'users' => array(),
'count' => 0,
'lastminutes' => floor(get_config('accessidletimeout') / 60),
);
case 1: // show institution only case 1: // show institution only
$sql = 'SELECT DISTINCT u.* FROM {usr} u JOIN {usr_institution} i ON u.id = i.usr $sql = 'SELECT DISTINCT u.* FROM {usr} u JOIN {usr_institution} i ON u.id = i.usr
WHERE i.institution IN ('.join(',', array_map('db_quote', array_keys($institutions))).') WHERE i.institution IN ('.join(',', array_map('db_quote', array_keys($institutions))).')
...@@ -3939,11 +3946,19 @@ function onlineusers_sideblock() { ...@@ -3939,11 +3946,19 @@ function onlineusers_sideblock() {
else { else {
$onlineusers = array(); $onlineusers = array();
} }
return array(
'users' => $onlineusers, $sideblock = array(
'count' => count($onlineusers), 'name' => 'onlineusers',
'lastminutes' => floor(get_config('accessidletimeout') / 60), 'id' => 'sb-onlineusers',
'weight' => -10,
'data' => array('users' => $onlineusers,
'count' => count($onlineusers),
'lastminutes' => floor(get_config('accessidletimeout') / 60),
),
'template' => 'sideblocks/onlineusers.tpl',
'visible' => $USER->is_logged_in() && !in_admin_section(),
); );
return $sideblock;
} }
function tag_weight($freq) { function tag_weight($freq) {
...@@ -4006,10 +4021,28 @@ function get_my_tags($limit=null, $cloud=true, $sort='freq', $excludeinstitution ...@@ -4006,10 +4021,28 @@ function get_my_tags($limit=null, $cloud=true, $sort='freq', $excludeinstitution
function tags_sideblock() { function tags_sideblock() {
global $USER; global $USER;
$maxtags = $USER->get_account_preference('tagssideblockmaxtags');
$maxtags = is_null($maxtags) ? get_config('tagssideblockmaxtags') : $maxtags; if (get_config('showtagssideblock')) {
if ($tagrecords = get_my_tags($maxtags)) { $maxtags = $USER->get_account_preference('tagssideblockmaxtags');
return array('tags' => $tagrecords); $maxtags = is_null($maxtags) ? get_config('tagssideblockmaxtags') : $maxtags;
$tags = null;
if ($tagrecords = get_my_tags($maxtags)) {
$tags = array('tags' => $tagrecords);
}
$sideblock = array(
'name' => 'tags',
'id' => 'sb-tags',
'weight' => 0,
'data' => $tags,
'template' => 'sideblocks/tags.tpl',
'visible' => $USER->is_logged_in() &&
in_array(MENUITEM, array('profile',
'create/files',
'share/sharedbyme',
'create/views')),
);
return $sideblock;
} }
return null; return null;
} }
...@@ -4038,6 +4071,10 @@ function progressbar_artefact_link($pluginname, $artefacttype) { ...@@ -4038,6 +4071,10 @@ function progressbar_artefact_link($pluginname, $artefacttype) {
function progressbar_sideblock($preview=false) { function progressbar_sideblock($preview=false) {
global $USER; global $USER;
if (!get_config('showprogressbar')) {
return null;
}
// TODO: Remove this URL param from here, and when previewing pass institution // TODO: Remove this URL param from here, and when previewing pass institution
// by function param instead // by function param instead
$institution = param_alphanum('i', null); $institution = param_alphanum('i', null);
...@@ -4124,6 +4161,7 @@ function progressbar_sideblock($preview=false) { ...@@ -4124,6 +4161,7 @@ function progressbar_sideblock($preview=false) {
} }
$onlytheseplugins[$plugin][$item] = $item; $onlytheseplugins[$plugin][$item] = $item;
} }
require_once(get_config('docroot') . 'artefact/lib.php');
$progressbaritems = artefact_get_progressbar_items($onlytheseplugins); $progressbaritems = artefact_get_progressbar_items($onlytheseplugins);
// Get the data link about every item // Get the data link about every item
...@@ -4216,7 +4254,7 @@ function progressbar_sideblock($preview=false) { ...@@ -4216,7 +4254,7 @@ function progressbar_sideblock($preview=false) {
$percent = 100; $percent = 100;
} }
} }
return array( $blockdata = array(
'data' => $data, 'data' => $data,
'percent' => $percent, 'percent' => $percent,
'preview' => $preview, 'preview' => $preview,
...@@ -4230,7 +4268,7 @@ function progressbar_sideblock($preview=false) { ...@@ -4230,7 +4268,7 @@ function progressbar_sideblock($preview=false) {
); );
} }
else if ($multiinstitutionprogress) { else if ($multiinstitutionprogress) {
return array( $blockdata = array(
'data' => null, 'data' => null,
'percent' => 0, 'percent' => 0,
'preview' => $preview, 'preview' => $preview,
...@@ -4243,16 +4281,71 @@ function progressbar_sideblock($preview=false) { ...@@ -4243,16 +4281,71 @@ function progressbar_sideblock($preview=false) {
'totalcounting' => 0, 'totalcounting' => 0,
); );
} }
return array( else {
'data' => null, $blockdata = array(
'percent' => 0, 'data' => null,
'preview' => $preview, 'percent' => 0,
'count' => 1, 'preview' => $preview,
'institutions' => null, 'count' => 1,
'institution' => 'mahara', 'institutions' => null,
'institution' => 'mahara',
);
}
$blockname = $preview ? 'progressbar_preview' : 'progressbar';
$sideblock = array(
'name' => $blockname,
'id' => 'sb-progressbar',
'class' => 'progressbar',
'weight' => -8,
'data' => $blockdata,
'template' => 'sideblocks/progressbar.tpl',
); );
if ($preview) {
// we are calling this via a page's extraconfig so will only exist on that page
// so we can set visibility to true
$sideblock['visible'] = true;
return $sideblock;
}
else if ($USER->get_account_preference('showprogressbar')) {
$sideblock['visible'] = !in_admin_section();
return $sideblock;
}
else {
return null;
}
} }
function quota_sideblock($group = false) {
global $USER;
$visible = false;
if ($USER->is_logged_in() &&
(defined('MENUITEM') && in_array(MENUITEM, array('create/files',
'profileicons'))
||
defined('MENUITEM') && in_array(MENUITEM, array('engage/mygroups',
'create/resume')) &&
defined('MENUITEM_SUBPAGE') && in_array(MENUITEM_SUBPAGE, array('files',
'goalsandskills')) // for places that have arrowbar menu
||
defined('SECTION_PAGE') && in_array(SECTION_PAGE, array('post',
'editnote'))
)
) {
$visible = true;
}
$template = $group ? 'sideblocks/groupquota.tpl' : 'sideblocks/quota.tpl';
$sideblock = array(
'name' => 'quota',
'weight' => -10,
'data' => array(), // worked out by the template
'template' => $template,
'visible' => $visible,
'override' => $group,
);
return $sideblock;
}
/** /**
* Cronjob to recalculate how much quota each user is using and update it as * Cronjob to recalculate how much quota each user is using and update it as
......
...@@ -2253,11 +2253,14 @@ function friends_control_sideblock($returnto='myfriends') { ...@@ -2253,11 +2253,14 @@ function friends_control_sideblock($returnto='myfriends') {
) )
); );
// Make a sideblock to put the friendscontrol block in // Make a sideblock to put the friendscontrol block in
return array( $sideblock = array(
'name' => 'friendscontrol', 'name' => 'friendscontrol',
'weight' => -5, 'weight' => -5,
'data' => array('form' => pieform($form)) 'data' => array('form' => pieform($form)),
'template' => 'sideblocks/friendscontrol.tpl',
'visible' => true,
); );
return $sideblock;
} }
function friendscontrol_submit(Pieform $form, $values) { function friendscontrol_submit(Pieform $form, $values) {
......
...@@ -169,12 +169,45 @@ function smarty($javascript = array(), $headers = array(), $pagestrings = array( ...@@ -169,12 +169,45 @@ function smarty($javascript = array(), $headers = array(), $pagestrings = array(
if (!isset($langselectform)) { if (!isset($langselectform)) {
$langselectform = language_select_form(); $langselectform = language_select_form();
} }
// Now that password element can set headdata we need to call the login form before smarty_core() $sideblock_menu = array();
$isloginblockvisible = !$USER->is_logged_in() && !get_config('siteclosedforupgrade') // Fetch all the core side blocks now to avoid any 'set headdata' before smarty_core() problems
&& get_config('showloginsideblock'); $authgenerateloginform = auth_generate_login_form();
if ($isloginblockvisible) { $isloginblockvisible = !$USER->is_logged_in() && !get_config('siteclosedforupgrade') && get_config('showloginsideblock');
$authgenerateloginform = auth_generate_login_form(); $loginsideblock = array(
'name' => 'login',
'weight' => -10,
'id' => 'sb-loginbox',
'data' => array('loginform' => $authgenerateloginform),
'visible' => $isloginblockvisible,
'template' => 'sideblocks/login.tpl',
'smarty' => array('SHOWLOGINBLOCK' => $isloginblockvisible),
);
sideblock_template($loginsideblock, $sideblock_menu);
sideblock_template(site_menu(), $sideblock_menu);
sideblock_template(tags_sideblock(), $sideblock_menu);
sideblock_template(selfsearch_sideblock(), $sideblock_menu);
sideblock_template(profile_sideblock(), $sideblock_menu);
sideblock_template(onlineusers_sideblock(), $sideblock_menu);
sideblock_template(progressbar_sideblock(), $sideblock_menu);
sideblock_template(ssopeer_sideblock(), $sideblock_menu);
sideblock_template(quota_sideblock(), $sideblock_menu);
if (isset($extraconfig['sideblocks']) && is_array($extraconfig['sideblocks'])) {
foreach ($extraconfig['sideblocks'] as $sideblock) {
sideblock_template($sideblock, $sideblock_menu);
}
}
// local_sideblocks_update allows sites to customise the sideblocks by munging the $sideblock_menu array.
if (function_exists('local_sideblocks_update')) {
local_sideblocks_update($sideblock_menu);
}
// Remove those that are not visible before displaying
foreach ($sideblock_menu as $sbk => $sbv) {
if (empty($sbv['visible'])) {
unset($sideblock_menu[$sbk]);
}
} }
usort($sideblock_menu, "sort_menu_by_weight");
$smarty = smarty_core(); $smarty = smarty_core();
$wwwroot = get_config('wwwroot'); $wwwroot = get_config('wwwroot');
...@@ -804,135 +837,22 @@ EOF; ...@@ -804,135 +837,22 @@ EOF;
} }
} }
// ---------- sideblock stuff ---------- // ---------- sideblock smarty stuff ----------
$sidebars = !isset($extraconfig['sidebars']) || $extraconfig['sidebars'] !== false; $sidebars = !isset($extraconfig['sidebars']) || $extraconfig['sidebars'] !== false;
if ($sidebars && !defined('INSTALLER') && (!defined('MENUITEM') || substr(MENUITEM, 0, 5) != 'admin')) { if ($sidebars && !defined('INSTALLER')) {
if (get_config('installed') && !$adminsection) { foreach ($sideblock_menu as $sideblock) {
$data = site_menu(); if (!empty($sideblock['visible']) && !empty($sideblock['smarty'])) {
if (!empty($data)) { foreach ($sideblock['smarty'] as $ks => $vs) {
$smarty->assign('SITEMENU', site_menu()); $smarty->assign($ks, $vs);
$sideblocks[] = array(
'name' => 'linksandresources',
'weight' => 10,
'data' => $data,
);
}
}
if ($USER->is_logged_in() && defined('MENUITEM') &&
(
substr(MENUITEM, 0, 7) == 'profile' ||
in_array(substr(MENUITEM, 0, 7), array('create/', 'engage/', 'manage/'))
)) {
if (get_config('showselfsearchsideblock')) {
$sideblocks[] = array(
'name' => 'selfsearch',
'weight' => 0,
'data' => array(),
);
}
if (get_config('showtagssideblock')) {
$sideblocks[] = array(
'name' => 'tags',
'id' => 'sb-tags',
'weight' => 0,
'data' => tags_sideblock(),
);
}
}
if ($USER->is_logged_in() && !$adminsection) {
$sideblocks[] = array(
'name' => 'profile',
'id' => 'sb-profile',
'class' => 'user-panel',
'weight' => -20,
'data' => profile_sideblock()
);
$showusers = 2;