From: willcast Date: Sun, 19 Oct 2003 03:40:36 +0000 (+0000) Subject: - Adding two more display formats: Continuous and FAQ X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=767a31c3bc21adb239e2ac891ea202d1c20c6467;p=moodle.git - Adding two more display formats: Continuous and FAQ - Fixed bug 818: Adding a new view: Sorted (by creation date or by last modified. --- diff --git a/lang/en/glossary.php b/lang/en/glossary.php index d97b5f8694..367260709e 100644 --- a/lang/en/glossary.php +++ b/lang/en/glossary.php @@ -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
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"; diff --git a/lang/en/help/glossary/displayformat.html b/lang/en/help/glossary/displayformat.html index 115d74e26b..ea2a466c25 100644 --- a/lang/en/help/glossary/displayformat.html +++ b/lang/en/help/glossary/displayformat.html @@ -1,10 +1,19 @@

Display format

-

The system has three built-in formats to display entries. You can create your own format if you want. -

The default view is quite simple. It looks like a conventional dictionary. -

The second view shows the entry in a forum-like format, without the author's data. -

And the third one shows the entry also in a forum-like format but with the author's data. +

This setting specify the way the entries will be shown within the glossary. The system has two built-in formats: Default and continuous. +

+

Also, there are three more display formats: +

+
-

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. -

Then, create a funcion called glossary_print_entry_by_format($course, $cm, $glossary, $entry) and dump all your creativity. -

The last stemp is to insert a new entry in every language pack you use called displayformat[number], and give it a meaningful description. +

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. +

Then, create a function called glossary_print_entry_by_format($course, $cm, $glossary, $entry) and dump all your creativity on it. +

The last step is to insert a new entry in every language pack you use called displayformat[number], and give it a short but meaningful description. diff --git a/mod/glossary/db/mysql.php b/mod/glossary/db/mysql.php index 9711921670..d6c414a38f 100644 --- a/mod/glossary/db/mysql.php +++ b/mod/glossary/db/mysql.php @@ -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; } diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 3bceaabba0..e1f286117b 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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 ""; } +function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$currentview="",$cat="") { + global $THEME, $USER; + if ($entry) { + if ($entry->attachment) { + $entry->course = $course->id; + echo "
"; + echo glossary_print_attachments($entry, "html"); + echo "
"; + } + 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 "

"; } -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").'
'; @@ -695,7 +725,7 @@ global $CFG, $THEME; if ( $l == "SPECIAL" ) { echo "$strspecial | "; } else { - $strexplainspecial = get_string("explainspecial","glossary"); + $strexplainspecial = strip_tags(get_string("explainspecial","glossary")); echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL\">$strspecial | "; } } @@ -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 "$alphabet[$i]"; } else { echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=$alphabet[$i]\">$alphabet[$i]"; @@ -719,12 +749,62 @@ global $CFG, $THEME; if ( $glossary->showall ) { if ( $l == "ALL" ) { - echo "$strallentries

"; + echo "$strallentries"; } else { - $strexplainall = get_string("explainall","glossary"); - echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries

"; + $strexplainall = strip_tags(get_string("explainall","glossary")); + echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries"; } } + $neworder = ""; + if ( $sortorder ) { + if ( $sortorder == "asc" ) { + $neworder = "&sortorder=desc"; + $ordertitle = get_string("descending","glossary"); + } else { + $neworder = "&sortorder=asc"; + $ordertitle = get_string("ascending","glossary"); + } + $icon = " "; + } else { + if ( $sortkey != "CREATION" and $sortkey != "UPDATE" ) { + $icon = ""; + $ordertitle = get_string("ascending","glossary"); + } else { + $ordertitle = get_string("descending","glossary"); + $neworder = "&sortorder=desc"; + $icon = " "; + } + } + $cicon = ""; + $cneworder = ""; + $cbtag = ""; + $cendbtag = ""; + + $uicon = ""; + $uneworder = ""; + $ubtag = ""; + $uendbtag = ""; + + if ( $sortkey == "CREATION" ) { + $cicon = $icon; + $cneworder = $neworder; + $cordertitle = $ordertitle; + $uordertitle = get_string("ascending","glossary"); + $cbtag = ""; + $cendbtag = ""; + } elseif ($sortkey == "UPDATE") { + $uicon = $icon; + $uneworder = $neworder; + $cordertitle = get_string("ascending","glossary"); + $uordertitle = $ordertitle; + $ubtag = ""; + $uendbtag = ""; + } else { + $cordertitle = get_string("ascending","glossary"); + $uordertitle = get_string("ascending","glossary"); + } + echo "
$strsort: $ubtagwwwroot/mod/glossary/view.php?id=$cm->id&sortkey=UPDATE$uneworder\">$strsortbylastupdate$uicon$uendbtag | ". + "$cbtagwwwroot/mod/glossary/view.php?id=$cm->id&sortkey=CREATION$cneworder\">$strsortbycreation$cicon$cendbtag

