Skip to content

Commit

Permalink
CONTRIB-2202 Now able to change the colour of the items in the checklist
Browse files Browse the repository at this point in the history
  • Loading branch information
davosmith committed Sep 10, 2010
1 parent e2fe753 commit e5cb97f
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 8 deletions.
2 changes: 1 addition & 1 deletion db/.emacscopyto
@@ -1 +1 @@
/usr/share/moodle/mod/checklist/db/
/home/davo/public_html/moodle198/mod/checklist/db/
3 changes: 2 additions & 1 deletion db/install.xml
Expand Up @@ -39,7 +39,8 @@
<FIELD NAME="indent" TYPE="int" LENGTH="8" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="position" NEXT="itemoptional"/>
<FIELD NAME="itemoptional" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="indent" NEXT="duetime"/>
<FIELD NAME="duetime" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Date/time when this item is due to be completed" PREVIOUS="itemoptional" NEXT="eventid"/>
<FIELD NAME="eventid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="id of the calendar event (if any) associated with this item" PREVIOUS="duetime"/>
<FIELD NAME="eventid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="id of the calendar event (if any) associated with this item" PREVIOUS="duetime" NEXT="colour"/>
<FIELD NAME="colour" TYPE="char" LENGTH="15" NOTNULL="true" DEFAULT="black" SEQUENCE="false" ENUM="false" PREVIOUS="eventid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
9 changes: 9 additions & 0 deletions db/upgrade.php
Expand Up @@ -88,6 +88,15 @@ function xmldb_checklist_upgrade($oldversion=0) {
$table->addIndexInfo('checklist_item_user', XMLDB_INDEX_UNIQUE, array('itemid', 'userid'));
$result = $result && create_table($table);
}

if ($result && $oldversion < 2010091003) {
$table = new XMLDBTable('checklist_item');
$field = new XMLDBField('colour');

$field->setAttributes(XMLDB_TYPE_CHAR, '15', null, XMLDB_NOTNULL, null, null, null, 'black', 'eventid');

$result = $result && add_field($table, $field);
}

return $result;

