1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Contains class mod_questionnaire\search\activity
|
|
|
19 |
*
|
|
|
20 |
* @package mod_questionnaire
|
|
|
21 |
* @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org)
|
|
|
22 |
* @author Mike Churchward
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace mod_questionnaire\search;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Search area for mod_questionnaire activities.
|
|
|
30 |
*
|
|
|
31 |
* @package mod_questionnaire
|
|
|
32 |
* @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org)
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class activity extends \core_search\base_activity {
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Returns recordset containing required data for indexing activities.
|
|
|
39 |
*
|
|
|
40 |
* @param int $modifiedfrom timestamp
|
|
|
41 |
* @return \moodle_recordset
|
|
|
42 |
*/
|
|
|
43 |
public function get_recordset_by_timestamp($modifiedfrom = 0) {
|
|
|
44 |
global $DB;
|
|
|
45 |
|
|
|
46 |
$sql = 'SELECT q.*, s.subtitle, s.info ' .
|
|
|
47 |
'FROM {questionnaire} q ' .
|
|
|
48 |
'INNER JOIN {questionnaire_survey} s ON q.sid = s.id ' .
|
|
|
49 |
'WHERE q.timemodified >= ? ' .
|
|
|
50 |
'ORDER BY q.timemodified ASC';
|
|
|
51 |
|
|
|
52 |
return $DB->get_recordset_sql($sql, [$modifiedfrom]);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* Returns the document associated with this activity.
|
|
|
57 |
*
|
|
|
58 |
* The default implementation for activities sets the activity name to title and the activity intro to
|
|
|
59 |
* content. This override takes that data and adds new fields to it for indexing.
|
|
|
60 |
*
|
|
|
61 |
* @param stdClass $record
|
|
|
62 |
* @param array $options
|
|
|
63 |
* @return \core_search\document
|
|
|
64 |
*/
|
|
|
65 |
public function get_document($record, $options = []) {
|
|
|
66 |
// Get the default implementation.
|
|
|
67 |
$doc = parent::get_document($record, $options);
|
|
|
68 |
if (!$doc) {
|
|
|
69 |
return false;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
// Add the subtitle and additional info fields.
|
|
|
73 |
$doc->set('description1', content_to_text($record->subtitle, false));
|
|
|
74 |
$doc->set('description2', content_to_text($record->info, $record->introformat));
|
|
|
75 |
|
|
|
76 |
return $doc;
|
|
|
77 |
}
|
|
|
78 |
}
|