[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/lp/classes/output/ -> manage_competencies_page.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   * Class containing data for managecompetencyframeworks page
  19   *
  20   * @package    tool_lp
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace tool_lp\output;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use renderable;
  28  use templatable;
  29  use renderer_base;
  30  use single_button;
  31  use stdClass;
  32  use moodle_url;
  33  use context_system;
  34  use core_competency\api;
  35  use core_competency\competency;
  36  use core_competency\competency_framework;
  37  use core_competency\external\competency_framework_exporter;
  38  
  39  /**
  40   * Class containing data for managecompetencies page
  41   *
  42   * @copyright  2015 Damyon Wiese
  43   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  44   */
  45  class manage_competencies_page implements renderable, templatable {
  46  
  47      /** @var \core_competency\competency_framework $framework This competency framework. */
  48      protected $framework = null;
  49  
  50      /** @var \core_competency\competency[] $competencies List of competencies. */
  51      protected $competencies = array();
  52  
  53      /** @var string $search Text to search for. */
  54      protected $search = '';
  55  
  56      /** @var bool $canmanage Result of permissions checks. */
  57      protected $canmanage = false;
  58  
  59      /** @var moodle_url $pluginurlbase Base url to use constructing links. */
  60      protected $pluginbaseurl = null;
  61  
  62      /** @var context $pagecontext The page context. */
  63      protected $pagecontext = null;
  64  
  65      /**
  66       * Construct this renderable.
  67       *
  68       * @param \core_competency\competency_framework $framework Competency framework.
  69       * @param string $search Search string.
  70       * @param context $pagecontext The page context.
  71       */
  72      public function __construct($framework, $search, $pagecontext) {
  73          $this->framework = $framework;
  74          $this->pagecontext = $pagecontext;
  75          $this->search = $search;
  76          $addpage = new single_button(
  77             new moodle_url('/admin/tool/lp/editcompetencyframework.php'),
  78             get_string('addnewcompetency', 'tool_lp')
  79          );
  80          $this->navigation[] = $addpage;
  81  
  82          $this->canmanage = has_capability('moodle/competency:competencymanage', $framework->get_context());
  83      }
  84  
  85      /**
  86       * Export this data so it can be used as the context for a mustache template.
  87       *
  88       * @param renderer_base $output Renderer base.
  89       * @return stdClass
  90       */
  91      public function export_for_template(renderer_base $output) {
  92          $data = new stdClass();
  93          $exporter = new competency_framework_exporter($this->framework);
  94          $data->framework = $exporter->export($output);
  95          $data->canmanage = $this->canmanage;
  96          $data->search = $this->search;
  97          $data->pagecontextid = $this->pagecontext->id;
  98          $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
  99  
 100          $rulesmodules = array();
 101          $rules = competency::get_available_rules();
 102          foreach ($rules as $type => $rulename) {
 103  
 104              $amd = null;
 105              if ($type == 'core_competency\\competency_rule_all') {
 106                  $amd = 'tool_lp/competency_rule_all';
 107              } else if ($type == 'core_competency\\competency_rule_points') {
 108                  $amd = 'tool_lp/competency_rule_points';
 109              } else {
 110                  // We do not know how to display that rule.
 111                  continue;
 112              }
 113  
 114              $rulesmodules[] = [
 115                  'name' => (string) $rulename,
 116                  'type' => $type,
 117                  'amd' => $amd,
 118              ];
 119          }
 120          $data->rulesmodules = json_encode(array_values($rulesmodules));
 121  
 122          return $data;
 123      }
 124  }


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