Skip to content

Commit ae117f1

Browse files
committed
Issue #66 Use parent functions and rename search class name
1 parent 44d71ec commit ae117f1

File tree

3 files changed

+3
-83
lines changed

3 files changed

+3
-83
lines changed

classes/search/cmsfield.php classes/search/activity.php

+1-81
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,7 @@
3131
* @copyright 2024 Catalyst IT
3232
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3333
*/
34-
class cmsfield extends \core_search\base_activity {
35-
36-
/**
37-
* @var array Internal quick static cache.
38-
*/
39-
protected $cmsdata = [];
40-
41-
/**
42-
* @var array Internal quick static cache.
43-
*/
44-
protected $defaultvalues = null;
34+
class activity extends \core_search\base_activity {
4535

4636
/**
4737
* Returns the document associated with this data id.
@@ -89,76 +79,6 @@ public function get_document($record, $options = []) {
8979
return $doc;
9080
}
9181

92-
/**
93-
* Whether the user can access the document or not.
94-
*
95-
* @param int $id data id
96-
* @return bool
97-
*/
98-
public function check_access($id) {
99-
try {
100-
$data = $this->get_data($id);
101-
$cminfo = $this->get_cm('cms', $data->id, $data->courseid);
102-
$context = \context_module::instance($cminfo->id);
103-
} catch (\dml_missing_record_exception $ex) {
104-
return \core_search\manager::ACCESS_DELETED;
105-
} catch (\dml_exception $ex) {
106-
return \core_search\manager::ACCESS_DENIED;
107-
}
108-
109-
// Recheck uservisible although it should have already been checked in core_search.
110-
if ($cminfo->uservisible === false) {
111-
return \core_search\manager::ACCESS_DENIED;
112-
}
113-
114-
if (!has_capability('mod/cms:view', $context)) {
115-
return \core_search\manager::ACCESS_DENIED;
116-
}
117-
118-
return \core_search\manager::ACCESS_GRANTED;
119-
}
120-
121-
/**
122-
* Link to the cms.
123-
*
124-
* @param \core_search\document $doc
125-
* @return \moodle_url
126-
*/
127-
public function get_doc_url(\core_search\document $doc) {
128-
$contextmodule = \context::instance_by_id($doc->get('contextid'));
129-
$cm = get_coursemodule_from_id('cms', $contextmodule->instanceid, $doc->get('courseid'), true);
130-
return new \moodle_url('/course/view.php', ['id' => $doc->get('courseid'), 'section' => $cm->sectionnum]);
131-
}
132-
133-
/**
134-
* Link to the cms.
135-
*
136-
* @param \core_search\document $doc
137-
* @return \moodle_url
138-
*/
139-
public function get_context_url(\core_search\document $doc) {
140-
$contextmodule = \context::instance_by_id($doc->get('contextid'));
141-
return new \moodle_url('/mod/cms/view.php', ['id' => $contextmodule->instanceid]);
142-
}
143-
144-
/**
145-
* Returns the specified data from its internal cache.
146-
*
147-
* @throws \dml_missing_record_exception
148-
* @param int $id
149-
* @return stdClass
150-
*/
151-
protected function get_data($id) {
152-
global $DB;
153-
if (empty($this->cmsdata[$id])) {
154-
$sql = "SELECT mc.id, mc.course AS courseid
155-
FROM {cms} mc
156-
WHERE mc.id = :id";
157-
$this->cmsdata[$id] = $DB->get_record_sql($sql, ['id' => $id], MUST_EXIST);
158-
}
159-
return $this->cmsdata[$id];
160-
}
161-
16282
/**
16383
* Returns true if this area uses file indexing.
16484
*

lang/en/cms.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
$string['error:no_config_hash'] = 'Module {$a} has no config hash.';
105105

106106
// Search strings.
107-
$string['search:cmsfield'] = 'CMS';
107+
$string['search:activity'] = 'CMS - activity information';
108108

109109
// Site datasource strings.
110110
$string['site:displayname'] = 'Site Info';

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
defined('MOODLE_INTERNAL') || die();
2727

28-
$plugin->version = 2024090300;
28+
$plugin->version = 2024090301;
2929
$plugin->requires = 2022112800; // Moodle 4.1 and above.
3030
$plugin->supported = [401, 401]; // Moodle 4.1.
3131
$plugin->component = 'mod_cms';

0 commit comments

Comments
 (0)