Search moodle.org's
Developer Documentation

   1  <?php
   2  
   3  global $CFG;
   4  
   5  require_once("../../config.php");
   6  require_once ("lib.php");
   7  
   8  $id            = required_param('id', PARAM_INT);                     // Course Module ID
   9  $sortorder     = optional_param('sortorder', 'asc', PARAM_ALPHA);     // Sorting order
  10  $offset        = optional_param('offset', 0, PARAM_INT);              // number of entries to bypass
  11  $displayformat = optional_param('displayformat',-1, PARAM_INT);
  12  
  13  $mode    = required_param('mode', PARAM_ALPHA);             // mode to show the entries
  14  $hook    = optional_param('hook','ALL', PARAM_CLEAN);       // what to show
  15  $sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA); // Sorting key
  16  
  17  $url = new moodle_url('/mod/glossary/print.php', array('id'=>$id));
  18  if ($sortorder !== 'asc') {
  19      $url->param('sortorder', $sortorder);
  20  }
  21  if ($offset !== 0) {
  22      $url->param('offset', $offset);
  23  }
  24  if ($displayformat !== -1) {
  25      $url->param('displayformat', $displayformat);
  26  }
  27  if ($sortkey !== 'UPDATE') {
  28      $url->param('sortkey', $sortkey);
  29  }
  30  if ($mode !== 'letter') {
  31      $url->param('mode', $mode);
  32  }
  33  if ($hook !== 'ALL') {
  34      $url->param('hook', $hook);
  35  }
  36  $PAGE->set_url($url);
  37  
  38  if (! $cm = get_coursemodule_from_id('glossary', $id)) {
  39      print_error('invalidcoursemodule');
  40  }
  41  
  42  if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
  43      print_error('coursemisconf');
  44  }
  45  
  46  if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
  47      print_error('invalidid', 'glossary');
  48  }
  49  
  50  if ( !$entriesbypage = $glossary->entbypage ) {
  51      $entriesbypage = $CFG->glossary_entbypage;
  52  }
  53  
  54  require_course_login($course, true, $cm);
  55  $context = context_module::instance($cm->id);
  56  
  57  // Prepare format_string/text options
  58  $fmtoptions = array(
  59      'context' => $context);
  60  
  61  $PAGE->set_pagelayout('print');
  62  $PAGE->set_title(get_string("modulenameplural", "glossary"));
  63  $PAGE->set_heading($course->fullname);
  64  echo $OUTPUT->header();
  65  
  66  if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) {
  67      notice(get_string('printviewnotallowed', 'glossary'));
  68  }
  69  
  70  /// setting the default values for the display mode of the current glossary
  71  /// only if the glossary is viewed by the first time
  72  if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
  73      $printpivot = $dp->showgroup;
  74      if ( $mode == '' and $hook == '' and $show == '') {
  75          $mode      = $dp->defaultmode;
  76          $hook      = $dp->defaulthook;
  77          $sortkey   = $dp->sortkey;
  78          $sortorder = $dp->sortorder;
  79      }
  80  } else {
  81      $printpivot = 1;
  82      if ( $mode == '' and $hook == '' and $show == '') {
  83          $mode = 'letter';
  84          $hook = 'ALL';
  85      }
  86  }
  87  
  88  if ( $displayformat == -1 ) {
  89       $displayformat = $glossary->displayformat;
  90  }
  91  
  92  /// stablishing flag variables
  93  if ( $sortorder = strtolower($sortorder) ) {
  94      if ($sortorder != 'asc' and $sortorder != 'desc') {
  95          $sortorder = '';
  96      }
  97  }
  98  if ( $sortkey = strtoupper($sortkey) ) {
  99      if ($sortkey != 'CREATION' and
 100          $sortkey != 'UPDATE' and
 101          $sortkey != 'FIRSTNAME' and
 102          $sortkey != 'LASTNAME'
 103          ) {
 104          $sortkey = '';
 105      }
 106  }
 107  
 108  switch ( $mode = strtolower($mode) ) {
 109  case 'entry':  /// Looking for a certain entry id
 110      $tab = GLOSSARY_STANDARD_VIEW;
 111  break;
 112  
 113  case 'cat':    /// Looking for a certain cat
 114      $tab = GLOSSARY_CATEGORY_VIEW;
 115      if ( $hook > 0 ) {
 116          $category = $DB->get_record("glossary_categories", array("id"=>$hook));
 117      }
 118  break;
 119  
 120  case 'approval':    /// Looking for entries waiting for approval
 121      $tab = GLOSSARY_APPROVAL_VIEW;
 122      if ( !$hook and !$sortkey and !$sortorder) {
 123          $hook = 'ALL';
 124      }
 125  break;
 126  
 127  case 'term':   /// Looking for entries that include certain term in its concept, definition or aliases
 128      $tab = GLOSSARY_STANDARD_VIEW;
 129  break;
 130  
 131  case 'date':
 132      $tab = GLOSSARY_DATE_VIEW;
 133      if ( !$sortkey ) {
 134          $sortkey = 'UPDATE';
 135      }
 136      if ( !$sortorder ) {
 137          $sortorder = 'desc';
 138      }
 139  break;
 140  
 141  case 'author':  /// Looking for entries, browsed by author
 142      $tab = GLOSSARY_AUTHOR_VIEW;
 143      if ( !$hook ) {
 144          $hook = 'ALL';
 145      }
 146      if ( !$sortkey ) {
 147          $sortkey = 'FIRSTNAME';
 148      }
 149      if ( !$sortorder ) {
 150          $sortorder = 'asc';
 151      }
 152  break;
 153  
 154  case 'letter':  /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
 155  default:
 156      $tab = GLOSSARY_STANDARD_VIEW;
 157      if ( !$hook ) {
 158          $hook = 'ALL';
 159      }
 160  break;
 161  }
 162  
 163  include_once ("sql.php");
 164  
 165  $entriesshown = 0;
 166  $currentpivot = '';
 167  
 168  $site = $DB->get_record("course", array("id"=>1));
 169  
 170  // Print dialog link.
 171  $printtext = get_string('print', 'glossary');
 172  $printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'glossary_no_print printicon');
 173  $printiconlink = html_writer::link('#', $printtext, $printlinkatt);
 174  echo  html_writer::tag('div', $printiconlink, array('class' => 'displayprinticon'));
 175  
 176  echo html_writer::tag('div', userdate(time()), array('class' => 'displaydate'));
 177  
 178  $sitename = get_string("site") . ': <span class="strong">' . format_string($site->fullname) . '</span>';
 179  echo html_writer::tag('div', $sitename, array('class' => 'sitename'));
 180  
 181  $coursename = get_string("course") . ': <span class="strong">' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</span>';
 182  echo html_writer::tag('div', $coursename, array('class' => 'coursename'));
 183  
 184  $modname = get_string("modulename","glossary") . ': <span class="strong">' . format_string($glossary->name, true) . '</span>';
 185  echo html_writer::tag('div', $modname, array('class' => 'modname'));
 186  
 187  if ( $allentries ) {
 188      foreach ($allentries as $entry) {
 189  
 190          // Setting the pivot for the current entry
 191          $pivot = $entry->glossarypivot;
 192          $upperpivot = core_text::strtoupper($pivot);
 193          $pivottoshow = core_text::strtoupper(format_string($pivot, true, $fmtoptions));
 194          // Reduce pivot to 1cc if necessary
 195          if ( !$fullpivot ) {
 196              $upperpivot = core_text::substr($upperpivot, 0, 1);
 197              $pivottoshow = core_text::substr($pivottoshow, 0, 1);
 198          }
 199  
 200          // If there's  group break
 201          if ( $currentpivot != $upperpivot ) {
 202  
 203              // print the group break if apply
 204              if ( $printpivot )  {
 205                  $currentpivot = $upperpivot;
 206  
 207                  if ( isset($entry->userispivot) ) {
 208                      // printing the user icon if defined (only when browsing authors)
 209                      $user = $DB->get_record("user", array("id"=>$entry->userid));
 210                      $pivottoshow = fullname($user);
 211                  }
 212                  echo html_writer::tag('div', clean_text($pivottoshow), array('class' => 'mdl-align strong'));
 213              }
 214          }
 215  
 216          glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook, 1, $displayformat, true);
 217      }
 218  }
 219  
 220  echo $OUTPUT->footer();

Search This Site: