[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/blocks/lp/classes/output/ -> summary.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   * Summary renderable.
  19   *
  20   * @package    block_lp
  21   * @copyright  2016 Frédéric Massart - FMCorz.net
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace block_lp\output;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  use core_competency\api;
  29  use core_competency\external\competency_exporter;
  30  use core_competency\external\plan_exporter;
  31  use core_competency\external\user_competency_exporter;
  32  use core_competency\external\user_summary_exporter;
  33  use core_competency\plan;
  34  use core_competency\url;
  35  use renderable;
  36  use renderer_base;
  37  use templatable;
  38  
  39  /**
  40   * Summary renderable class.
  41   *
  42   * @package    block_lp
  43   * @copyright  2016 Frédéric Massart - FMCorz.net
  44   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  45   */
  46  class summary implements renderable, templatable {
  47  
  48      /** @var array Active plans. */
  49      protected $activeplans = array();
  50      /** @var array Competencies to review. */
  51      protected $compstoreview = array();
  52      /** @var array Plans to review. */
  53      protected $planstoreview = array();
  54      /** @var array Plans. */
  55      protected $plans = array();
  56      /** @var stdClass The user. */
  57      protected $user;
  58  
  59      /**
  60       * Constructor.
  61       * @param stdClass $user The user.
  62       */
  63      public function __construct($user = null) {
  64          global $USER;
  65          if (!$user) {
  66              $user = $USER;
  67          }
  68          $this->user = $user;
  69  
  70          // Get the plans.
  71          $this->plans = api::list_user_plans($this->user->id);
  72  
  73          // Get the competencies to review.
  74          $this->compstoreview = api::list_user_competencies_to_review(0, 3);
  75  
  76          // Get the plans to review.
  77          $this->planstoreview = api::list_plans_to_review(0, 3);
  78      }
  79  
  80      public function export_for_template(renderer_base $output) {
  81          $plans = array();
  82          foreach ($this->plans as $plan) {
  83              if (count($plans) >= 3) {
  84                  break;
  85              }
  86              if ($plan->get_status() == plan::STATUS_ACTIVE) {
  87                  $plans[] = $plan;
  88              }
  89          }
  90          $activeplans = array();
  91          foreach ($plans as $plan) {
  92              $planexporter = new plan_exporter($plan, array('template' => $plan->get_template()));
  93              $activeplans[] = $planexporter->export($output);
  94          }
  95  
  96          $compstoreview = array();
  97          foreach ($this->compstoreview['competencies'] as $compdata) {
  98              $ucexporter = new user_competency_exporter($compdata->usercompetency,
  99                  array('scale' => $compdata->competency->get_scale()));
 100              $compexporter = new competency_exporter($compdata->competency,
 101                  array('context' => $compdata->competency->get_context()));
 102              $userexporter = new user_summary_exporter($compdata->user);
 103              $compstoreview[] = array(
 104                  'usercompetency' => $ucexporter->export($output),
 105                  'competency' => $compexporter->export($output),
 106                  'user' => $userexporter->export($output),
 107              );
 108          }
 109  
 110          $planstoreview = array();
 111          foreach ($this->planstoreview['plans'] as $plandata) {
 112              $planexporter = new plan_exporter($plandata->plan, array('template' => $plandata->template));
 113              $userexporter = new user_summary_exporter($plandata->owner);
 114              $planstoreview[] = array(
 115                  'plan' => $planexporter->export($output),
 116                  'user' => $userexporter->export($output),
 117              );
 118          }
 119  
 120          $data = array(
 121              'hasplans' => !empty($this->plans),
 122              'hasactiveplans' => !empty($activeplans),
 123              'hasmoreplans' => count($this->plans) > count($activeplans),
 124              'activeplans' => $activeplans,
 125  
 126              'compstoreview' => $compstoreview,
 127              'hascompstoreview' => $this->compstoreview['count'] > 0,
 128              'hasmorecompstoreview' => $this->compstoreview['count'] > 3,
 129  
 130              'planstoreview' => $planstoreview,
 131              'hasplanstoreview' => $this->planstoreview['count'] > 0,
 132              'hasmoreplanstoreview' => $this->planstoreview['count'] > 3,
 133  
 134              'plansurl' => url::plans($this->user->id)->out(false),
 135              'pluginbaseurl' => (new \moodle_url('/blocks/lp'))->out(false),
 136              'userid' => $this->user->id,
 137          );
 138  
 139          return $data;
 140      }
 141  
 142      /**
 143       * Returns whether there is content in the summary.
 144       *
 145       * @return boolean
 146       */
 147      public function has_content() {
 148          return !empty($this->plans) || $this->planstoreview['count'] > 0 || $this->compstoreview['count'] > 0;
 149      }
 150  
 151  }


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