Skip to content

Instantly share code, notes, and snippets.

@prateeksachan
Last active December 19, 2015 04:39
Show Gist options
  • Save prateeksachan/5899120 to your computer and use it in GitHub Desktop.
Save prateeksachan/5899120 to your computer and use it in GitHub Desktop.
<?php
//get a chapter's records for each chapter id
$chapter = $DB->get_record('book_chapters', array('id' => $id), '*', MUST_EXIST);
//get book record for that chapter
$book = $DB->get_record('book', array('id' => $chapter->bookid), '*', MUST_EXIST);
$doc = new SolrInputDocument();
$doc->addField('id', 'book_' . $chapter->id);
$doc->addField('name', $book->name);
$doc->addField('intro', format_text($book->intro, $book->introformat, array('nocache' => true, 'para' => false)));
$doc->addField('title', $chapter->title);
$doc->addField('content', format_text($chapter->content, $chapter->contentformat, array('nocache' => true, 'para' => false)));
$doc->addField('contextlink', '/mod/book/view.php?id=' . $cm->id .'&chapterid=' . $book->id);
$doc->addField('module', 'book');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment