Permalink
Browse files

- Case sensitive search when click on a letter, fixed.

- Adding a display format manager. It controls the behavior of the display format when the user enter the glossary and when an auto-link is shown.
- Adding support to the new fullname function.
  • Loading branch information...
willcast
willcast committed Nov 19, 2003
1 parent 0dafa92 commit b6862360af8412253b3cfa2f8b8751467aea0461
View
@@ -35,6 +35,12 @@
$string['cnflinkentry'] = 'Define if an entry should be automatically linked by default';
$string['cnflinkglossaries'] = 'Define if a glossary should be automatically linked by default';
$string['cnfstudentcanpost'] = 'Define if the students can or cannot post entries by default';
+$string['cnfrelatedview'] = 'Select the display format to be used for automatic linking and entry view.';
+$string['cnfdefaultmode'] = 'Select the default frame to show when the glossary is first viewed.';
+$string['cnfdefaulthook'] = 'Select the default selection to show when the glossary is first viewed';
+$string['cnfsortkey'] = 'Select the sorting key by default.';
+$string['cnfsortorder'] = 'Select the sorting order by default.';
+$string['cnfshowgroup'] = 'Specify if the group break should be shown or not.';
$string['comment'] = 'Comment';
$string['commentdeleted'] = 'The comment has been deleted.';
$string['comments'] = 'Comments';
@@ -53,6 +59,7 @@
$string['descending'] = '(descending)';
$string['destination'] = 'Destination';
$string['displayformat'] = 'Display format';
+$string['displayformats'] = 'Display formats';
$string['displayformat2'] = 'Full with author';
$string['displayformat3'] = 'Encyclopedia';
$string['displayformat4'] = 'FAQ';
View
@@ -6,6 +6,7 @@ Things that are in the inkpot yet:
* Default view
* Default Order
* Show (or do not) the group breaks.
+ * Default view for automatic links, entry view, etc.
* What else? Post in http://moodle.org/mod/forum/view.php?id=742
- Allow grading of entries
View
@@ -188,9 +188,85 @@
<?php print_string("cnffullmatch", "glossary") ?>
</td>
</tr>
+<tr valign=top>
+ <td colspan = 3 align=center><a name=formats><strong>Display Formats Setup</strong></td>
+</tr>
+<tr>
+ <td colspan=3 align=center>
+<?php
+ if ( !$displayformat = get_record("glossary_displayformats","fid",0) ) {
+ unset($displayformat);
+ $displayformat->fid = 0;
+ $displayformat->relatedview = 0;
+ $displayformat->visible = 1;
+ $displayformat->id = insert_record("glossary_displayformats",$displayformat);
+ }
+ if ( !$displayformat = get_record("glossary_displayformats","fid",1) ) {
+ unset($displayformat);
+ $displayformat->fid = 1;
+ $displayformat->relatedview = 1;
+ $displayformat->visible = 1;
+ $displayformat->id = insert_record("glossary_displayformats",$displayformat);
+ }
+
+ $formats = array();
+ $formats[0] = get_string("displayformatdefault", "glossary");
+ $formats[1] = get_string("displayformatcontinuous", "glossary");
+
+ $basedir = opendir("$CFG->dirroot/mod/glossary/formats");
+ while ($dir = readdir($basedir)) {
+ $firstchar = substr($dir, 0, 1);
+ if ($firstchar == "." or $dir == "CVS" or $dir == "_vti_cnf") {
+ continue;
+ }
+ if (filetype("$CFG->dirroot/mod/glossary/formats/$dir") == "dir") {
+ continue;
+ }
+ if ( $pos = strpos($dir, ".") ) {
+ $dir = substr($dir, 0, $pos );
+ if ($dir != 0 and $dir != 1) { // excluding basic formats
+ if ( !$displayformat = get_record("glossary_displayformats","fid",$dir) ) {
+ unset($displayformat);
+ $displayformat->fid = $dir;
+ $displayformat->relatedview = $dir;
+ $displayformat->visible = 1;
+ $displayformat->id = insert_record("glossary_displayformats",$displayformat);
+ }
+ $formats[$dir] = get_string("displayformat$dir", "glossary");
+ }
+ }
+ }
+ asort($formats);
+
+ echo '<table cellpadding="5" bgcolor="#FFFFFF" class="generaltab" width="40%" align="center" style="border-style: solid; border-width: 1px;">';
+ for ($i = 0; $i <= count($formats); $i++) {
+ if ( $formats[$i] ) {
+ $format = get_record("glossary_displayformats","fid",$i);
+ echo '<tr>';
+ echo '<td>' . $formats[$i] . '</td>';
+ $eicon = "<a title=\"" . get_string("edit") . "\" href=\"$CFG->wwwroot/mod/glossary/formats.php?id=$i&mode=edit\"><img border=\"0\" src=\"../pix/t/edit.gif\"></a>";
+ if ( $format->visible ) {
+ $vtitle = get_string("hide");
+ $vicon = "hide.gif";
+ } else {
+ $vtitle = get_string("show");
+ $vicon = "show.gif";
+ }
+ $vicon = "<a title=\"" . $vtitle . "\" href=\"$CFG->wwwroot/mod/glossary/formats.php?id=$i&mode=visible\"><img border=\"0\" src=\"../pix/t/" . $vicon . "\"></a>";
+
+ echo '<td align="center"> ' . $eicon . '&nbsp;&nbsp;' . $vicon . '</td>';
+ echo '</tr>';
+ }
+ }
+ echo '</table>';
+
+?>
+
+ </td>
+</tr>
<tr>
<td colspan=3 align=center>
- <input type="submit" value="<?php print_string("savechanges") ?>"></td>
+ <input type="submit" value="<?php print_string("savechanges") ?>"></td>
</tr>
</table>
View
@@ -173,6 +173,51 @@ function glossary_upgrade($oldversion) {
execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`
ADD `entbypage` TINYINT(3) UNSIGNED NOT NULL DEFAULT '10' AFTER `globalglossary`" );
+ }
+
+ if ( $oldversion < 2003111800 ) {
+ execute_sql("CREATE TABLE `{$CFG->prefix}glossary_displayformats` (
+ `id` INT(10) unsigned NOT NULL auto_increment,
+ `fid` INT(10) UNSIGNED NOT NULL default '0',
+ `visible` TINYINT(2) UNSIGNED NOT NULL default '1',
+ `relatedview` TINYINT(3) NOT NULL default '-1',
+ `showgroup` TINYINT(2) UNSIGNED NOT NULL default '1',
+ `defaultmode` VARCHAR(50) NOT NULL default '',
+ `defaulthook` VARCHAR(50) NOT NULL default '',
+ `sortkey` VARCHAR(50) NOT NULL default '',
+ `sortorder` VARCHAR(50) NOT NULL default '',
+ PRIMARY KEY (`id`)
+ ) TYPE=MyISAM COMMENT='Setting of the display formats'");
+
+ // Default format
+ execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
+ (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
+ VALUES (0,0,'letter','ALL','CREATION','asc',1,1)");
+ // Continuous format
+ execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
+ (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
+ VALUES (1,1,'date','ALL','CREATION','asc',0,1)");
+ // Full w/author View
+ execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
+ (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
+ VALUES (2,2,'letter','ALL','CREATION','asc',1,1)");
+ // Encyclopedia
+ execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
+ (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
+ VALUES (3,3,'letter','ALL','CREATION','asc',1,1)");
+ // FAQ View
+ execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
+ (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
+ VALUES (4,4,'date','ALL','CREATION','asc',0,1)");
+ // Full w/o author View
+ execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
+ (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
+ VALUES (5,5,'letter','ALL','CREATION','asc',1,1)");
+ // Entry list
+ execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
+ (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
+ VALUES (6,0,'letter','ALL','CREATION','asc',1,1)");
+
}
return true;
}
View
@@ -98,6 +98,23 @@ CREATE TABLE prefix_glossary_comments (
PRIMARY KEY (id)
) TYPE=MyISAM COMMENT='comments on glossary entries';
+CREATE TABLE prefix_glossary_displayformats (
+ id int(10) unsigned NOT NULL auto_increment,
+ fid int(10) unsigned NOT NULL default '0',
+ visible tinyint(2) unsigned NOT NULL default '1',
+
+ relatedview tinyint(3) NOT NULL default '-1',
+ showgroup tinyint(2) unsigned NOT NULL default '1',
+
+ defaultmode varchar(50) NOT NULL default '',
+ defaulthook varchar(50) NOT NULL default '',
+
+ sortkey varchar(50) NOT NULL default '',
+ sortorder varchar(50) NOT NULL default '',
+
+ PRIMARY KEY (id)
+) TYPE=MyISAM COMMENT='Setting of the display formats';
+
#
# Dumping data for table `log_display`
#
View
@@ -12,7 +12,6 @@ function glossary_dynamic_link($courseid, $text) {
$GLOSSARY_CONCEPT_IS_ENTRY = 0;
$GLOSSARY_CONCEPT_IS_CATEGORY = 1;
-// $glossarieslist = get_records_select("glossary", "usedynalink != 0 and (course = $courseid or global != 0)","id");
$glossarieslist = get_records_select("glossary", "usedynalink != 0 and (course = $courseid or globalglossary != 0)","globalglossary, id");
if ( $glossarieslist ) {
$glossaries = "";
@@ -35,7 +34,7 @@ function glossary_dynamic_link($courseid, $text) {
}
$entries = get_records_select("glossary_entries", "glossaryid IN ($glossaries) AND usedynalink != 0 and approved != 0 and concept != ''","$ebylenght glossaryid","id,glossaryid,concept,casesensitive,$GLOSSARY_CONCEPT_IS_ENTRY category,fullmatch");
- $categories = get_records_select("glossary_categories", "glossaryid IN ($glossaries) AND usedynalink != 0", "$cbylenght glossaryid,id","id,glossaryid,name concept, 1 casesensitive,$GLOSSARY_CONCEPT_IS_CATEGORY category, 1 fullmatch");
+ $categories = get_records_select("glossary_categories", "glossaryid IN ($glossaries) AND usedynalink != 0", "$cbylenght glossaryid","id,glossaryid,name concept, 1 casesensitive,$GLOSSARY_CONCEPT_IS_CATEGORY category, 1 fullmatch");
if ( $entries and $categories ) {
$concepts = array_merge($entries, $categories);
usort($concepts,'glossary_sort_entries_by_lenght');
@@ -49,19 +48,23 @@ function glossary_dynamic_link($courseid, $text) {
$lastglossary = 0;
$lastcategory = 0;
foreach ( $concepts as $concept ) {
- if ( $lastglossary != $concept->glossaryid ) {
- $glossary = get_record("glossary","id",$concept->glossaryid);
- $lastglossary = $glossary->id;
- }
if ( $concept->category ) {
if ( $lastcategory != $concept->id ) {
$category = get_record("glossary_categories","id",$concept->id);
$lastcategory = $concept->id;
+ if ( $cm->instance != $category->glossaryid ) {
+ $cm = get_coursemodule_from_instance("glossary", $category->glossaryid, $courseid);
+ }
}
- $cm = get_coursemodule_from_instance("glossary", $glossary->id, $courseid);
+
$title = strip_tags("$glossary->name: " . get_string("category","glossary"). " $category->name");
$href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&mode=cat&hook=$concept->id\">";
} else {
+ if ( $lastglossary != $concept->glossaryid ) {
+ $glossary = get_record("glossary","id",$concept->glossaryid);
+ $lastglossary = $glossary->id;
+ }
+
$concepttitle = urlencode($concept->concept);
$title = strip_tags("$glossary->name: $concepttitle");
$href_tag_begin = "<a target=\"entry\" class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/glossary/showentry.php?courseid=$courseid&concept=$concepttitle\" ".
@@ -73,9 +76,12 @@ function glossary_dynamic_link($courseid, $text) {
$currentconcept = str_replace("*", "\*", $currentconcept);
if ( $currentconcept = trim(strip_tags($currentconcept)) ) {
if ( !$concept->category ) {
- if ( $aliases = get_records("glossary_alias","entryid",$concept->id) ) {
+ if ( $aliases = get_records("glossary_alias","entryid",$concept->id, "alias") ) {
foreach ($aliases as $alias) {
- $currentconcept .= "|" . trim(strip_tags(str_replace("|", "\|", $alias->alias)));
+ $currentalias = str_replace("|", "\|", $alias->alias);
+ $currentalias = str_replace("'", "\'", $currentalias);
+ $currentalias = str_replace("*", "\*", $currentalias);
+ $currentconcept .= "|" . trim($currentalias);
}
}
}
@@ -97,6 +103,7 @@ function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "
if ($list_of_words_cp{strlen($list_of_words_cp)-1}=="|") {
$list_of_words_cp{strlen($list_of_words_cp)-1}="";
}
+
$list_of_words_cp = trim($list_of_words_cp);
if ($fullmatch) {
$invalidprefixs = "([a-zA-Z0-9])";
@@ -153,18 +160,19 @@ function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "
} else {
$text = eregi_replace("$list_of_words_cp", "$href_tag_begin"."\\1"."$href_tag_end", $text);
}
- $text = str_replace(array_keys($final),$final,$text);
+
+ if ( $final ) {
+ $text = str_replace(array_keys($final),$final,$text);
+ }
if ( $links ) {
$text = str_replace(array_keys($links),$links,$text);
}
if ( $excludes ) {
$text = str_replace(array_keys($excludes),$excludes,$text);
}
- if ( $fullmatch ) {
- if ( isset($words) ) {
- if ($words) {
- $text = str_replace(array_keys($words),$words,$text);
- }
+ if ( $fullmatch and isset($words) ) {
+ if ($words) {
+ $text = str_replace(array_keys($words),$words,$text);
}
}
return $text;
View
@@ -52,6 +52,7 @@
$newentry->casesensitive = $form->casesensitive;
$newentry->fullmatch = $form->fullmatch;
$newentry->timemodified = $timenow;
+ $newentry->approved = $glossary->defaultapproval or isteacher($course->id);
if ($form->concept == '' or trim($form->text) == '' ) {
$errors = get_string('fillfields','glossary');
@@ -108,7 +109,7 @@
if (! update_record("glossary_entries", $newentry)) {
error("Could not update your glossary");
} else {
- add_to_log($course->id, "glossary", "update entry", "view.php?id=$cm->id&mode=entry&hook=$newentry->id", "$newentry->id");
+ add_to_log($course->id, "glossary", "update entry", "view.php?id=$cm->id&mode=entry&hook=$newentry->id", $newentry->id);
}
} else {
error("Could not update this glossary entry because this concept already exist.");
@@ -117,7 +118,6 @@
$newentry->userid = $USER->id;
$newentry->timecreated = $timenow;
$newentry->sourceglossaryid = 0;
- $newentry->approved = $glossary->defaultapproval or isteacher($course->id);
$newentry->teacherentry = isteacher($course->id);
$permissiongranted = 1;
@@ -137,7 +137,7 @@
unset($newentry->attachment);
}
set_field("glossary_entries", "attachment", $newfilename, "id", $newentry->id);
- add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&mode=entry&hook=$newentry->id", "$newentry->id");
+ add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&mode=entry&hook=$newentry->id", $newentry->id);
}
} else {
error("Could not insert this glossary entry because this concept already exist.");
Oops, something went wrong.

0 comments on commit b686236

Please sign in to comment.