Expand Down
Binary file added images/colour_black.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/colour_blue.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/colour_green.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/colour_orange.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/colour_purple.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/colour_red.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 83 additions & 5 deletions locallib.php
Expand Up @@ -545,7 +545,24 @@ function view_items($viewother = false, $userreport = false) {
if ($viewother || $userreport) {
$checked .= ' disabled="disabled" ';
}
$optional = $item->itemoptional ? ' class="itemoptional" ' : '';
switch ($item->colour) {
case 'red':
$itemcolour = 'itemred';
break;
case 'orange':
$itemcolour = 'itemorange';
break;
case 'green':
$itemcolour = 'itemgreen';
break;
case 'purple':
$itemcolour = 'itempurple';
break;
default:
$itemcolour = 'itemblack';
}

$optional = $item->itemoptional ? ' class="itemoptional '.$itemcolour.'" ' : 'class="'.$itemcolour.'"';
echo '<li>';
if ($showteachermark) {
if ($viewother) {
Expand Down Expand Up @@ -809,17 +826,39 @@ function view_edit_items() {
$baseurl .= ($this->editdates) ? '&amp;editdates=on' : '';
$baseurl .= '&amp;action=';

switch ($item->colour) {
case 'red':
$itemcolour = 'itemred';
$nexticon = 'colour_orange.gif';
break;
case 'orange':
$itemcolour = 'itemorange';
$nexticon = 'colour_green.gif';
break;
case 'green':
$itemcolour = 'itemgreen';
$nexticon = 'colour_purple.gif';
break;
case 'purple':
$itemcolour = 'itempurple';
$nexticon = 'colour_black.gif';
break;
default:
$itemcolour = 'itemblack';
$nexticon = 'colour_red.gif';
}

echo '<li>';
if ($item->itemoptional) {
$title = '"'.get_string('optionalitem','checklist').'"';
echo '<a href="'.$baseurl.'makerequired">';
echo '<img src="'.$CFG->wwwroot.'/mod/checklist/images/optional.png" alt='.$title.' title='.$title.' /></a>&nbsp;';
$optional = ' class="itemoptional" ';
$optional = ' class="itemoptional '.$itemcolour.'" ';
} else {
$title = '"'.get_string('requireditem','checklist').'"';
echo '<a href="'.$baseurl.'makeoptional">';
echo '<img src="'.$CFG->wwwroot.'/mod/checklist/images/required.png" alt='.$title.' title='.$title.' /></a>&nbsp;';
$optional = '';
$optional = ' class="'.$itemcolour.'"';
}

if (isset($item->editme)) {
Expand All @@ -840,7 +879,9 @@ function view_edit_items() {

echo '<form style="display:inline" action="'.$CFG->wwwroot.'/mod/checklist/edit.php" method="get">';
echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
echo '<input type="hidden" name="editdates" value="on" />';
if ($this->editdates) {
echo '<input type="hidden" name="editdates" value="on" />';
}
if ($this->additemafter) {
echo '<input type="hidden" name="additemafter" value="'.$this->additemafter.'" />';
}
Expand All @@ -849,6 +890,10 @@ function view_edit_items() {
} else {
echo '<label for='.$itemname.$optional.'>'.s($item->displaytext).'</label>&nbsp;';

echo '<a href="'.$baseurl.'nextcolour">';
$title = '"'.get_string('changetextcolour','checklist').'"';
echo '<img src="'.$CFG->wwwroot.'/mod/checklist/images/'.$nexticon.'" alt='.$title.' title='.$title.' /></a>';

echo '<a href="'.$baseurl.'edititem">';
$title = '"'.get_string('edititem','checklist').'"';
echo '<img src="'.$CFG->pixpath.'/t/edit.gif" alt='.$title.' title='.$title.' /></a>&nbsp;';
Expand Down Expand Up @@ -883,7 +928,7 @@ function view_edit_items() {
echo '&nbsp;<a href="'.$baseurl.'deleteitem">';
$title = '"'.get_string('deleteitem','checklist').'"';
echo '<img src="'.$CFG->pixpath.'/t/delete.gif" alt='.$title.' title='.$title.' /></a>';

echo '&nbsp;&nbsp;&nbsp;<a href="'.$baseurl.'startadditem">';
$title = '"'.get_string('additemhere','checklist').'"';
echo '<img src="'.$CFG->wwwroot.'/mod/checklist/images/add.png" alt='.$title.' title='.$title.' /></a>';
Expand Down Expand Up @@ -1383,6 +1428,9 @@ function process_edit_actions() {
case 'makerequired':
$this->makeoptional($itemid, false);
break;
case 'nextcolour':
$this->nextcolour($itemid);
break;
default:
error('Invalid action - "'.s($action).'"');
}
Expand Down Expand Up @@ -1714,8 +1762,38 @@ function makeoptional($itemid, $optional) {
update_record('checklist_item', $upditem);
}

function nextcolour($itemid) {
if (!isset($this->items[$itemid])) {
return;
}

switch ($this->items[$itemid]->colour) {
case 'black':
$nextcolour='red';
break;
case 'red':
$nextcolour='orange';
break;
case 'orange':
$nextcolour='green';
break;
case 'green':
$nextcolour='purple';
break;
default:
$nextcolour='black';
}

$upditem = new stdClass;
$upditem->id = $itemid;
$upditem->colour = $nextcolour;
update_record('checklist_item', $upditem);
$this->items[$itemid]->colour = $nextcolour;
}

function updatechecks() {
$newchecks = optional_param('items', array(), PARAM_INT);

if (!is_array($newchecks)) {
// Something has gone wrong, so update nothing
return;
Expand Down
39 changes: 39 additions & 0 deletions styles.php
Expand Up @@ -17,9 +17,48 @@

ol.checklist .itemoptional {
font-style: italic;
}

ol.checklist .itemblack {
color: #000000;
}

ol.checklist .itemblack.itemoptional {
color: #a0a0a0;
}

ol.checklist .itemred {
color: #ff0000;
}

ol.checklist .itemred.itemoptional {
color: #ffa0a0;
}

ol.checklist .itemorange {
color: #ffba00;
}

ol.checklist .itemorange.itemoptional {
color: #ffdaa0;
}

ol.checklist .itemgreen {
color: #00ff00;
}

ol.checklist .itemgreen.itemoptional {
color: #a0ffa0;
}

ol.checklist .itempurple {
color: #d000ff;
}

ol.checklist .itempurple.itemoptional {
color: #d0a0ff;
}

ol.checklist .teachercomment {
color: black;
background-color: #ffffb0;
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -8,7 +8,7 @@
* @package mod/checklist
*/

$module->version = 2010050100; // The current module version (Date: YYYYMMDDXX)
$module->version = 2010091003; // The current module version (Date: YYYYMMDDXX)
$module->cron = 0; // Period for cron to check this module (secs)

?>

0 comments on commit e5cb97f

Please sign in to comment.