Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 79... Línea 79...
79
                $this->instance_config_commit();
79
                $this->instance_config_commit();
80
            }
80
            }
Línea 81... Línea 81...
81
 
81
 
Línea -... Línea 82...
-
 
82
            $glossaryctx = context_module::instance($cm->id);
82
            $glossaryctx = context_module::instance($cm->id);
83
 
83
 
84
            $entries = $DB->get_records_sql('SELECT id, concept, definition, definitionformat, definitiontrust
-
 
85
                                               FROM {glossary_entries}
Línea -... Línea 86...
-
 
86
                                              WHERE glossaryid = ? AND approved = 1
84
            $limitfrom = 0;
87
                                              ORDER BY timemodified ASC', [$this->config->glossary]);
Línea -... Línea 88...
-
 
88
 
-
 
89
            // Reset entries keys, so subsequent selection by index works correctly.
-
 
90
            $entries = array_values($entries);
-
 
91
 
85
            $limitnum = 1;
92
            if (empty($entries)) {
86
 
-
 
87
            $orderby = 'timemodified ASC';
93
                $text = get_string('noentriesyet', 'block_glossary_random');
88
 
94
            } else {
-
 
95
                // Now picking out the correct entry from the array.
-
 
96
                switch ($this->config->type) {
89
            switch ($this->config->type) {
97
                    case BGR_RANDOMLY:
-
 
98
                        $i = ($numberofentries > 1) ? rand(1, $numberofentries) : 1;
-
 
99
                        if (count($entries) == 1) {
90
 
100
                            $entry = reset($entries);
91
                case BGR_RANDOMLY:
101
                        } else {
92
                    $i = ($numberofentries > 1) ? rand(1, $numberofentries) : 1;
102
                            $entry = $entries[$i - 1];
-
 
103
                        }
93
                    $limitfrom = $i-1;
104
                        break;
94
                    break;
105
 
95
 
106
                    case BGR_NEXTONE:
96
                case BGR_NEXTONE:
107
                        // The array is already sorted by last modified.
97
                    if (isset($this->config->previous)) {
108
                        if (isset($this->config->previous)) {
98
                        $i = $this->config->previous + 1;
109
                            $i = $this->config->previous + 1;
99
                    } else {
110
                        } else {
100
                        $i = 1;
111
                            $i = 1;
-
 
112
                        }
-
 
113
                        if ($i > $numberofentries) {  // Loop back to beginning.
101
                    }
114
                            $i = 1;
-
 
115
                        }
-
 
116
                        if (count($entries) == 1) {
102
                    if ($i > $numberofentries) {  // Loop back to beginning
117
                            $entry = reset($entries);
103
                        $i = 1;
118
                        } else {
104
                    }
119
                            $entry = $entries[$i - 1];
-
 
120
                        }
105
                    $limitfrom = $i-1;
121
                        break;
-
 
122
 
-
 
123
                    case BGR_NEXTALPHA:
106
                    break;
124
                        // Now sort the array in regard to the current language.
107
 
125
                        usort($entries, function($a, $b) {
108
                case BGR_NEXTALPHA:
126
                            return format_string($a->concept) <=> format_string($b->concept);
109
                    $orderby = 'concept ASC';
127
                        });
110
                    if (isset($this->config->previous)) {
128
                        if (isset($this->config->previous)) {
111
                        $i = $this->config->previous + 1;
129
                            $i = $this->config->previous + 1;
112
                    } else {
130
                        } else {
113
                        $i = 1;
131
                            $i = 1;
-
 
132
                        }
114
                    }
133
                        if ($i > $numberofentries) {  // Loop back to beginning.
-
 
134
                            $i = 1;
-
 
135
                        }
-
 
136
                        if (count($entries) == 1) {
115
                    if ($i > $numberofentries) {  // Loop back to beginning
137
                            $entry = $entries;
116
                        $i = 1;
138
                        } else {
117
                    }
139
                            $entry = $entries[$i - 1];
-
 
140
                        }
118
                    $limitfrom = $i-1;
141
                        break;
119
                    break;
142
 
120
 
143
                    default:  // BGR_LASTMODIFIED
121
                default:  // BGR_LASTMODIFIED
144
                        // The array is already sorted by last modified.
122
                    $i = $numberofentries;
-
 
123
                    $limitfrom = 0;
-
 
124
                    $orderby = 'timemodified DESC, id DESC';
-
 
125
                    break;
145
                        $i = $numberofentries;
126
            }
146
                        if (count($entries) == 1) {
127
 
147
                            $entry = reset($entries);
128
            if ($entry = $DB->get_records_sql("SELECT id, concept, definition, definitionformat, definitiontrust
-
 
129
                                                 FROM {glossary_entries}
148
                        } else {
130
                                                WHERE glossaryid = ? AND approved = 1
-
 
131
                                             ORDER BY $orderby", array($this->config->glossary), $limitfrom, $limitnum)) {
149
                            $entry = array_pop($entries);
132
 
150
                        }
133
                $entry = reset($entry);
151
                        break;
134
 
152
                }
135
                if (empty($this->config->showconcept)) {
153
                if (empty($this->config->showconcept) || (!isset($entry->concept))) {
Línea 136... Línea 154...
136
                    $text = '';
154
                    $text = '';
-
 
155
                } else {
137
                } else {
156
                    $text = "<h3>" . format_string($entry->concept, true, ["context" => $glossaryctx]) . "</h3>";
-
 
157
                }
138
                    $text = "<h3>".format_string($entry->concept,true)."</h3>";
158
 
-
 
159
                $options = new stdClass();
139
                }
160
                if (isset($entry->definitiontrust)) {
-
 
161
                    $options->trusted = $entry->definitiontrust;
140
 
162
                }
141
                $options = new stdClass();
-
 
-
 
163
                $options->overflowdiv = true;
142
                $options->trusted = $entry->definitiontrust;
164
                if (isset($entry->definitiontrust) && isset($entry->id) && isset($entry->definition)) {
143
                $options->overflowdiv = true;
165
                    $entry->definition = file_rewrite_pluginfile_urls($entry->definition, 'pluginfile.php', $glossaryctx->id,
144
                $entry->definition = file_rewrite_pluginfile_urls($entry->definition, 'pluginfile.php', $glossaryctx->id, 'mod_glossary', 'entry', $entry->id);
-
 
145
                $text .= format_text($entry->definition, $entry->definitionformat, $options);
-
 
146
 
-
 
147
                $this->config->nexttime = usergetmidnight(time()) + DAYSECS * $this->config->refresh;
166
                        'mod_glossary', 'entry', $entry->id);
-
 
167
                    $text .= format_text($entry->definition, $entry->definitionformat, $options);
148
                $this->config->previous = $i;
168
                }
149
 
169
                $this->config->nexttime = usergetmidnight(time()) + DAYSECS * $this->config->refresh;
150
            } else {
170
                $this->config->previous = $i;
151
                $text = get_string('noentriesyet','block_glossary_random');
171
            }
152
            }
172