[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/cohort/ -> index.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Cohort related management functions, this file needs to be included manually.
  19   *
  20   * @package    core_cohort
  21   * @copyright  2010 Petr Skoda  {@link http://skodak.org}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require('../config.php');
  26  require($CFG->dirroot.'/cohort/lib.php');
  27  require_once($CFG->libdir.'/adminlib.php');
  28  
  29  $contextid = optional_param('contextid', 0, PARAM_INT);
  30  $page = optional_param('page', 0, PARAM_INT);
  31  $searchquery  = optional_param('search', '', PARAM_RAW);
  32  $showall = optional_param('showall', false, PARAM_BOOL);
  33  
  34  require_login();
  35  
  36  if ($contextid) {
  37      $context = context::instance_by_id($contextid, MUST_EXIST);
  38  } else {
  39      $context = context_system::instance();
  40  }
  41  
  42  if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
  43      print_error('invalidcontext');
  44  }
  45  
  46  $category = null;
  47  if ($context->contextlevel == CONTEXT_COURSECAT) {
  48      $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
  49  }
  50  
  51  $manager = has_capability('moodle/cohort:manage', $context);
  52  $canassign = has_capability('moodle/cohort:assign', $context);
  53  if (!$manager) {
  54      require_capability('moodle/cohort:view', $context);
  55  }
  56  
  57  $strcohorts = get_string('cohorts', 'cohort');
  58  
  59  if ($category) {
  60      $PAGE->set_pagelayout('admin');
  61      $PAGE->set_context($context);
  62      $PAGE->set_url('/cohort/index.php', array('contextid'=>$context->id));
  63      $PAGE->set_title($strcohorts);
  64      $PAGE->set_heading($COURSE->fullname);
  65      $showall = false;
  66  } else {
  67      admin_externalpage_setup('cohorts', '', null, '', array('pagelayout'=>'report'));
  68  }
  69  
  70  echo $OUTPUT->header();
  71  
  72  if ($showall) {
  73      $cohorts = cohort_get_all_cohorts($page, 25, $searchquery);
  74  } else {
  75      $cohorts = cohort_get_cohorts($context->id, $page, 25, $searchquery);
  76  }
  77  
  78  $count = '';
  79  if ($cohorts['allcohorts'] > 0) {
  80      if ($searchquery === '') {
  81          $count = ' ('.$cohorts['allcohorts'].')';
  82      } else {
  83          $count = ' ('.$cohorts['totalcohorts'].'/'.$cohorts['allcohorts'].')';
  84      }
  85  }
  86  
  87  echo $OUTPUT->heading(get_string('cohortsin', 'cohort', $context->get_context_name()).$count);
  88  
  89  $params = array('page' => $page);
  90  if ($contextid) {
  91      $params['contextid'] = $contextid;
  92  }
  93  if ($searchquery) {
  94      $params['search'] = $searchquery;
  95  }
  96  if ($showall) {
  97      $params['showall'] = true;
  98  }
  99  $baseurl = new moodle_url('/cohort/index.php', $params);
 100  
 101  if ($editcontrols = cohort_edit_controls($context, $baseurl)) {
 102      echo $OUTPUT->render($editcontrols);
 103  }
 104  
 105  // Add search form.
 106  $search  = html_writer::start_tag('form', array('id'=>'searchcohortquery', 'method'=>'get'));
 107  $search .= html_writer::start_tag('div');
 108  $search .= html_writer::label(get_string('searchcohort', 'cohort'), 'cohort_search_q'); // No : in form labels!
 109  $search .= html_writer::empty_tag('input', array('id'=>'cohort_search_q', 'type'=>'text', 'name'=>'search', 'value'=>$searchquery));
 110  $search .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('search', 'cohort')));
 111  $search .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'contextid', 'value'=>$contextid));
 112  $search .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'showall', 'value'=>$showall));
 113  $search .= html_writer::end_tag('div');
 114  $search .= html_writer::end_tag('form');
 115  echo $search;
 116  
 117  // Output pagination bar.
 118  echo $OUTPUT->paging_bar($cohorts['totalcohorts'], $page, 25, $baseurl);
 119  
 120  $data = array();
 121  $editcolumnisempty = true;
 122  foreach($cohorts['cohorts'] as $cohort) {
 123      $line = array();
 124      $cohortcontext = context::instance_by_id($cohort->contextid);
 125      $cohort->description = file_rewrite_pluginfile_urls($cohort->description, 'pluginfile.php', $cohortcontext->id,
 126              'cohort', 'description', $cohort->id);
 127      if ($showall) {
 128          if ($cohortcontext->contextlevel == CONTEXT_COURSECAT) {
 129              $line[] = html_writer::link(new moodle_url('/cohort/index.php' ,
 130                      array('contextid' => $cohort->contextid)), $cohortcontext->get_context_name(false));
 131          } else {
 132              $line[] = $cohortcontext->get_context_name(false);
 133          }
 134      }
 135      $tmpl = new \core_cohort\output\cohortname($cohort);
 136      $line[] = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT));
 137      $tmpl = new \core_cohort\output\cohortidnumber($cohort);
 138      $line[] = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT));
 139      $line[] = format_text($cohort->description, $cohort->descriptionformat);
 140  
 141      $line[] = $DB->count_records('cohort_members', array('cohortid'=>$cohort->id));
 142  
 143      if (empty($cohort->component)) {
 144          $line[] = get_string('nocomponent', 'cohort');
 145      } else {
 146          $line[] = get_string('pluginname', $cohort->component);
 147      }
 148  
 149      $buttons = array();
 150      if (empty($cohort->component)) {
 151          $cohortmanager = has_capability('moodle/cohort:manage', $cohortcontext);
 152          $cohortcanassign = has_capability('moodle/cohort:assign', $cohortcontext);
 153  
 154          $urlparams = array('id' => $cohort->id, 'returnurl' => $baseurl->out_as_local_url());
 155          $showhideurl = new moodle_url('/cohort/edit.php', $urlparams + array('sesskey' => sesskey()));
 156          if ($cohortmanager) {
 157              if ($cohort->visible) {
 158                  $showhideurl->param('hide', 1);
 159                  $visibleimg = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/hide'), 'alt' => get_string('hide'), 'class' => 'iconsmall'));
 160                  $buttons[] = html_writer::link($showhideurl, $visibleimg, array('title' => get_string('hide')));
 161              } else {
 162                  $showhideurl->param('show', 1);
 163                  $visibleimg = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/show'), 'alt' => get_string('show'), 'class' => 'iconsmall'));
 164                  $buttons[] = html_writer::link($showhideurl, $visibleimg, array('title' => get_string('show')));
 165              }
 166              $buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', $urlparams + array('delete' => 1)),
 167                  html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall')),
 168                  array('title' => get_string('delete')));
 169              $buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', $urlparams),
 170                  html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall')),
 171                  array('title' => get_string('edit')));
 172              $editcolumnisempty = false;
 173          }
 174          if ($cohortcanassign) {
 175              $buttons[] = html_writer::link(new moodle_url('/cohort/assign.php', $urlparams),
 176                  html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/users'), 'alt' => get_string('assign', 'core_cohort'), 'class' => 'iconsmall')),
 177                  array('title' => get_string('assign', 'core_cohort')));
 178              $editcolumnisempty = false;
 179          }
 180      }
 181      $line[] = implode(' ', $buttons);
 182  
 183      $data[] = $row = new html_table_row($line);
 184      if (!$cohort->visible) {
 185          $row->attributes['class'] = 'dimmed_text';
 186      }
 187  }
 188  $table = new html_table();
 189  $table->head  = array(get_string('name', 'cohort'), get_string('idnumber', 'cohort'), get_string('description', 'cohort'),
 190                        get_string('memberscount', 'cohort'), get_string('component', 'cohort'));
 191  $table->colclasses = array('leftalign name', 'leftalign id', 'leftalign description', 'leftalign size','centeralign source');
 192  if ($showall) {
 193      array_unshift($table->head, get_string('category'));
 194      array_unshift($table->colclasses, 'leftalign category');
 195  }
 196  if (!$editcolumnisempty) {
 197      $table->head[] = get_string('edit');
 198      $table->colclasses[] = 'centeralign action';
 199  } else {
 200      // Remove last column from $data.
 201      foreach ($data as $row) {
 202          array_pop($row->cells);
 203      }
 204  }
 205  $table->id = 'cohorts';
 206  $table->attributes['class'] = 'admintable generaltable';
 207  $table->data  = $data;
 208  echo html_writer::table($table);
 209  echo $OUTPUT->paging_bar($cohorts['totalcohorts'], $page, 25, $baseurl);
 210  echo $OUTPUT->footer();


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