Skip to content

Commit

Permalink
- Case sensitive search when click on a letter, fixed.
Browse files Browse the repository at this point in the history
- 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 committed Nov 19, 2003
1 parent 0dafa92 commit b686236
Show file tree
Hide file tree
Showing 17 changed files with 579 additions and 111 deletions.
7 changes: 7 additions & 0 deletions lang/en/glossary.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
$string['cnflinkentry'] = 'Define if an entry should be automatically linked by default'; $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['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['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['comment'] = 'Comment';
$string['commentdeleted'] = 'The comment has been deleted.'; $string['commentdeleted'] = 'The comment has been deleted.';
$string['comments'] = 'Comments'; $string['comments'] = 'Comments';
Expand All @@ -53,6 +59,7 @@
$string['descending'] = '(descending)'; $string['descending'] = '(descending)';
$string['destination'] = 'Destination'; $string['destination'] = 'Destination';
$string['displayformat'] = 'Display format'; $string['displayformat'] = 'Display format';
$string['displayformats'] = 'Display formats';
$string['displayformat2'] = 'Full with author'; $string['displayformat2'] = 'Full with author';
$string['displayformat3'] = 'Encyclopedia'; $string['displayformat3'] = 'Encyclopedia';
$string['displayformat4'] = 'FAQ'; $string['displayformat4'] = 'FAQ';
Expand Down
1 change: 1 addition & 0 deletions mod/glossary/TODO.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Things that are in the inkpot yet:
* Default view * Default view
* Default Order * Default Order
* Show (or do not) the group breaks. * 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 * What else? Post in http://moodle.org/mod/forum/view.php?id=742


- Allow grading of entries - Allow grading of entries
Expand Down
78 changes: 77 additions & 1 deletion mod/glossary/config.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -188,9 +188,85 @@
<?php print_string("cnffullmatch", "glossary") ?> <?php print_string("cnffullmatch", "glossary") ?>
</td> </td>
</tr> </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> <tr>
<td colspan=3 align=center> <td colspan=3 align=center>
<input type="submit" value="<?php print_string("savechanges") ?>"></td> <input type="submit" value="<?php print_string("savechanges") ?>"></td>
</tr> </tr>
</table> </table>


Expand Down
45 changes: 45 additions & 0 deletions mod/glossary/db/mysql.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -173,6 +173,51 @@ function glossary_upgrade($oldversion) {
execute_sql( "ALTER TABLE `{$CFG->prefix}glossary` execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`
ADD `entbypage` TINYINT(3) UNSIGNED NOT NULL DEFAULT '10' AFTER `globalglossary`" ); 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; return true;
} }
Expand Down
17 changes: 17 additions & 0 deletions mod/glossary/db/mysql.sql
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ CREATE TABLE prefix_glossary_comments (
PRIMARY KEY (id) PRIMARY KEY (id)
) TYPE=MyISAM COMMENT='comments on glossary entries'; ) 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` # Dumping data for table `log_display`
# #
Expand Down
38 changes: 23 additions & 15 deletions mod/glossary/dynalink.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function glossary_dynamic_link($courseid, $text) {
$GLOSSARY_CONCEPT_IS_ENTRY = 0; $GLOSSARY_CONCEPT_IS_ENTRY = 0;
$GLOSSARY_CONCEPT_IS_CATEGORY = 1; $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"); $glossarieslist = get_records_select("glossary", "usedynalink != 0 and (course = $courseid or globalglossary != 0)","globalglossary, id");
if ( $glossarieslist ) { if ( $glossarieslist ) {
$glossaries = ""; $glossaries = "";
Expand All @@ -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"); $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 ) { if ( $entries and $categories ) {
$concepts = array_merge($entries, $categories); $concepts = array_merge($entries, $categories);
usort($concepts,'glossary_sort_entries_by_lenght'); usort($concepts,'glossary_sort_entries_by_lenght');
Expand All @@ -49,19 +48,23 @@ function glossary_dynamic_link($courseid, $text) {
$lastglossary = 0; $lastglossary = 0;
$lastcategory = 0; $lastcategory = 0;
foreach ( $concepts as $concept ) { foreach ( $concepts as $concept ) {
if ( $lastglossary != $concept->glossaryid ) {
$glossary = get_record("glossary","id",$concept->glossaryid);
$lastglossary = $glossary->id;
}
if ( $concept->category ) { if ( $concept->category ) {
if ( $lastcategory != $concept->id ) { if ( $lastcategory != $concept->id ) {
$category = get_record("glossary_categories","id",$concept->id); $category = get_record("glossary_categories","id",$concept->id);
$lastcategory = $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"); $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\">"; $href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&mode=cat&hook=$concept->id\">";
} else { } else {
if ( $lastglossary != $concept->glossaryid ) {
$glossary = get_record("glossary","id",$concept->glossaryid);
$lastglossary = $glossary->id;
}

$concepttitle = urlencode($concept->concept); $concepttitle = urlencode($concept->concept);
$title = strip_tags("$glossary->name: $concepttitle"); $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\" ". $href_tag_begin = "<a target=\"entry\" class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/glossary/showentry.php?courseid=$courseid&concept=$concepttitle\" ".
Expand All @@ -73,9 +76,12 @@ function glossary_dynamic_link($courseid, $text) {
$currentconcept = str_replace("*", "\*", $currentconcept); $currentconcept = str_replace("*", "\*", $currentconcept);
if ( $currentconcept = trim(strip_tags($currentconcept)) ) { if ( $currentconcept = trim(strip_tags($currentconcept)) ) {
if ( !$concept->category ) { 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) { 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);
} }
} }
} }
Expand All @@ -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}=="|") { 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{strlen($list_of_words_cp)-1}="";
} }

$list_of_words_cp = trim($list_of_words_cp); $list_of_words_cp = trim($list_of_words_cp);
if ($fullmatch) { if ($fullmatch) {
$invalidprefixs = "([a-zA-Z0-9])"; $invalidprefixs = "([a-zA-Z0-9])";
Expand Down Expand Up @@ -153,18 +160,19 @@ function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "
} else { } else {
$text = eregi_replace("$list_of_words_cp", "$href_tag_begin"."\\1"."$href_tag_end", $text); $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 ) { if ( $links ) {
$text = str_replace(array_keys($links),$links,$text); $text = str_replace(array_keys($links),$links,$text);
} }
if ( $excludes ) { if ( $excludes ) {
$text = str_replace(array_keys($excludes),$excludes,$text); $text = str_replace(array_keys($excludes),$excludes,$text);
} }
if ( $fullmatch ) { if ( $fullmatch and isset($words) ) {
if ( isset($words) ) { if ($words) {
if ($words) { $text = str_replace(array_keys($words),$words,$text);
$text = str_replace(array_keys($words),$words,$text);
}
} }
} }
return $text; return $text;
Expand Down
6 changes: 3 additions & 3 deletions mod/glossary/edit.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
$newentry->casesensitive = $form->casesensitive; $newentry->casesensitive = $form->casesensitive;
$newentry->fullmatch = $form->fullmatch; $newentry->fullmatch = $form->fullmatch;
$newentry->timemodified = $timenow; $newentry->timemodified = $timenow;
$newentry->approved = $glossary->defaultapproval or isteacher($course->id);


if ($form->concept == '' or trim($form->text) == '' ) { if ($form->concept == '' or trim($form->text) == '' ) {
$errors = get_string('fillfields','glossary'); $errors = get_string('fillfields','glossary');
Expand Down Expand Up @@ -108,7 +109,7 @@
if (! update_record("glossary_entries", $newentry)) { if (! update_record("glossary_entries", $newentry)) {
error("Could not update your glossary"); error("Could not update your glossary");
} else { } 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 { } else {
error("Could not update this glossary entry because this concept already exist."); error("Could not update this glossary entry because this concept already exist.");
Expand All @@ -117,7 +118,6 @@
$newentry->userid = $USER->id; $newentry->userid = $USER->id;
$newentry->timecreated = $timenow; $newentry->timecreated = $timenow;
$newentry->sourceglossaryid = 0; $newentry->sourceglossaryid = 0;
$newentry->approved = $glossary->defaultapproval or isteacher($course->id);
$newentry->teacherentry = isteacher($course->id); $newentry->teacherentry = isteacher($course->id);


$permissiongranted = 1; $permissiongranted = 1;
Expand All @@ -137,7 +137,7 @@
unset($newentry->attachment); unset($newentry->attachment);
} }
set_field("glossary_entries", "attachment", $newfilename, "id", $newentry->id); 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 { } else {
error("Could not insert this glossary entry because this concept already exist."); error("Could not insert this glossary entry because this concept already exist.");
Expand Down
Loading

0 comments on commit b686236

Please sign in to comment.