[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/enrol/lti/classes/ -> manage_table.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   * Displays enrolment LTI instances.
  19   *
  20   * @package    enrol_lti
  21   * @copyright  2016 Mark Nelson <markn@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace enrol_lti;
  26  
  27  defined('MOODLE_INTERNAL') || die;
  28  
  29  global $CFG;
  30  
  31  require_once($CFG->libdir . '/tablelib.php');
  32  
  33  /**
  34   * Handles displaying enrolment LTI instances.
  35   *
  36   * @package    enrol_lti
  37   * @copyright  2016 Mark Nelson <markn@moodle.com>
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class manage_table extends \table_sql {
  41  
  42      /**
  43       * @var \enrol_plugin $ltiplugin
  44       */
  45      protected $ltiplugin;
  46  
  47      /**
  48       * @var bool $ltienabled
  49       */
  50      protected $ltienabled;
  51  
  52      /**
  53       * @var bool $canconfig
  54       */
  55      protected $canconfig;
  56  
  57      /**
  58       * @var int $courseid The course id.
  59       */
  60      protected $courseid;
  61  
  62      /**
  63       * Sets up the table.
  64       *
  65       * @param string $courseid The id of the course.
  66       */
  67      public function __construct($courseid) {
  68          parent::__construct('enrol_lti_manage_table');
  69  
  70          $this->define_columns(array(
  71              'name',
  72              'url',
  73              'secret',
  74              'edit'
  75          ));
  76          $this->define_headers(array(
  77              get_string('name'),
  78              get_string('url'),
  79              get_string('secret', 'enrol_lti'),
  80              get_string('edit')
  81          ));
  82          $this->collapsible(false);
  83          $this->sortable(false);
  84  
  85          // Set the variables we need access to.
  86          $this->ltiplugin = enrol_get_plugin('lti');
  87          $this->ltienabled = enrol_is_enabled('lti');
  88          $this->canconfig = has_capability('moodle/course:enrolconfig', \context_course::instance($courseid));
  89          $this->courseid = $courseid;
  90      }
  91  
  92      /**
  93       * Generate the name column.
  94       *
  95       * @param \stdClass $tool event data.
  96       * @return string
  97       */
  98      public function col_name($tool) {
  99          if (empty($tool->name)) {
 100              $toolcontext = \context::instance_by_id($tool->contextid);
 101              $name = $toolcontext->get_context_name();
 102          } else {
 103              $name = $tool->name;
 104          };
 105  
 106          return $this->get_display_text($tool, $name);
 107      }
 108  
 109      /**
 110       * Generate the URL column.
 111       *
 112       * @param \stdClass $tool event data.
 113       * @return string
 114       */
 115      public function col_url($tool) {
 116          $url = new \moodle_url('/enrol/lti/tool.php', array('id' => $tool->id));
 117          return $this->get_display_text($tool, $url);
 118      }
 119  
 120      /**
 121       * Generate the secret column.
 122       *
 123       * @param \stdClass $tool event data.
 124       * @return string
 125       */
 126      public function col_secret($tool) {
 127          return $this->get_display_text($tool, $tool->secret);
 128      }
 129  
 130  
 131      /**
 132       * Generate the edit column.
 133       *
 134       * @param \stdClass $tool event data.
 135       * @return string
 136       */
 137      public function col_edit($tool) {
 138          global $OUTPUT;
 139  
 140          $buttons = array();
 141  
 142          $instance = new \stdClass();
 143          $instance->id = $tool->enrolid;
 144          $instance->courseid = $tool->courseid;
 145          $instance->enrol = 'lti';
 146          $instance->status = $tool->status;
 147  
 148          $strdelete = get_string('delete');
 149          $strenable = get_string('enable');
 150          $strdisable = get_string('disable');
 151  
 152          $url = new \moodle_url('/enrol/lti/index.php', array('sesskey' => sesskey(), 'courseid' => $this->courseid));
 153  
 154          if ($this->ltiplugin->can_delete_instance($instance)) {
 155              $aurl = new \moodle_url($url, array('action' => 'delete', 'instanceid' => $instance->id));
 156              $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/delete', $strdelete, 'core',
 157                  array('class' => 'iconsmall')));
 158          }
 159  
 160          if ($this->ltienabled && $this->ltiplugin->can_hide_show_instance($instance)) {
 161              if ($instance->status == ENROL_INSTANCE_ENABLED) {
 162                  $aurl = new \moodle_url($url, array('action' => 'disable', 'instanceid' => $instance->id));
 163                  $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/hide', $strdisable, 'core',
 164                      array('class' => 'iconsmall')));
 165              } else if ($instance->status == ENROL_INSTANCE_DISABLED) {
 166                  $aurl = new \moodle_url($url, array('action' => 'enable', 'instanceid' => $instance->id));
 167                  $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/show', $strenable, 'core',
 168                      array('class' => 'iconsmall')));
 169              }
 170          }
 171  
 172          if ($this->ltienabled && $this->canconfig) {
 173              $linkparams = array(
 174                  'courseid' => $instance->courseid,
 175                  'id' => $instance->id, 'type' => $instance->enrol,
 176                  'returnurl' => new \moodle_url('/enrol/lti/index.php', array('courseid' => $this->courseid))
 177              );
 178              $editlink = new \moodle_url("/enrol/editinstance.php", $linkparams);
 179              $buttons[] = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit'), 'core',
 180                  array('class' => 'iconsmall')));
 181          }
 182  
 183          return implode(' ', $buttons);
 184      }
 185  
 186      /**
 187       * Query the reader. Store results in the object for use by build_table.
 188       *
 189       * @param int $pagesize size of page for paginated displayed table.
 190       * @param bool $useinitialsbar do you want to use the initials bar.
 191       */
 192      public function query_db($pagesize, $useinitialsbar = true) {
 193          $total = \enrol_lti\helper::count_lti_tools(array('courseid' => $this->courseid));
 194          $this->pagesize($pagesize, $total);
 195          $tools = \enrol_lti\helper::get_lti_tools(array('courseid' => $this->courseid), $this->get_page_start(),
 196              $this->get_page_size());
 197          $this->rawdata = $tools;
 198          // Set initial bars.
 199          if ($useinitialsbar) {
 200              $this->initialbars($total > $pagesize);
 201          }
 202      }
 203  
 204      /**
 205       * Returns text to display in the columns.
 206       *
 207       * @param \stdClass $tool the tool
 208       * @param string $text the text to alter
 209       * @return string
 210       */
 211      protected function get_display_text($tool, $text) {
 212          if ($tool->status != ENROL_INSTANCE_ENABLED) {
 213              return \html_writer::tag('span', $text, array('class' => 'dimmed_text'));
 214          }
 215  
 216          return $text;
 217      }
 218  }


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