Esempio n. 1
0
/**
 * Fetch an entry.
 *
 * @param  int $id The entry ID.
 * @return object|false The entry, or false when not found.
 * @since Moodle 3.1
 */
function glossary_get_entry_by_id($id)
{
    // Build the query.
    $qb = new mod_glossary_entry_query_builder();
    $qb->add_field('*', 'entries');
    $qb->join_user();
    $qb->add_user_fields();
    $qb->where('id', 'entries', $id);
    // Fetching the entries.
    $entries = $qb->get_records();
    if (empty($entries)) {
        return false;
    }
    return array_pop($entries);
}
Esempio n. 2
0
$coursename = get_string("course") . ': <span class="strong">' . format_string($course->fullname) . ' (' . format_string($course->shortname) . ')</span>';
echo html_writer::tag('div', $coursename, array('class' => 'coursename'));
$modname = get_string("modulename", "glossary") . ': <span class="strong">' . format_string($glossary->name, true) . '</span>';
echo html_writer::tag('div', $modname, array('class' => 'modname'));
if ($allentries) {
    foreach ($allentries as $entry) {
        // Setting the pivot for the current entry.
        if ($printpivot) {
            $pivot = $entry->{$pivotkey};
            $upperpivot = core_text::strtoupper($pivot);
            $pivottoshow = core_text::strtoupper(format_string($pivot, true, $fmtoptions));
            // Reduce pivot to 1cc if necessary.
            if (!$fullpivot) {
                $upperpivot = core_text::substr($upperpivot, 0, 1);
                $pivottoshow = core_text::substr($pivottoshow, 0, 1);
            }
            // If there's a group break.
            if ($currentpivot != $upperpivot) {
                $currentpivot = $upperpivot;
                if ($userispivot) {
                    // Printing the user icon if defined (only when browsing authors).
                    $user = mod_glossary_entry_query_builder::get_user_from_record($entry);
                    $pivottoshow = fullname($user);
                }
                echo html_writer::tag('div', clean_text($pivottoshow), array('class' => 'mdl-align strong'));
            }
        }
        glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook, 1, $displayformat, true);
    }
}
echo $OUTPUT->footer();
Esempio n. 3
0
 /**
  * Fill in an entry object.
  *
  * This adds additional required fields for the external function to return.
  *
  * @param  stdClass $entry   The entry.
  * @param  context  $context The context the entry belongs to.
  * @return void
  */
 protected static function fill_entry_details($entry, $context)
 {
     global $PAGE;
     $canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
     // Format concept and definition.
     $entry->concept = external_format_string($entry->concept, $context->id);
     list($entry->definition, $entry->definitionformat) = external_format_text($entry->definition, $entry->definitionformat, $context->id, 'mod_glossary', 'entry', $entry->id);
     // Author details.
     $user = mod_glossary_entry_query_builder::get_user_from_record($entry);
     $userpicture = new user_picture($user);
     $userpicture->size = 1;
     $entry->userfullname = fullname($user, $canviewfullnames);
     $entry->userpictureurl = $userpicture->get_url($PAGE)->out(false);
     // Fetch attachments.
     $entry->attachment = !empty($entry->attachment) ? 1 : 0;
     $entry->attachments = array();
     if ($entry->attachment) {
         $entry->attachments = external_util::get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);
     }
     $definitioninlinefiles = external_util::get_area_files($context->id, 'mod_glossary', 'entry', $entry->id);
     if (!empty($definitioninlinefiles)) {
         $entry->definitioninlinefiles = $definitioninlinefiles;
     }
 }
Esempio n. 4
0
 /**
  * Fill in an entry object.
  *
  * This adds additional required fields for the external function to return.
  *
  * @param  stdClass $entry   The entry.
  * @param  context  $context The context the entry belongs to.
  * @return void
  */
 protected static function fill_entry_details($entry, $context)
 {
     global $PAGE;
     $canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
     // Format concept and definition.
     $entry->concept = external_format_string($entry->concept, $context->id);
     list($entry->definition, $entry->definitionformat) = external_format_text($entry->definition, $entry->definitionformat, $context->id, 'mod_glossary', 'entry', $entry->id);
     // Author details.
     $user = mod_glossary_entry_query_builder::get_user_from_record($entry);
     $userpicture = new user_picture($user);
     $userpicture->size = 1;
     $entry->userfullname = fullname($user, $canviewfullnames);
     $entry->userpictureurl = $userpicture->get_url($PAGE)->out(false);
     // Fetch attachments.
     $entry->attachment = !empty($entry->attachment) ? 1 : 0;
     $entry->attachments = array();
     if ($entry->attachment) {
         $fs = get_file_storage();
         if ($files = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id, 'filename', false)) {
             foreach ($files as $file) {
                 $filename = $file->get_filename();
                 $fileurl = moodle_url::make_webservice_pluginfile_url($context->id, 'mod_glossary', 'attachment', $entry->id, '/', $filename);
                 $entry->attachments[] = array('filename' => $filename, 'mimetype' => $file->get_mimetype(), 'fileurl' => $fileurl->out(false));
             }
         }
     }
 }