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($) {
});
EOF;
$smarty = smarty();
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(progressbar_sideblock(true))));
setpageicon($smarty, 'icon-university');
$smarty->assign('progressbarform', $form);
......
......@@ -209,13 +209,6 @@ $smarty = smarty(array(), array(), array(), array(
'tinymceconfig' => '
image_filebrowser: "editpost_filebrowser",
',
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('form', $form);
......
......@@ -19,15 +19,7 @@ $fileid = param_integer('file');
// @todo provide upload form when fileid not set.
$file = artefact_instance_from_id($fileid);
$smartyconfig = array(
'sideblocks' => array(
array(
'name' => ($file->get('group') ? 'groupquota' : 'quota'),
'weight' => -10,
'data' => array(),
),
),
);
$smartyconfig = array('sideblocks' => array(quota_sideblock($file->get('group'))));
if ($group = $file->get('group')) {
require_once(get_config('libroot') . 'group.php');
......
......@@ -41,13 +41,7 @@ $smarty = smarty(
array(),
array(),
array(
'sideblocks' => array(
array(
'name' => 'groupquota',
'weight' => -10,
'data' => array(),
),
),
'sideblocks' => array(quota_sideblock(true))
)
);
$smarty->assign('heading', $group->name);
......
......@@ -23,20 +23,7 @@ safe_require('artefact', 'file');
$form = pieform(ArtefactTypeFileBase::files_form(get_config('wwwroot') . 'artefact/file/index.php'));
$js = ArtefactTypeFileBase::files_js();
$smarty = smarty(
array(),
array(),
array(),
array(
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
)
);
$smarty = smarty();
setpageicon($smarty, 'icon-file-image-o');
$smarty->assign('form', $form);
$smarty->assign('INLINEJAVASCRIPT', $js);
......
......@@ -318,20 +318,7 @@ function settings_submit_delete(Pieform $form, $values) {
redirect('/artefact/file/profileicons.php');
}
$smarty = smarty(
array('tablerenderer'),
array(),
array(),
array(
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
)
);
$smarty = smarty(array('tablerenderer'));
setpageicon($smarty, 'icon-id-badge');
$smarty->assign('INLINEJAVASCRIPT', $IJS);
$smarty->assign('uploadform', $uploadform);
......
......@@ -147,14 +147,7 @@ $othernotesmsg = '<div class="alert alert-info">' . get_string('textusedinothern
$smarty = smarty(array(), array(), array(), array(
'tinymceconfig' => '
image_filebrowser: "editnote_filebrowser",
',
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
'
));
setpageicon($smarty, 'icon-pencil-square-o');
$smarty->assign('INLINEJAVASCRIPT', $javascript);
......
......@@ -13,6 +13,7 @@ define('INTERNAL', true);
define('MENUITEM', 'create/resume');
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'resume');
define('SECTION_PAGE', 'goalsandskills');
define('MENUITEM_SUBPAGE', 'goalsandskills');
require_once(dirname(dirname(dirname(__FILE__))) . '/init.php');
......@@ -130,13 +131,6 @@ $smarty = smarty(array(), array(), array(), array(
'tinymceconfig' => '
image_filebrowser: "editgoalsandskills_filebrowser",
',
'sideblocks' => array(
array(
'name' => 'quota',
'weight' => -10,
'data' => array(),
),
),
));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
......
......@@ -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['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) {
);
if ($updatetags && $form->submitted_by_js()) {
$smarty = smarty_core();
$tagdata = tags_sideblock();
$smarty->assign('sbdata', $tagdata);
$returndata['tagblockhtml'] = $smarty->fetch('sideblocks/tags.tpl');
if ($tagdata) {
$smarty = smarty_core();
$smarty->assign('sbdata', $tagdata['data']);
$returndata['tagblockhtml'] = $smarty->fetch($tagdata['template']);
}
}
return $returndata;
......
......@@ -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() {
}
}
}
if (!get_config('showonlineuserssideblock') || $showusers == 0) {
return null;
}
$maxonlineusers = get_config('onlineuserssideblockmaxusers');
switch ($showusers) {
case 0: // show none
return array(
'users' => array(),
'count' => 0,
'lastminutes' => floor(get_config('accessidletimeout') / 60),
);
case 1: // show institution only
$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))).')
......@@ -3939,11 +3946,19 @@ function onlineusers_sideblock() {
else {
$onlineusers = array();
}
return array(
'users' => $onlineusers,
'count' => count($onlineusers),
'lastminutes' => floor(get_config('accessidletimeout') / 60),
$sideblock = array(
'name' => 'onlineusers',
'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) {
......@@ -4006,10 +4021,28 @@ function get_my_tags($limit=null, $cloud=true, $sort='freq', $excludeinstitution
function tags_sideblock() {
global $USER;
$maxtags = $USER->get_account_preference('tagssideblockmaxtags');
$maxtags = is_null($maxtags) ? get_config('tagssideblockmaxtags') : $maxtags;
if ($tagrecords = get_my_tags($maxtags)) {
return array('tags' => $tagrecords);
if (get_config('showtagssideblock')) {
$maxtags = $USER->get_account_preference('tagssideblockmaxtags');
$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;
}
......@@ -4038,6 +4071,10 @@ function progressbar_artefact_link($pluginname, $artefacttype) {
function progressbar_sideblock($preview=false) {
global $USER;
if (!get_config('showprogressbar')) {
return null;
}
// TODO: Remove this URL param from here, and when previewing pass institution
// by function param instead
$institution = param_alphanum('i', null);
......@@ -4124,6 +4161,7 @@ function progressbar_sideblock($preview=false) {
}
$onlytheseplugins[$plugin][$item] = $item;
}
require_once(get_config('docroot') . 'artefact/lib.php');
$progressbaritems = artefact_get_progressbar_items($onlytheseplugins);
// Get the data link about every item
......@@ -4216,7 +4254,7 @@ function progressbar_sideblock($preview=false) {
$percent = 100;
}
}
return array(
$blockdata = array(
'data' => $data,
'percent' => $percent,
'preview' => $preview,
......@@ -4230,7 +4268,7 @@ function progressbar_sideblock($preview=false) {
);
}
else if ($multiinstitutionprogress) {
return array(
$blockdata = array(
'data' => null,
'percent' => 0,
'preview' => $preview,
......@@ -4243,16 +4281,71 @@ function progressbar_sideblock($preview=false) {
'totalcounting' => 0,
);
}
return array(
'data' => null,
'percent' => 0,
'preview' => $preview,
'count' => 1,
'institutions' => null,
'institution' => 'mahara',
else {
$blockdata = array(
'data' => null,
'percent' => 0,
'preview' => $preview,
'count' => 1,
'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
......
......@@ -2253,11 +2253,14 @@ function friends_control_sideblock($returnto='myfriends') {
)
);
// Make a sideblock to put the friendscontrol block in
return array(
'name' => 'friendscontrol',
$sideblock = array(
'name' => 'friendscontrol',
'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) {
......
......@@ -169,12 +169,45 @@ function smarty($javascript = array(), $headers = array(), $pagestrings = array(
if (!isset($langselectform)) {
$langselectform = language_select_form();
}
// Now that password element can set headdata we need to call the login form before smarty_core()
$isloginblockvisible = !$USER->is_logged_in() && !get_config('siteclosedforupgrade')
&& get_config('showloginsideblock');
if ($isloginblockvisible) {
$authgenerateloginform = auth_generate_login_form();
$sideblock_menu = array();
// Fetch all the core side blocks now to avoid any 'set headdata' before smarty_core() problems
$authgenerateloginform = auth_generate_login_form();
$isloginblockvisible = !$USER->is_logged_in() && !get_config('siteclosedforupgrade') && get_config('showloginsideblock');
$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();
$wwwroot = get_config('wwwroot');
......@@ -804,135 +837,22 @@ EOF;
}
}
// ---------- sideblock stuff ----------
// ---------- sideblock smarty stuff ----------
$sidebars = !isset($extraconfig['sidebars']) || $extraconfig['sidebars'] !== false;
if ($sidebars && !defined('INSTALLER') && (!defined('MENUITEM') || substr(MENUITEM, 0, 5) != 'admin')) {
if (get_config('installed') && !$adminsection) {
$data = site_menu();
if (!empty($data)) {
$smarty->assign('SITEMENU', site_menu());
$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;
$institutions = $USER->institutions;
if (!empty($institutions)) {
$showusers = 0;
foreach ($institutions as $i) {
if ($i->showonlineusers == 2) {
$showusers = 2;
break;
}
if ($i->showonlineusers == 1) {
$showusers = 1;
}
if ($sidebars && !defined('INSTALLER')) {
foreach ($sideblock_menu as $sideblock) {
if (!empty($sideblock['visible']) && !empty($sideblock['smarty'])) {
foreach ($sideblock['smarty'] as $ks => $vs) {
$smarty->assign($ks, $vs);
}
}
if (get_config('showonlineuserssideblock') && $showusers > 0) {
$sideblocks[] = array(
'name' => 'onlineusers',
'id' => 'sb-onlineusers',
'weight' => -10,
'data' => onlineusers_sideblock(),
);
}
if (get_config('showprogressbar') && $USER->get_account_preference('showprogressbar')) {
$sideblocks[] = array(
'name' => 'progressbar',
'id' => 'sb-progressbar',
'class' => 'progressbar',
'weight' => -8,
'data' => progressbar_sideblock(),
);
}
}
if ($USER->is_logged_in() && $adminsection && defined('SECTION_PAGE') && SECTION_PAGE == 'progressbar') {
$sideblocks[] = array(
'name' => 'progressbar',
'id' => 'sb-progressbar',
'class' => 'progressbar',
'weight' => -8,
'data' => progressbar_sideblock(true),
);
}
if ($isloginblockvisible) {
$sideblocks[] = array(
'name' => 'login',
'weight' => -10,
'id' => 'sb-loginbox',
'data' => array(
'loginform' => $authgenerateloginform,
),
);
}
$smarty->assign('SHOWLOGINBLOCK', $isloginblockvisible);
if (get_config('enablenetworking')) {
require_once(get_config('docroot') .'api/xmlrpc/lib.php');
if ($USER->is_logged_in() && $ssopeers = get_service_providers($USER->authinstance)) {
$sideblocks[] = array(
'name' => 'ssopeers',
'weight' => 1,
'data' => $ssopeers,
);
}
}
if (isset($extraconfig['sideblocks']) && is_array($extraconfig['sideblocks'])) {
foreach ($extraconfig['sideblocks'] as $sideblock) {
$sideblocks[] = $sideblock;
}
}
// local_sideblocks_update allows sites to customise the sideblocks by munging the $sideblocks array.
if (function_exists('local_sideblocks_update')) {
local_sideblocks_update($sideblocks);
}
usort($sideblocks, "sort_menu_by_weight");
// Place all sideblocks on the right. If this structure is munged
// appropriately, you can put blocks on the left. In future versions of
// Mahara, we'll make it easy to do this.
$sidebars = $sidebars && !empty($sideblocks);
$sideblocks = array('left' => array(), 'right' => $sideblocks);
$sidebars = $sidebars && !empty($sideblock_menu);
$sideblocks = array('left' => array(), 'right' => $sideblock_menu);
$smarty->assign('userauthinstance', $SESSION->get('authinstance'));
$smarty->assign('MNETUSER', $SESSION->get('mnetuser'));
......@@ -1502,6 +1422,38 @@ function jsstrings() {
);
}
function sideblock_template($sideblock, &$sideblock_menu) {
if ($sideblock === null) {
// No side block to add - possibly due to user permissions or config settings so we ignore
return;
}
// If we want to override an already available sideblock, eg quota -> groupqouta
if (!empty($sideblock['override']) && array_key_exists($sideblock['name'], $sideblock_menu)) {
$sideblock_menu[$sideblock['name']] = array_merge($sideblock_menu[$sideblock['name']], $sideblock);
}
// Make sure we don't have 2 sideblocks with same name
if (empty($sideblock['name']) || (array_key_exists($sideblock['name'], $sideblock_menu) && empty($sideblock['override']))) {
throw new MaharaException(get_string('sideblockmenuclash', 'error', $sideblock['name']));
}
// A sideblock menu can contain the following
$defaultsideblock = array(
'name' => null, // Only required option
'title' => '',