[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/data/ -> index.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * This file is part of the Database module for Moodle
  20   *
  21   * @copyright 1990 Martin Dougiamas  http://dougiamas.com
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   * @package mod_data
  24   */
  25  
  26  require_once("../../config.php");
  27  require_once ("lib.php");
  28  
  29  $id = required_param('id', PARAM_INT);   // course
  30  
  31  $PAGE->set_url('/mod/data/index.php', array('id'=>$id));
  32  
  33  if (!$course = $DB->get_record('course', array('id'=>$id))) {
  34      print_error('invalidcourseid');
  35  }
  36  
  37  require_course_login($course);
  38  $PAGE->set_pagelayout('incourse');
  39  
  40  $context = context_course::instance($course->id);
  41  
  42  $params = array(
  43      'context' => context_course::instance($course->id)
  44  );
  45  $event = \mod_data\event\course_module_instance_list_viewed::create($params);
  46  $event->add_record_snapshot('course', $course);
  47  $event->trigger();
  48  
  49  $strname = get_string('name');
  50  $strdata = get_string('modulename','data');
  51  $strdataplural  = get_string('modulenameplural','data');
  52  
  53  $PAGE->navbar->add($strdata, new moodle_url('/mod/data/index.php', array('id'=>$course->id)));
  54  $PAGE->set_title($strdata);
  55  $PAGE->set_heading($course->fullname);
  56  echo $OUTPUT->header();
  57  echo $OUTPUT->heading($strdataplural, 2);
  58  
  59  if (! $datas = get_all_instances_in_course("data", $course)) {
  60      notice(get_string('thereareno', 'moodle',$strdataplural) , "$CFG->wwwroot/course/view.php?id=$course->id");
  61  }
  62  
  63  $usesections = course_format_uses_sections($course->format);
  64  
  65  $timenow  = time();
  66  $strname  = get_string('name');
  67  $strdescription = get_string("description");
  68  $strentries = get_string('entries', 'data');
  69  $strnumnotapproved = get_string('numnotapproved', 'data');
  70  
  71  $table = new html_table();
  72  
  73  if ($usesections) {
  74      $strsectionname = get_string('sectionname', 'format_'.$course->format);
  75      $table->head  = array ($strsectionname, $strname, $strdescription, $strentries, $strnumnotapproved);
  76      $table->align = array ('center', 'center', 'center', 'center', 'center');
  77  } else {
  78      $table->head  = array ($strname, $strdescription, $strentries, $strnumnotapproved);
  79      $table->align = array ('center', 'center', 'center', 'center');
  80  }
  81  
  82  $rss = (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds));
  83  
  84  if ($rss) {
  85      require_once($CFG->libdir."/rsslib.php");
  86      array_push($table->head, 'RSS');
  87      array_push($table->align, 'center');
  88  }
  89  
  90  $options = new stdClass();
  91  $options->noclean = true;
  92  
  93  $currentsection = "";
  94  
  95  foreach ($datas as $data) {
  96  
  97      $printsection = "";
  98  
  99      //Calculate the href
 100      if (!$data->visible) {
 101          //Show dimmed if the mod is hidden
 102          $link = "<a class=\"dimmed\" href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
 103      } else {
 104          //Show normal if the mod is visible
 105          $link = "<a href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
 106      }
 107  
 108      // TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page
 109  
 110      $numrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =?', array($data->id));
 111  
 112      if ($data->approval == 1) {
 113          $numunapprovedrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =? AND r.approved <> 1', array($data->id));
 114      } else {
 115          $numunapprovedrecords = '-';
 116      }
 117  
 118      $rsslink = '';
 119      if ($rss && $data->rssarticles > 0) {
 120          $rsslink = rss_get_link($context->id, $USER->id, 'mod_data', $data->id, 'RSS');
 121      }
 122  
 123      if ($usesections) {
 124          if ($data->section !== $currentsection) {
 125              if ($data->section) {
 126                  $printsection = get_section_name($course, $data->section);
 127              }
 128              if ($currentsection !== '') {
 129                  $table->data[] = 'hr';
 130              }
 131              $currentsection = $data->section;
 132          }
 133          $row = array ($printsection, $link, format_text($data->intro, $data->introformat, $options), $numrecords, $numunapprovedrecords);
 134  
 135      } else {
 136          $row = array ($link, format_text($data->intro, $data->introformat, $options), $numrecords, $numunapprovedrecords);
 137      }
 138  
 139      if ($rss) {
 140          array_push($row, $rsslink);
 141      }
 142  
 143      $table->data[] = $row;
 144  }
 145  
 146  echo "<br />";
 147  echo html_writer::tag('div', html_writer::table($table), array('class'=>'no-overflow'));
 148  echo $OUTPUT->footer();
 149  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1