"; } function glossary_print_categories_menu($course, $cm, $glossary, $cat, $category) { global $CFG, $THEME; diff --git a/mod/glossary/mod.html b/mod/glossary/mod.html index f9edca29d3..490ac019c2 100644 --- a/mod/glossary/mod.html +++ b/mod/glossary/mod.html @@ -144,6 +144,11 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) { echo "selected"; } ?>> + id == $form->instance ) { if (filetype("$CFG->dirroot/mod/glossary/formats/$dir") == "dir") { continue; } - if ( $pos = strpos($dir, ".") ) { - $dir = substr($dir, 0, $pos ); - - echo ""; - } + if ( $pos = strpos($dir, ".") ) { + $dir = substr($dir, 0, $pos ); + if ($dir != 0 and $dir != 1) { // excluding basic formats + echo ""; + } + } } - + ?> diff --git a/mod/glossary/version.php b/mod/glossary/version.php index 61eaf7cd92..e15d5aa72d 100644 --- a/mod/glossary/version.php +++ b/mod/glossary/version.php @@ -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 diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 92186b368f..02d7d0dbac 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -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 '

'; + echo '

'; echo $glossary->intro; echo '

'; 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 "

$strsearch: $search

"; @@ -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 "
"; + } $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 "

"; } - echo "\n

cellheading2\">"; - } - if ($l == "ALL") { + echo "\n
cellheading2\">"; + } + if ($l == "ALL" and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) { echo "$currentletter"; } - if ($glossary->displayformat == 0) { + if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) { echo "\n
"; if ($dumpeddefinitions > 0) { - echo "\n
"; + echo "\n
"; } } } @@ -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 "

"; } echo "\n

cellheading2\">"; } + if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) { + echo "
"; + } echo "$entry->name"; + if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) { + echo "

"; + } } - if ($glossary->displayformat == 0) { + if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) { echo "\n

"; if ($dumpeddefinitions > 0) { echo "\n
"; @@ -271,7 +314,7 @@ $definition = $entry->definition; if ($dumpeddefinitions == 1) { - if ($glossary->displayformat == 0) { + if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) { echo "\n
"; } } @@ -282,14 +325,14 @@ glossary_print_entry($course, $cm, $glossary, $entry, $currentview, $cat); - if ($glossary->displayformat != 0) { + if ($glossary->displayformat != GLOSSARY_FORMAT_SIMPLE) { echo "

"; } } } } if (! $dumpeddefinitions) { - print_simple_box_start("center", "70%", "$THEME->cellheading"); + print_simple_box_start("center", "70%", "$THEME->cellheading2"); if (!$search) { echo "

$strnoentries
"; } else { @@ -299,7 +342,10 @@ } print_simple_box_end(); } else { - if ($glossary->displayformat == 0) { + if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) { + echo "
"; + } + if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) { echo "\n
"; } }