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