mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Added language file (somewhat different to one in forums).
Made some major cleanups to the block for efficiency, robustness and Postgres compat. It seems to work for me OK but could use some good testing!
This commit is contained in:
parent
f1eaa9727f
commit
2896553e9d
3 changed files with 95 additions and 48 deletions
|
@ -1,7 +1,8 @@
|
||||||
<?PHP
|
<?PHP
|
||||||
define("RANDOMLY", "0");
|
|
||||||
define("LASTMODIFIED", "1");
|
define('BGR_RANDOMLY', '0');
|
||||||
define("NEXTONE","2");
|
define('BGR_LASTMODIFIED', '1');
|
||||||
|
define('BGR_NEXTONE', '2');
|
||||||
|
|
||||||
class block_glossary_random extends block_base {
|
class block_glossary_random extends block_base {
|
||||||
function init() {
|
function init() {
|
||||||
|
@ -35,42 +36,54 @@ class block_glossary_random extends block_base {
|
||||||
if (time() > $this->config->nexttime) {
|
if (time() > $this->config->nexttime) {
|
||||||
|
|
||||||
// place glossary concept and definition in $pref->cache
|
// place glossary concept and definition in $pref->cache
|
||||||
$numberofentries = count_records("glossary_entries","glossaryid",$this->config->glossary,"approved",1)-1;
|
if (!$numberofentries = count_records('glossary_entries','glossaryid',$this->config->glossary,
|
||||||
|
'approved',1)) {
|
||||||
|
$this->config->cache = get_string('noentriesyet','block_glossary_random');
|
||||||
|
parent::instance_config_save($this->config);
|
||||||
|
}
|
||||||
|
|
||||||
switch ($this->config->type) {
|
switch ($this->config->type) {
|
||||||
|
|
||||||
case RANDOMLY:
|
case BGR_RANDOMLY:
|
||||||
$i = rand(0,$numberofentries);
|
$i = rand(1,$numberofentries);
|
||||||
|
$LIMIT = sql_paging_limit($i-1, 1);
|
||||||
|
$SORT = 'ASC';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NEXTONE:
|
case BGR_NEXTONE:
|
||||||
$i = 1 + $this->config->previous;
|
if (isset($this->config->previous)) {
|
||||||
if ($i < $numberofentries) {
|
$i = $this->config->previous + 1;
|
||||||
break;
|
} else {
|
||||||
|
$i = 1;
|
||||||
|
}
|
||||||
|
if ($i > $numberofentries) { // Loop back to beginning
|
||||||
|
$i = 1;
|
||||||
}
|
}
|
||||||
//otherwise fall through
|
$LIMIT = sql_paging_limit($i-1, 1);
|
||||||
|
$SORT = 'ASC';
|
||||||
|
break;
|
||||||
|
|
||||||
case LASTMODIFIED:
|
default: // BGR_LASTMODIFIED
|
||||||
$i=$numberofentries;
|
$i = $numberofentries;
|
||||||
|
$LIMIT = 'LIMIT 1'; // The last one
|
||||||
|
$SORT = 'DESC';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($entries = get_records_sql("SELECT concept, definition, format FROM {$CFG->prefix}glossary_entries WHERE glossaryid = {$this->config->glossary} and approved = 1 ORDER BY timemodified LIMIT {$i},1")) {
|
if ($entry = get_record_sql(' SELECT concept, definition, format '.
|
||||||
// get all entries, normally there is only one entry returned
|
' FROM '.$CFG->prefix.'glossary_entries'.
|
||||||
foreach ($entries as $entry) {
|
' WHERE glossaryid = '.$this->config->glossary.
|
||||||
$text = "<b> $entry->concept</b><br>";
|
' AND approved = 1 '.
|
||||||
$text .= format_text($entry->definition, $entry->format);
|
'ORDER BY timemodified '.$SORT.' '.$LIMIT)) {
|
||||||
|
|
||||||
}
|
$text = "<b>$entry->concept</b><br />";
|
||||||
|
$text .= format_text($entry->definition, $entry->format);
|
||||||
|
|
||||||
$this->config->nexttime = usergetmidnight(time())+60*60*24*$this->config->refresh;
|
$this->config->nexttime = usergetmidnight(time())+60*60*24*$this->config->refresh;
|
||||||
$this->config->previous = $i;
|
$this->config->previous = $i;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$text = get_string('notyetconfigured','block_glossary_random');
|
$text = get_string('noentriesyet','block_glossary_random');
|
||||||
}
|
}
|
||||||
// store the text
|
// store the text
|
||||||
$this->config->cache= $text;
|
$this->config->cache= $text;
|
||||||
|
@ -92,19 +105,19 @@ class block_glossary_random extends block_base {
|
||||||
$this->config->title = get_string('blockname','block_glossary_random');
|
$this->config->title = get_string('blockname','block_glossary_random');
|
||||||
$this->config->refresh = 0;
|
$this->config->refresh = 0;
|
||||||
|
|
||||||
$this->config->cache= get_string("notyetconfigured","block_glossary_random");
|
$this->config->cache= get_string('notyetconfigured','block_glossary_random');
|
||||||
$this->config->addentry=get_string("addentry", "block_glossary_random");
|
$this->config->addentry=get_string('addentry', 'block_glossary_random');
|
||||||
$this->config->viewglossary=get_string("viewglossary", "block_glossary_random");
|
$this->config->viewglossary=get_string('viewglossary', 'block_glossary_random');
|
||||||
$this->config->invisible=get_string("invisible", "block_glossary_random");
|
$this->config->invisible=get_string('invisible', 'block_glossary_random');
|
||||||
}
|
}
|
||||||
|
|
||||||
// select glossaries to put in dropdown box ...
|
// select glossaries to put in dropdown box ...
|
||||||
$glossaries = get_records_select_menu("glossary", "course=".$this->course->id,"name","id,name");
|
$glossaries = get_records_select_menu('glossary', 'course='.$this->course->id,'name','id,name');
|
||||||
|
|
||||||
// and select quotetypes to put in dropdown box
|
// and select quotetypes to put in dropdown box
|
||||||
$type[0] = get_string("random","block_glossary_random");
|
$type[0] = get_string('random','block_glossary_random');
|
||||||
$type[1] = get_string("lastmodified","block_glossary_random");
|
$type[1] = get_string('lastmodified','block_glossary_random');
|
||||||
$type[2] = get_string("nextone","block_glossary_random");
|
$type[2] = get_string('nextone','block_glossary_random');
|
||||||
|
|
||||||
$this->config->nexttime = usergetmidnight(time())+24*60*60*$this->config->refresh;
|
$this->config->nexttime = usergetmidnight(time())+24*60*60*$this->config->refresh;
|
||||||
|
|
||||||
|
@ -118,31 +131,36 @@ class block_glossary_random extends block_base {
|
||||||
notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me()));
|
notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_content() {
|
function get_content() {
|
||||||
global $USER, $CFG;
|
global $USER, $CFG;
|
||||||
|
|
||||||
if($this->content !== NULL) {
|
|
||||||
return $this->content;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->content = new stdClass;
|
|
||||||
$this->content->text = $this->config->cache;
|
|
||||||
|
|
||||||
if (empty($this->config->glossary)) {
|
if (empty($this->config->glossary)) {
|
||||||
|
$this->content->text = get_string('notyetconfigured','block_glossary_random');
|
||||||
|
return $this->content->text;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($this->config->cache)) {
|
||||||
|
$this->config->cache = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->content !== NULL) {
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->content = new stdClass;
|
||||||
|
$this->content->text = $this->config->cache;
|
||||||
|
|
||||||
// place link to glossary in the footer if the glossary is visible
|
// place link to glossary in the footer if the glossary is visible
|
||||||
$glossaryid = $this->config->glossary;
|
$glossaryid = $this->config->glossary;
|
||||||
$glossary=get_record("glossary", "id", $glossaryid);
|
$glossary=get_record('glossary', 'id', $glossaryid);
|
||||||
$studentcanpost = $glossary->studentcanpost; //needed to decide on which footer
|
$studentcanpost = $glossary->studentcanpost; //needed to decide on which footer
|
||||||
|
|
||||||
//Create a temp valid module structure (course,id)
|
//Create a temp valid module structure (course,id)
|
||||||
$tempmod->course = $this->course->id;
|
$tempmod->course = $this->course->id;
|
||||||
$tempmod->id = $glossaryid;
|
$tempmod->id = $glossaryid;
|
||||||
|
|
||||||
//Obtain the visible property from the instance
|
//Obtain the visible property from the instance
|
||||||
if (instance_is_visible('glossary', $tempmod)) {
|
if (instance_is_visible('glossary', $tempmod)) {
|
||||||
|
@ -167,9 +185,6 @@ class block_glossary_random extends block_base {
|
||||||
|
|
||||||
function hide_header() {
|
function hide_header() {
|
||||||
if (empty($this->config->title)) {
|
if (empty($this->config->title)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($this->config->title == "") {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
<?php
|
||||||
|
if (!isset($this->config->glossary)) {
|
||||||
|
$this->config->glossary = 0;
|
||||||
|
}
|
||||||
|
if (!isset($this->config->type)) {
|
||||||
|
$this->config->type = 0;
|
||||||
|
}
|
||||||
|
?>
|
||||||
<table cellpadding="9" cellspacing="0">
|
<table cellpadding="9" cellspacing="0">
|
||||||
<tr valign=top>
|
<tr valign=top>
|
||||||
<td align=right><?php print_string("title","block_glossary_random") ?>:</td>
|
<td align=right><?php print_string("title","block_glossary_random") ?>:</td>
|
||||||
|
|
24
lang/en/block_glossary_random.php
Normal file
24
lang/en/block_glossary_random.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php // $Id$
|
||||||
|
$string['aboutfooter'] = 'This block inherits some settings from the glossary it is associated with. Only one of the following texts is displayed depending on the settings of the glossary';
|
||||||
|
$string['addentry'] = 'Add your own favorite quotes!';
|
||||||
|
$string['askaddentry'] = 'If students are allowed to add their own entries to the glossary, a link to the glossary is shown with the following text';
|
||||||
|
$string['askinvisible'] = 'If you want to keep the original glossary hidden from students, no link is shown. The following text is shown instead.';
|
||||||
|
$string['askviewglossary'] = 'If students are only allowed to see the entire content of the glossary, a link to the glossary is shown with the following text';
|
||||||
|
$string['blockname'] = 'Random Glossary Entry';
|
||||||
|
$string['change_configuration'] = 'Change settings for block';
|
||||||
|
$string['configureblock'] = 'Change settings for this block';
|
||||||
|
$string['intro'] = 'Make sure you have at least one glossary with at least one entry added to this course. Then you can adjust the following settings';
|
||||||
|
$string['invisible'] = '(to be continued)';
|
||||||
|
$string['lastmodified'] = 'Last modified entry';
|
||||||
|
$string['nextone'] = 'Next entry';
|
||||||
|
$string['noentriesyet'] = 'There are no entries yet in the chosen glossary.';
|
||||||
|
$string['notyetconfigured'] = 'Please configure this block using the edit icon.';
|
||||||
|
$string['notyetglossary'] = 'You need to have at least one Glossary to choose.';
|
||||||
|
$string['random'] = 'Random entry';
|
||||||
|
$string['refresh'] = 'Days before a new entry is chosen';
|
||||||
|
$string['select_glossary'] = 'Take entries from this glossary';
|
||||||
|
$string['title'] = 'Title';
|
||||||
|
$string['typehelp'] = '<b>Last modified entry</b> will always display the entry that was last modified, and <b>Random entry</b> will choose a new one at random every time. The option <b>Next entry</b> will cycle through the entries in order. This last option is especially useful when a number of days is also chosen, allowing you to make a \"Quote of the week\" or a \"Tip of the day\" that everyone sees.';
|
||||||
|
$string['type'] = 'How a new entry is chosen';
|
||||||
|
$string['viewglossary'] = 'More quotes...';
|
||||||
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue