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

Refactoring so that 3rd-party plugins will have a default task string

Bug 1259538

Change-Id: Ifb09d2b9f9c9d4fbe3ef461c0bb12e81624c2138
parent 592ec736
......@@ -106,7 +106,7 @@ class PluginArtefactBlog extends PluginArtefact {
);
}
public static function progressbar_link() {
public static function progressbar_link($artefacttype) {
return 'artefact/blog/view/index.php';
}
}
......
......@@ -81,20 +81,10 @@ abstract class PluginArtefact extends Plugin {
return array();
}
/**
* Returns the relative URL path to the place in mahara that relates
* to the artefact.
* E.g. For plan artefact the link will be 'artefact/plans/index.php'
* @return string Url path to artefact.
*/
public static function progressbar_link() {
return '';
}
/**
* When filtering searches, some artefact types are classified the same way
* even when they come from different artefact plugins. This function allows
* artefact plugins to declare which search filter content type each of their
* artefact plugins to declare which search filter content type each of their
* artefact types belong to.
* @return array of artefacttype => array of filter content types
*/
......@@ -113,6 +103,34 @@ abstract class PluginArtefact extends Plugin {
return true;
}
/**
* Returns the relative URL path to the place in mahara that relates
* to the artefact.
* E.g. For plan artefact the link will be 'artefact/plans/index.php'
* @param int The name of the artefact type (in case different ones need different links)
* @return string Url path to artefact.
*/
public static function progressbar_link($artefacttype) {
return '';
}
public static function progressbar_task_label($artefacttype, $target, $completed) {
// By default we check to see if they provided a string called "progress_{$artefacttype}"
// in the plugin lang file (which takes one param with the count remaining)
$label = get_string('progress_' . $artefacttype, 'artefact.' . static::get_plugin_name(), ($target - $completed));
// Kind of a hack: if get_string() gave us a result indicating the string could not be found,
// try to construct one using the plugin and artefact name.
if (substr($label, 0, 2) == '[[') {
$artname = get_string($artefacttype, 'artefact.' . static::get_plugin_name());
if (substr($artname, 0, 2) == '[[') {
$artname = $artefacttype;
}
$label = get_string('progressbargenerictask', 'mahara', ($target - $completed), $artname);
}
return $label;
}
/**
* Add any special progress items that may not exist as an artefact type.
* @return array of objects each containing name, title, plugin, active, iscountable
......
......@@ -49,7 +49,7 @@ class PluginArtefactPlans extends PluginArtefact {
);
}
public static function progressbar_link() {
public static function progressbar_link($artefacttype) {
return 'artefact/plans/index.php';
}
}
......
......@@ -194,7 +194,11 @@ $string['views'] = 'Pages';
$string['profilecompleteness'] = 'Profile completion';
$string['profilecompletenesspreview'] = 'Profile completion preview';
$string['profilecompletenesstips'] = 'Profile completion tips';
$string['for'] = 'for';
$string['progressbargenerictask'] = array(
0 => 'Add one: %2$s',
1 => 'Add %d: %s'
);
$string['profilecompletionforwhichinstitution'] = 'for';
// Online users sideblock strings
$string['onlineusers'] = 'Online users';
......
......@@ -2875,7 +2875,23 @@ function tags_sideblock() {
return null;
}
/**
* Get the string to display for a given progress bar item (in the sideblock).
* eg: Upload 2 files
* @param string $pluginname
* @param string $artefacttype
* @param int $target How many items need to be created
* @param int $completed How many items have been created
*/
function progressbar_artefact_task_label($pluginname, $artefacttype, $target, $completed) {
return call_user_func(generate_class_name('artefact', $pluginname) . '::progressbar_task_label', $artefacttype, $target, $completed);
}
/**
* Get the link to link on a given progress bar item (in the sideblock)
* @param string $pluginname
* @param string $artefacttype
*/
function progressbar_artefact_link($pluginname, $artefacttype) {
return call_user_func(generate_class_name('artefact', $pluginname) . '::progressbar_link', $artefacttype);
}
......@@ -2958,14 +2974,15 @@ function progressbar_sideblock($preview=false) {
$parts = explode('_', $itemname);
$pluginname = $parts[1];
$artefactname = $parts[2];
$remaining = $counting[$itemname]->value;
$target = $c->value;
$completed = 0;
$data[$itemname] = array(
'artefact' => $artefactname,
'link' => progressbar_artefact_link($pluginname, $artefactname),
'counting' => $c->value,
'completed' => 0,
'counting' => $target,
'completed' => $completed,
'display' => ((bool) $c->value),
'label' => get_string('progress_' . $artefactname, 'artefact.' . $pluginname, $remaining),
'label' => progressbar_artefact_task_label($pluginname, $artefactname, $target, $completed),
);
}
......
......@@ -13,7 +13,7 @@
<form class="pieform" name="progresssidebarselect" method="post" action="" id="progresssidebarselect">
<table cellspacing="0"><tbody>
<tr id="progresssidebarselect_institution_container" class="select">
<th><label for="progresssidebarselect_institution">{str tag=for}</label></th>
<th><label for="progresssidebarselect_institution">{str tag=profilecompletionforwhichinstitution}</label></th>
<td><select class="select autofocus" id="progresssidebarselect_institution" name="institution" tabindex="1" style="">
{foreach from=$sbdata.institutions key=inst item=displayname}
<option value="{$inst}"{if $inst == $sbdata.institution} selected="selected"{/if}>{$displayname|str_shorten_html:25:true}</option>
......
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