- Adding two more display formats: Continuous and FAQ

- Fixed bug 818: Adding a new view: Sorted (by creation date or by last modified.
This commit is contained in:
willcast
2003-10-19 03:40:36 +00:00
parent 7069af60aa
commit 767a31c3bc
7 changed files with 211 additions and 57 deletions
+10 -1
View File
@@ -8,8 +8,10 @@ $string['allcategories'] = "All Categories";
$string['allowcomments'] = "Allow comments on entries";
$string['allowduplicatedentries'] = "Duplicated entries allowed";
$string['alphabet'] = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z";
$string['answer'] = "Answer";
$string['areyousuredelete'] = "Are you sure you want to delete this entry?";
$string['areyousuredeletecomment'] = "Are you sure you want to delete this comment?";
$string['ascending'] = "(ascending)";
$string['attachment'] = "Attachment";
$string['back'] = "Back";
$string['casesensitive'] = "This entry is<br>case sensitive";
@@ -29,11 +31,14 @@ $string['definition'] = "Definition";
$string['definitions'] = "Definitions";
$string['deleteentry'] = "Delete entry";
$string['deletingnoneemptycategory'] = "Deleting this category will not delete the entries it contains - they will be marked as uncategorised.";
$string['descending'] = "(descending)";
$string['displayformat'] = "Display format";
$string['displayformatdefault'] = "Simple, dictionary style";
$string['displayformat1'] = "Full without author";
$string['displayformatcontinuous'] = "Continuous without author";
$string['displayformat2'] = "Full with author";
$string['displayformat3'] = "Encyclopedia";
$string['displayformat4'] = "FAQ";
$string['displayformat5'] = "Full without author";
$string['editcategories'] = "Edit categories";
$string['editentry'] = "Edit entry";
$string['editingcomment'] = "Editing comment";
@@ -61,12 +66,16 @@ $string['nocomment'] = "No comment found";
$string['nocomments'] = "(No comments found on this entry)";
$string['noentries'] = "No entries found in this section";
$string['noentry'] = "No entry found.";
$string['question'] = "Question";
$string['searchindefinition'] = "Search definitions too";
$string['secondaryglossary'] = "Secondary glossary";
$string['showspecial'] = "Show 'Special' link";
$string['showalphabet'] = "Show alphabet";
$string['showall'] = "Show 'ALL' link";
$string['special'] = "Special";
$string['sortchronogically'] = "Sort chronologically";
$string['sortbycreation'] = "By creation date";
$string['sortbylastupdate'] = "By last update";
$string['standardview'] = "Browse by alphabet";
$string['studentcanpost'] = "Students can add entries";
$string['usedynalink'] = "Link this glossary with other modules automatically";
+16 -7
View File
@@ -1,10 +1,19 @@
<P ALIGN=CENTER><B>Display format</B></P>
<P>The system has three built-in formats to display entries. You can create your own format if you want.
<p>The default view is quite simple. It looks like a conventional dictionary.
<p>The second view shows the entry in a forum-like format, without the author's data.
<p>And the third one shows the entry also in a forum-like format but with the author's data.
<P>This setting specify the way the entries will be shown within the glossary. The system has two built-in formats: Default and continuous.
<ul>
<il>The default view is simple. It looks like a conventional dictionary. No author. Attachment are shown as links.</il>
<il>Continuous shows the entries one after other without any kind of separation but the editing icons.</il>
</ul>
<p>Also, there are three more display formats:
<ul>
<il>Full with Author: A forum-like display format showing author's data. Attachments are shown as links.</il>
<il>Encyclopedia: Quite like Full with Author but shows the attached images inline.</il>
<il>FAQ: A sort of FAQ. It automatically appends the words QUESTION and ANSWER in the concepto and definition respectivelly.</il>
<il>Full without Author: A forum-like display format that does not show author's data. Attachments are shown as links.</il>
</ul>
<hr>
<p>If you want to create your own format, you should create a .PHP file and give it a number as its name. See into mod/glossary/formats which should be the next number.
<p>Then, create a funcion called <b>glossary_print_entry_by_format($course, $cm, $glossary, $entry)</b> and dump all your creativity.
<p>The last stemp is to insert a new entry in every language pack you use called <b>displayformat[number]</b>, and give it a meaningful description.
<p>If you want to create your own format, you should create a .PHP file and give it a number as its name. See into mod/glossary/formats which should be the next number. Note that numbers 0 and 1 are reserved.
<p>Then, create a function called <b>glossary_print_entry_by_format($course, $cm, $glossary, $entry)</b> and dump all your creativity on it.
<p>The last step is to insert a new entry in every language pack you use called <b>displayformat[number]</b>, and give it a short but meaningful description.
+5
View File
@@ -104,6 +104,11 @@ function glossary_upgrade($oldversion) {
execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries` " .
"ADD `fullmatch` TINYINT(2) UNSIGNED NOT NULL DEFAULT '1' AFTER `casesensitive` ");
}
if ( $oldversion < 2003101800 ) {
execute_sql( "UPDATE `{$CFG->prefix}glossary`" .
" SET displayformat = 5 WHERE displayformat = 1");
}
return true;
}
+92 -12
View File
@@ -10,6 +10,9 @@ define("GLOSSARY_SHOW_NOT_CATEGORISED", -1);
define("GLOSSARY_STANDARD_VIEW", 0);
define("GLOSSARY_CATEGORY_VIEW", 1);
define("GLOSSARY_FORMAT_SIMPLE", 0);
define("GLOSSARY_FORMAT_CONTINUOUS", 1);
function glossary_add_instance($glossary) {
/// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function
@@ -189,7 +192,9 @@ function glossary_print_entry($course, $cm, $glossary, $entry, $currentview="",$
$formatfile = "$CFG->dirroot/mod/glossary/formats/$glossary->displayformat.php";
$functionname = "glossary_print_entry_by_format";
if ( $glossary->displayformat > 0 ) {
$basicformat = ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE or
$glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS);
if ( !$basicformat ) {
if ( file_exists($formatfile) ) {
include_once($formatfile);
if (function_exists($functionname) ) {
@@ -200,10 +205,17 @@ function glossary_print_entry($course, $cm, $glossary, $entry, $currentview="",$
$permissiongranted = 1;
}
if ( $glossary->displayformat > 0 and $permissiongranted ) {
if ( !$basicformat and $permissiongranted ) {
glossary_print_entry_by_format($course, $cm, $glossary, $entry,$currentview,$cat);
} else {
glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview,$cat);
switch ( $glossary->displayformat ) {
case GLOSSARY_FORMAT_SIMPLE:
glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview,$cat);
break;
case GLOSSARY_FORMAT_CONTINUOUS:
glossary_print_entry_continuous($course, $cm, $glossary, $entry,$currentview,$cat);
break;
}
}
}
@@ -228,6 +240,21 @@ function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$curren
echo "</TR>";
}
function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$currentview="",$cat="") {
global $THEME, $USER;
if ($entry) {
if ($entry->attachment) {
$entry->course = $course->id;
echo "<table border=0 align=right><tr><td>";
echo glossary_print_attachments($entry, "html");
echo "</td></tr></table>";
}
echo " $entry->concept ";
echo format_text($entry->definition, $entry->format);
glossary_print_entry_icons($course, $cm, $glossary, $entry, $currentview, $cat);
}
}
function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview="",$cat="") {
global $THEME, $USER;
@@ -679,11 +706,14 @@ function glossary_print_tabbed_table_end() {
echo "</center><p></td></tr></table></center>";
}
function glossary_print_alphabet_menu($cm, $glossary, $l) {
function glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder = "") {
global $CFG, $THEME;
$strselectletter = get_string("selectletter", "glossary");
$strspecial = get_string("special", "glossary");
$strallentries = get_string("allentries", "glossary");
$strselectletter = get_string("selectletter", "glossary");
$strspecial = get_string("special", "glossary");
$strallentries = get_string("allentries", "glossary");
$strsort = get_string("sortchronogically", "glossary");
$strsortbycreation = get_string("sortbycreation", "glossary");
$strsortbylastupdate = get_string("sortbylastupdate", "glossary");
if ($glossary->showalphabet) {
$output .= get_string("explainalphabet","glossary").'<br />';
@@ -695,7 +725,7 @@ global $CFG, $THEME;
if ( $l == "SPECIAL" ) {
echo "<b>$strspecial</b> | ";
} else {
$strexplainspecial = get_string("explainspecial","glossary");
$strexplainspecial = strip_tags(get_string("explainspecial","glossary"));
echo "<a title=\"$strexplainspecial\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL\">$strspecial</a> | ";
}
}
@@ -704,7 +734,7 @@ global $CFG, $THEME;
$alphabet = explode("|", get_string("alphabet","glossary"));
$letters_by_line = 14;
for ($i = 0; $i < count($alphabet); $i++) {
if ( $l == $alphabet[$i] ) {
if ( $l == $alphabet[$i] and $l) {
echo "<b>$alphabet[$i]</b>";
} else {
echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=$alphabet[$i]\">$alphabet[$i]</a>";
@@ -719,12 +749,62 @@ global $CFG, $THEME;
if ( $glossary->showall ) {
if ( $l == "ALL" ) {
echo "<b>$strallentries</b></p>";
echo "<b>$strallentries</b>";
} else {
$strexplainall = get_string("explainall","glossary");
echo "<a title=\"$strexplainall\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries</a></p>";
$strexplainall = strip_tags(get_string("explainall","glossary"));
echo "<a title=\"$strexplainall\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries</a>";
}
}
$neworder = "";
if ( $sortorder ) {
if ( $sortorder == "asc" ) {
$neworder = "&sortorder=desc";
$ordertitle = get_string("descending","glossary");
} else {
$neworder = "&sortorder=asc";
$ordertitle = get_string("ascending","glossary");
}
$icon = " <img src=\"$sortorder.gif\" border=0 width=16 height=16>";
} else {
if ( $sortkey != "CREATION" and $sortkey != "UPDATE" ) {
$icon = "";
$ordertitle = get_string("ascending","glossary");
} else {
$ordertitle = get_string("descending","glossary");
$neworder = "&sortorder=desc";
$icon = " <img src=\"asc.gif\" border=0 width=16 height=16>";
}
}
$cicon = "";
$cneworder = "";
$cbtag = "";
$cendbtag = "";
$uicon = "";
$uneworder = "";
$ubtag = "";
$uendbtag = "";
if ( $sortkey == "CREATION" ) {
$cicon = $icon;
$cneworder = $neworder;
$cordertitle = $ordertitle;
$uordertitle = get_string("ascending","glossary");
$cbtag = "<b>";
$cendbtag = "</b>";
} elseif ($sortkey == "UPDATE") {
$uicon = $icon;
$uneworder = $neworder;
$cordertitle = get_string("ascending","glossary");
$uordertitle = $ordertitle;
$ubtag = "<b>";
$uendbtag = "</b>";
} else {
$cordertitle = get_string("ascending","glossary");
$uordertitle = get_string("ascending","glossary");
}
echo "<br>$strsort: $ubtag<a title=\"$strsortbylastupdate $uordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=UPDATE$uneworder\">$strsortbylastupdate$uicon</a>$uendbtag | ".
"$cbtag<a title=\"$strsortbycreation $cordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=CREATION$cneworder\">$strsortbycreation$cicon</a>$cendbtag</p>";
}
function glossary_print_categories_menu($course, $cm, $glossary, $cat, $category) {
global $CFG, $THEME;
+17 -12
View File
@@ -144,6 +144,11 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) {
echo "selected";
}
?>><?php echo get_string("displayformatdefault", "glossary") ?></option>
<option value="1" <?php
if ( $form->displayformat == 1) {
echo "selected";
}
?>><?php echo get_string("displayformatcontinuous", "glossary") ?></option>
<?php
global $CFG;
@@ -157,19 +162,19 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) {
if (filetype("$CFG->dirroot/mod/glossary/formats/$dir") == "dir") {
continue;
}
if ( $pos = strpos($dir, ".") ) {
$dir = substr($dir, 0, $pos );
echo "<option value=\"$dir\" ";
if ( $form->displayformat == $dir) {
echo "selected ";
}
echo ">";
echo get_string("displayformat$dir", "glossary")."</option>";
}
if ( $pos = strpos($dir, ".") ) {
$dir = substr($dir, 0, $pos );
if ($dir != 0 and $dir != 1) { // excluding basic formats
echo "<option value=\"$dir\" ";
if ( $form->displayformat == $dir) {
echo "selected ";
}
echo ">";
echo get_string("displayformat$dir", "glossary")."</option>";
}
}
}
?>
</select> <?php helpbutton("displayformat", get_string("displayformat", "glossary"), "glossary") ?>
+1 -1
View File
@@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
$module->version = 2003101601; // The current module version (Date: YYYYMMDDXX)
$module->version = 2003101800; // The current module version (Date: YYYYMMDDXX)
$module->cron = 0; // Period for cron to check this module (secs)
$release = "0.5 development"; // User-friendly version number
+70 -24
View File
@@ -5,14 +5,17 @@
require_once("lib.php");
require_variable($id); // Course Module ID
optional_variable($l); // letter to look for
optional_variable($l,""); // letter to look for
optional_variable($eid); // Entry ID
optional_variable($search, ""); // search string
optional_variable($includedefinition); // include definition in search function?
optional_variable($currentview); // browsing entries by categories?
optional_variable($currentview,""); // browsing entries by categories?
optional_variable($cat); // categoryID
optional_variable($sortkey,""); // Sorted view: CREATION or UPDATE
optional_variable($sortorder,""); // it define the order of the sorting (ASC or DESC)
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
@@ -33,6 +36,17 @@
add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id");
if ( $sortorder ) {
$sortorder = strtolower($sortorder);
if ($sortorder != "asc" and $sortorder != "desc") {
$sortorder = "";
}
}
if ( $sortorder ) {
$l = "";
$search ="";
}
$search = trim(strip_tags($search));
if ($search and !$entryid) {
$l = "";
@@ -49,7 +63,7 @@
}
$alphabet = explode("|", get_string("alphabet","glossary"));
if ($l == "" and $search == "" and ($eid == "" or $eid == 0)) {
if ($l == "" and $search == "" and $sortkey == "" and ($eid == "" or $eid == 0)) {
$l = $alphabet[0];
} elseif ($eid) {
$l = "";
@@ -94,7 +108,7 @@
if ( $glossary->intro ) {
print_simple_box_start("center","70%");
echo '<p>';
echo '<p align="center">';
echo $glossary->intro;
echo '</p>';
print_simple_box_end();
@@ -155,8 +169,8 @@
$currentcategory = "";
} else {
glossary_print_alphabet_menu($cm, $glossary, $l);
if ($l) {
glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder);
if ($l or $sortkey) {
$currentletter = "";
} elseif ($search) {
echo "<h3>$strsearch: $search</h3>";
@@ -177,12 +191,32 @@
{$CFG->prefix}glossary_categories gc
WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND
gec.entryid = ge.id AND
gc.id = gec.categoryid
ORDER BY gc.name, ge.concept";
gc.id = gec.categoryid ";
if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
$sql .= "ORDER BY gc.name, ge.timecreated";
} else {
$sql .= "ORDER BY gc.name, ge.concept";
}
$allentries = get_records_sql($sql);
} else { // looking for terms that begin with a specify letter or entries with no category associated
$ownentries = get_records("glossary_entries", "glossaryid", $glossary->id, "concept ASC");
$importedentries = get_records("glossary_entries", "sourceglossaryid", $glossary->id, "concept ASC");
if ( $sortkey == "CREATION" or $sortkey == "UPDATE" or $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
if ( !$sortkey and $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
$sortkey = "CREATION";
$sortorder = "asc";
}
if ( !$sortorder ) {
$sortorder = "asc";
}
if ($sortkey == "CREATION") {
$orderby = "timecreated $sortorder";
} else {
$orderby = "timemodified $sortorder";
}
} else {
$orderby = "concept ASC";
}
$ownentries = get_records("glossary_entries", "glossaryid", $glossary->id, $orderby);
$importedentries = get_records("glossary_entries", "sourceglossaryid", $glossary->id, $orderby);
if ($ownentries and $importedentries) {
$allentries = array_merge($ownentries, $importedentries);
@@ -195,29 +229,32 @@
}
if ($allentries) {
if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
echo "<table border=0 cellspacing=0 width=95% valign=top cellpadding=5><tr><td align=left bgcolor=\"#FFFFFF\">";
}
$dumpeddefinitions = 0;
foreach ($allentries as $entry) {
$dumptoscreen = 0;
$firstletter = strtoupper(substr(ltrim($entry->concept), 0, strlen($l)));
if ($l) {
if ($l == "ALL" or $firstletter == $l) {
if ($l == "ALL" or $sortkey == "CREATION" or $sortkey == "UPDATE" or $firstletter == $l) {
if ($currentletter != $firstletter[0]) {
$currentletter = $firstletter[0];
if ($glossary->displayformat == 0) {
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
if ($dumpeddefinitions > 0) {
echo "</table></center><p>";
}
echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=10><tr><td align=center bgcolor=\"$THEME->cellheading2\">";
}
if ($l == "ALL") {
echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=5><tr><td align=center bgcolor=\"$THEME->cellheading2\">";
}
if ($l == "ALL" and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
echo "<b>$currentletter</b>";
}
if ($glossary->displayformat == 0) {
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
echo "\n</center></td></tr></table></center>";
if ($dumpeddefinitions > 0) {
echo "\n<center><table border=1 cellspacing=0 width=95% valign=top cellpadding=10>";
echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=5>";
}
}
}
@@ -240,16 +277,22 @@
} else { // All categories
if ($currentcategory != $entry->CID) {
$currentcategory = $entry->CID;
if ($glossary->displayformat == 0) {
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
if ($dumpeddefinitions > 0) {
echo "</table></center><p>";
}
echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=10><tr><td align=center bgcolor=\"$THEME->cellheading2\">";
}
if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
echo "<center>";
}
echo "<b>$entry->name</b>";
if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
echo "</center><p>";
}
}
if ($glossary->displayformat == 0) {
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
echo "\n</center></td></tr></table></center>";
if ($dumpeddefinitions > 0) {
echo "\n<center><table border=1 cellspacing=0 width=95% valign=top cellpadding=10>";
@@ -271,7 +314,7 @@
$definition = $entry->definition;
if ($dumpeddefinitions == 1) {
if ($glossary->displayformat == 0) {
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
echo "\n<center><table border=1 cellspacing=0 width=95% valign=top cellpadding=10>";
}
}
@@ -282,14 +325,14 @@
glossary_print_entry($course, $cm, $glossary, $entry, $currentview, $cat);
if ($glossary->displayformat != 0) {
if ($glossary->displayformat != GLOSSARY_FORMAT_SIMPLE) {
echo "<p>";
}
}
}
}
if (! $dumpeddefinitions) {
print_simple_box_start("center", "70%", "$THEME->cellheading");
print_simple_box_start("center", "70%", "$THEME->cellheading2");
if (!$search) {
echo "<center>$strnoentries</center>";
} else {
@@ -299,7 +342,10 @@
}
print_simple_box_end();
} else {
if ($glossary->displayformat == 0) {
if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
echo "</td></tr></table>";
}
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
echo "\n</table></center>";
}
}