Skip to content

Commit

Permalink
Merge pull request #115 from pramithkm/MOODLE_400_STABLE
Browse files Browse the repository at this point in the history
Improvement search area "coversations"
  • Loading branch information
danmarsden authored Feb 15, 2023
2 parents 82c8a6d + e525a55 commit 8cfd35e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions classes/search/conversations.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ public function get_doc_url(\core_search\document $doc) {
* @return \moodle_url
*/
public function get_context_url(\core_search\document $doc) {
$contextmodule = \context::instance_by_id($doc->get('contextid'));
return new \moodle_url('/mod/dialogue/view.php', array('id' => $contextmodule->instanceid));
$context = \context::instance_by_id($doc->get('contextid'));
$entry = $this->get_dialogue_conversations($doc->get('itemid'));
return new \moodle_url('/mod/dialogue/conversation.php', array('id' => $context->instanceid, 'action' => 'view', 'conversationid' => $entry->messageid));
}

/**
Expand All @@ -169,7 +170,7 @@ public function get_context_url(\core_search\document $doc) {
protected function get_dialogue_conversations($messageid) {
global $DB;

return $DB->get_record_sql("SELECT dm.dialogueid, dc.course FROM {dialogue_messages} dm
return $DB->get_record_sql("SELECT dm.dialogueid, dc.course, dc.id as messageid FROM {dialogue_messages} dm
LEFT JOIN {dialogue_conversations} dc ON dc.id = dm.conversationid
WHERE dm.id = ?", array('id' => $messageid), MUST_EXIST);
}
Expand All @@ -187,29 +188,28 @@ public function uses_file_indexing() {
* Add the forum post attachments.
*
* @param document $document The current document
* @return null|object stored file
* @return null
*/
public function attach_files($doc) {
$fs = get_file_storage();

$entryid = $doc->get('itemid');

try {
$entry = $this->get_entry($entryid);
$entry = $this->get_dialogue_conversations($entryid);
} catch (\dml_missing_record_exception $e) {
debugging('Could not get record to attach files to '.$doc->get('id'), DEBUG_DEVELOPER);
return;
}

$cm = $this->get_cm('dialogue', $entry->dataid, $doc->get('courseid'));
$cm = $this->get_cm('dialogue', $entry->dialogueid, $doc->get('courseid'));
$context = \context_module::instance($cm->id);

// Get the files and attach them.
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_dialogue', 'attachment', $entryid, 'filename', false);

foreach ($files as $file) {
$document->add_stored_file($file);
$doc->add_stored_file($file);
}
}

Expand Down

0 comments on commit 8cfd35e

Please sign in to comment.