Skip to content

Commit

Permalink
MDL-26429 usability: Add course completion icons.
Browse files Browse the repository at this point in the history
This patch adds a method to the course completion criteria classes
which allows them to specify an icon for display in the course
completion report table.

There is a default implementation which simply looks for an icon
in pix/i with a name matching the completion criteria type.
  • Loading branch information
cameorn1730 committed Nov 5, 2015
1 parent 08dc6b0 commit 7062e7c
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 12 deletions.
14 changes: 14 additions & 0 deletions completion/criteria/completion_criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ abstract public function get_type_title();
*/
abstract public function get_details($completion);

/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
global $COMPLETION_CRITERIA_TYPES;

$criteriatype = $COMPLETION_CRITERIA_TYPES[$this->criteriatype];
return new pix_icon('i/'.$criteriatype, $alt, 'moodle', $attributes);
}

/**
* Return criteria status text for display in reports
*
Expand Down
11 changes: 11 additions & 0 deletions completion/criteria/completion_criteria_activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,15 @@ public function get_details($completion) {

return $details;
}

/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('icon', $alt, 'mod_'.$this->module, $attributes);
}
}
11 changes: 11 additions & 0 deletions completion/criteria/completion_criteria_date.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,15 @@ public function get_details($completion) {

return $details;
}

/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('i/calendar', $alt, 'moodle', $attributes);
}
}
11 changes: 11 additions & 0 deletions completion/criteria/completion_criteria_grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,15 @@ public function get_details($completion) {

return $details;
}

/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('i/grades', $alt, 'moodle', $attributes);
}
}
11 changes: 11 additions & 0 deletions completion/criteria/completion_criteria_self.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,15 @@ public function get_details($completion) {

return $details;
}

/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('i/completion_self', $alt, 'moodle', $attributes);
}
}
11 changes: 11 additions & 0 deletions completion/criteria/completion_criteria_unenrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,15 @@ public function get_details($completion) {
$details['status'] = '';
return $details;
}

/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('i/user', $alt, 'moodle', $attributes);
}
}
22 changes: 10 additions & 12 deletions report/completion/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,16 @@
foreach ($criteria as $criterion) {

// Generate icon details
$icon = '';
$iconlink = '';
$icontitle = ''; // Required if $iconlink set
$iconalt = ''; // Required
$iconattributes = array('class' => 'icon');
switch ($criterion->criteriatype) {

case COMPLETION_CRITERIA_TYPE_ACTIVITY:

// Display icon
$icon = $OUTPUT->pix_url('icon', $criterion->module);
$iconlink = $CFG->wwwroot.'/mod/'.$criterion->module.'/view.php?id='.$criterion->moduleinstance;
$icontitle = $modinfo->cms[$criterion->moduleinstance]->get_formatted_name();
$iconattributes['title'] = $modinfo->cms[$criterion->moduleinstance]->get_formatted_name();
$iconalt = get_string('modulename', $criterion->module);
break;

Expand All @@ -478,7 +476,7 @@

// Display icon
$iconlink = $CFG->wwwroot.'/course/view.php?id='.$criterion->courseinstance;
$icontitle = format_string($crs->fullname, true, array('context' => context_course::instance($crs->id, MUST_EXIST)));
$iconattributes['title'] = format_string($crs->fullname, true, array('context' => context_course::instance($crs->id, MUST_EXIST)));
$iconalt = format_string($crs->shortname, true, array('context' => context_course::instance($crs->id)));
break;

Expand All @@ -491,16 +489,16 @@
break;
}

// Create icon alt if not supplied
if (!$iconalt) {
$iconalt = $criterion->get_title();
}

// Print icon and cell
print '<th class="criteriaicon">';

// Create icon if not supplied
if (!$icon) {
$icon = $OUTPUT->pix_url('i/'.$COMPLETION_CRITERIA_TYPES[$criterion->criteriatype]);
}

print ($iconlink ? '<a href="'.$iconlink.'" title="'.$icontitle.'">' : '');
print '<img src="'.$icon.'" class="icon" alt="'.$iconalt.'" '.(!$iconlink ? 'title="'.$iconalt.'"' : '').' />';
print ($iconlink ? '<a href="'.$iconlink.'" title="'.$iconattributes['title'].'">' : '');
print $OUTPUT->render($criterion->get_icon($iconalt, $iconattributes));
print ($iconlink ? '</a>' : '');

print '</th>';
Expand Down

0 comments on commit 7062e7c

Please sign in to comment.