Differences Between: [Versions 310 and 311] [Versions 39 and 311]
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 * This file contains the core_privacy\local\request helper. 19 * 20 * @package core_privacy 21 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace core_privacy\local\request; 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * A class containing a set of data transformations for core data types. 30 * 31 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class transform { 35 /** 36 * Translate a userid into the standard user format for exports. 37 * 38 * We have not determined if we will do this or not, but we provide the functionality and encourgae people to use 39 * it so that it can be retrospectively fitted if required. 40 * 41 * @param int $userid the userid to translate 42 * @return mixed 43 */ 44 public static function user(int $userid) { 45 // For the moment we do not think we should transform as this reveals information about other users. 46 // However this function is implemented should the need arise in the future. 47 return $userid; 48 } 49 50 /** 51 * Translate a unix timestamp into a datetime string. 52 * 53 * @param int $datetime the unixtimestamp to translate. 54 * @return string The translated string. 55 */ 56 public static function datetime($datetime) { 57 return userdate($datetime, get_string('strftimedaydatetime', 'langconfig')); 58 } 59 60 /** 61 * Translate a unix timestamp into a date string. 62 * 63 * @param int $date the unixtimestamp to translate. 64 * @return string The translated string. 65 */ 66 public static function date($date) { 67 return userdate($date, get_string('strftimedate', 'langconfig')); 68 } 69 70 /** 71 * Translate a bool or int (0/1) value into a translated yes/no string. 72 * 73 * @param bool $value The value to translate 74 * @return string 75 */ 76 public static function yesno($value) { 77 if ($value) { 78 return get_string('yes'); 79 } else { 80 return get_string('no'); 81 } 82 } 83 84 /** 85 * Translate a float value which should be between 0.0 and 1.0 into percentage. 86 * 87 * @param float $value The value between 0.0 and 1.0. 88 * @return float|string 89 */ 90 public static function percentage(float $value) { 91 if (is_float($value)) { 92 return (100 * $value) . '%'; 93 } else { 94 return $value; 95 } 96 } 97 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body