[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/competency/classes/external/ -> plan_exporter.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 for exporting plan data.
  19   *
  20   * @package    core_competency
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core_competency\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use core_user;
  28  use renderer_base;
  29  use stdClass;
  30  use moodle_url;
  31  use core_competency\url;
  32  
  33  /**
  34   * Class for exporting plan data.
  35   *
  36   * @copyright  2015 Damyon Wiese
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class plan_exporter extends persistent_exporter {
  40  
  41      protected static function define_class() {
  42          return 'core_competency\\plan';
  43      }
  44  
  45      protected static function define_related() {
  46          return array('template' => 'core_competency\\template?');
  47      }
  48  
  49      protected function get_other_values(renderer_base $output) {
  50          $classname = static::define_class();
  51          $status = $this->persistent->get_status();
  52  
  53          $values = new stdClass();
  54  
  55          $values->statusname = $this->persistent->get_statusname();
  56          $values->isbasedontemplate = $this->persistent->is_based_on_template();
  57  
  58          $values->canmanage = $this->persistent->can_manage();
  59          $values->canrequestreview = $this->persistent->can_request_review();
  60          $values->canreview = $this->persistent->can_review();
  61          $values->canbeedited = $this->persistent->can_be_edited();
  62  
  63          $values->isactive = $status == $classname::STATUS_ACTIVE;
  64          $values->isdraft = $status == $classname::STATUS_DRAFT;
  65          $values->iscompleted = $status == $classname::STATUS_COMPLETE;
  66          $values->isinreview = $status == $classname::STATUS_IN_REVIEW;
  67          $values->iswaitingforreview = $status == $classname::STATUS_WAITING_FOR_REVIEW;
  68  
  69          $values->isreopenallowed = $values->canmanage && $values->iscompleted;
  70          $values->iscompleteallowed = $values->canmanage && $values->isactive;
  71          $values->isunlinkallowed = $values->canmanage && !$values->iscompleted && $values->isbasedontemplate;
  72  
  73          $values->isrequestreviewallowed = false;
  74          $values->iscancelreviewrequestallowed = false;
  75          $values->isstartreviewallowed = false;
  76          $values->isstopreviewallowed = false;
  77          $values->isapproveallowed = false;
  78          $values->isunapproveallowed = false;
  79          if (!$values->isbasedontemplate) {
  80              $values->isrequestreviewallowed = $values->canrequestreview && $values->isdraft;
  81              $values->iscancelreviewrequestallowed = $values->canrequestreview && $values->iswaitingforreview;
  82              $values->isstartreviewallowed = $values->canreview && $values->iswaitingforreview;
  83              $values->isstopreviewallowed = $values->canreview && $values->isinreview;
  84              $values->isapproveallowed = $values->canreview && !$values->iscompleted && !$values->isactive;
  85              $values->isunapproveallowed = $values->canreview && $values->isactive;
  86          }
  87  
  88          $values->duedateformatted = userdate($this->persistent->get_duedate());
  89  
  90          if ($this->persistent->is_based_on_template()) {
  91              $exporter = new template_exporter($this->related['template']);
  92              $values->template = $exporter->export($output);
  93          }
  94  
  95          if (!empty($values->isinreview)) {
  96              // TODO Make this more efficient.
  97              $userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get_reviewerid(), '*', MUST_EXIST));
  98              $values->reviewer = $userexporter->export($output);
  99          }
 100  
 101          $commentareaexporter = new comment_area_exporter($this->persistent->get_comment_object());
 102          $values->commentarea = $commentareaexporter->export($output);
 103          $values->url = url::plan($this->persistent->get_id())->out(false);
 104  
 105          return (array) $values;
 106      }
 107  
 108      public static function define_other_properties() {
 109          return array(
 110              'statusname' => array(
 111                  'type' => PARAM_RAW,
 112              ),
 113              'isbasedontemplate' => array(
 114                  'type' => PARAM_BOOL,
 115              ),
 116              'canmanage' => array(
 117                  'type' => PARAM_BOOL,
 118              ),
 119              'canrequestreview' => array(
 120                  'type' => PARAM_BOOL,
 121              ),
 122              'canreview' => array(
 123                  'type' => PARAM_BOOL,
 124              ),
 125              'canbeedited' => array(
 126                  'type' => PARAM_BOOL,
 127              ),
 128              'isactive' => array(
 129                  'type' => PARAM_BOOL
 130              ),
 131              'isdraft' => array(
 132                  'type' => PARAM_BOOL
 133              ),
 134              'iscompleted' => array(
 135                  'type' => PARAM_BOOL
 136              ),
 137              'isinreview' => array(
 138                  'type' => PARAM_BOOL
 139              ),
 140              'iswaitingforreview' => array(
 141                  'type' => PARAM_BOOL
 142              ),
 143              'isreopenallowed' => array(
 144                  'type' => PARAM_BOOL
 145              ),
 146              'iscompleteallowed' => array(
 147                  'type' => PARAM_BOOL
 148              ),
 149              'isunlinkallowed' => array(
 150                  'type' => PARAM_BOOL
 151              ),
 152              'isrequestreviewallowed' => array(
 153                  'type' => PARAM_BOOL
 154              ),
 155              'iscancelreviewrequestallowed' => array(
 156                  'type' => PARAM_BOOL
 157              ),
 158              'isstartreviewallowed' => array(
 159                  'type' => PARAM_BOOL
 160              ),
 161              'isstopreviewallowed' => array(
 162                  'type' => PARAM_BOOL
 163              ),
 164              'isapproveallowed' => array(
 165                  'type' => PARAM_BOOL
 166              ),
 167              'isunapproveallowed' => array(
 168                  'type' => PARAM_BOOL
 169              ),
 170              'duedateformatted' => array(
 171                  'type' => PARAM_TEXT
 172              ),
 173              'commentarea' => array(
 174                  'type' => comment_area_exporter::read_properties_definition(),
 175              ),
 176              'reviewer' => array(
 177                  'type' => user_summary_exporter::read_properties_definition(),
 178                  'optional' => true
 179              ),
 180              'template' => array(
 181                  'type' => template_exporter::read_properties_definition(),
 182                  'optional' => true,
 183              ),
 184              'url' => array(
 185                  'type' => PARAM_URL
 186              )
 187          );
 188      }
 189  }


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