Commit b6e51195 authored by Aaron Wells's avatar Aaron Wells
Browse files

Refactor progress bar meta-artefact stuff a little bit

Bug 1259538

Change-Id: I22cc9e1f1b996cea41bd0811ebaa807d630e87e2
parent 486b6c9d
......@@ -296,27 +296,25 @@ class PluginArtefactInternal extends PluginArtefact {
return $records;
}
public static function progressbar_metaartefact_count($plugin) {
public static function progressbar_metaartefact_count($name) {
global $USER;
if (!$plugin->is_metaartefact) {
return false;
}
$meta = new StdClass();
$meta->artefacttype = $plugin->name;
$meta->artefacttype = $name;
$meta->completed = 0;
switch ($plugin->name) {
case 'messaging':
// Add messaging group data and
// use user's entered values of individual messaging artefacts
$sql = "SELECT COUNT(*) AS completed FROM {artefact}
WHERE owner = ? AND artefacttype IN
('aimscreenname', 'icqnumber', 'jabberusername',
'msnnumber', 'skypeusername', 'yahoochat')";
$count = get_records_sql_array($sql, array($USER->get('id')));
$meta->completed = $count[0]->completed;
break;
switch ($name) {
case 'messaging':
// Add messaging group data and
// use user's entered values of individual messaging artefacts
$sql = "SELECT COUNT(*) AS completed FROM {artefact}
WHERE owner = ? AND artefacttype IN
('aimscreenname', 'icqnumber', 'jabberusername',
'msnnumber', 'skypeusername', 'yahoochat')";
$count = get_records_sql_array($sql, array($USER->get('id')));
$meta->completed = $count[0]->completed;
break;
default:
return false;
}
return $meta;
}
......
......@@ -160,29 +160,31 @@ abstract class PluginArtefact extends Plugin {
$results = array();
$classname = generate_class_name('artefact', $plugin);
// Check the artefacttypes to see if they have a special metaartefact count
if (method_exists($classname, 'progressbar_metaartefact_count')) {
$names = call_static_method($classname, 'get_artefact_types');
foreach ($names as $name) {
$record = new stdClass();
$record->name = $name;
$record->is_metaartefact = call_static_method('ArtefactType' . ucfirst($name), 'is_metaartefact');
if (is_object($meta = call_user_func($classname . '::progressbar_metaartefact_count', $record))) {
$names = call_static_method($classname, 'get_artefact_types');
foreach ($names as $name) {
$is_metaartefact = call_static_method('ArtefactType' . ucfirst($name), 'is_metaartefact');
if ($is_metaartefact) {
$meta = call_user_func($classname . '::progressbar_metaartefact_count', $name);
if (is_object($meta)) {
array_push($results, $meta);
}
}
// Also check the special artefacts
if (is_array($specials = call_static_method($classname, 'progressbar_additional_items'))) {
foreach ($specials as $special) {
if (empty($special->is_metaartefact)) {
// check to see if it can have mataartefact count
$special->is_metaartefact = call_static_method('ArtefactType' . ucfirst($special->name), 'is_metaartefact');
}
if (!empty($special->is_metaartefact)) {
// Now check if they have a special metaartefact count
if (is_object($meta = call_user_func($classname . '::progressbar_metaartefact_count', $special))) {
array_push($results, $meta);
}
}
// Also check the special artefacts
if (is_array($specials = call_static_method($classname, 'progressbar_additional_items'))) {
foreach ($specials as $special) {
if (empty($special->is_metaartefact)) {
// check to see if it can have mataartefact count
$special->is_metaartefact = call_static_method('ArtefactType' . ucfirst($special->name), 'is_metaartefact');
}
if (!empty($special->is_metaartefact)) {
// Now check if they have a special metaartefact count
$meta = call_user_func($classname . '::progressbar_metaartefact_count', $special->name);
if (is_object($meta)) {
array_push($results, $meta);
}
}
}
......@@ -197,6 +199,17 @@ abstract class PluginArtefact extends Plugin {
public static function progressbar_additional_items() {
return array();
}
/**
* If this plugin provides some progress bar metaartefacts, then this method should
* provide the logic to count them.
* @param string $name The name of the meta-artefact to count
* @return object A record containing the count data to be displayed in the sidebar.
* It should contain the fields "artefacttype" and "completion"
*/
public static function progressbar_metaartefact_count($name) {
return false;
}
}
/**
......
......@@ -48,34 +48,36 @@ class PluginArtefactSocial extends PluginArtefact {
}
}
public static function progressbar_metaartefact_count($plugin) {
public static function progressbar_metaartefact_count($name) {
global $USER;
$meta = new StdClass();
$meta->artefacttype = $plugin->name;
$meta->artefacttype = $name;
$meta->completed = 0;
switch ($plugin->name) {
case 'feedback':
$sql = "SELECT COUNT(*) AS completed
FROM {artefact}
WHERE artefacttype='comment'
AND owner <> ? AND author = ?";
$count = get_records_sql_array($sql, array($USER->get('id'), $USER->get('id')));
$meta->completed = $count[0]->completed;
break;
case 'joingroup':
$sql = "SELECT COUNT(*) AS completed
FROM {group_member}
WHERE member = ?";
$count = get_records_sql_array($sql, array($USER->get('id')));
$meta->completed = $count[0]->completed;
break;
case 'makefriend':
$sql = "SELECT COUNT(*) AS completed
FROM {usr_friend}
WHERE usr1 = ?";
$count = get_records_sql_array($sql, array($USER->get('id')));
$meta->completed = $count[0]->completed;
break;
switch ($name) {
case 'feedback':
$sql = "SELECT COUNT(*) AS completed
FROM {artefact}
WHERE artefacttype='comment'
AND owner <> ? AND author = ?";
$count = get_records_sql_array($sql, array($USER->get('id'), $USER->get('id')));
$meta->completed = $count[0]->completed;
break;
case 'joingroup':
$sql = "SELECT COUNT(*) AS completed
FROM {group_member}
WHERE member = ?";
$count = get_records_sql_array($sql, array($USER->get('id')));
$meta->completed = $count[0]->completed;
break;
case 'makefriend':
$sql = "SELECT COUNT(*) AS completed
FROM {usr_friend}
WHERE usr1 = ?";
$count = get_records_sql_array($sql, array($USER->get('id')));
$meta->completed = $count[0]->completed;
break;
default:
return false;
}
return $meta;
}
......
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