1 |
efrain |
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 |
* Language import page.
|
|
|
19 |
*
|
|
|
20 |
* @package tool_langimport
|
|
|
21 |
* @copyright 2016 Jun Pataleta
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
namespace tool_langimport\output;
|
|
|
25 |
|
|
|
26 |
use core_collator;
|
|
|
27 |
use moodle_url;
|
|
|
28 |
use renderable;
|
|
|
29 |
use renderer_base;
|
|
|
30 |
use stdClass;
|
|
|
31 |
use templatable;
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Language import page class.
|
|
|
35 |
*
|
|
|
36 |
* @package tool_langimport
|
|
|
37 |
* @copyright 2016 Jun Pataleta
|
|
|
38 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
39 |
*/
|
|
|
40 |
class langimport_page implements renderable, templatable {
|
|
|
41 |
|
|
|
42 |
/** @var array Array of currently installed languages. */
|
|
|
43 |
protected $installedlanguages;
|
|
|
44 |
|
|
|
45 |
/** @var array Array of languages that can be installed. */
|
|
|
46 |
protected $availablelanguages;
|
|
|
47 |
|
|
|
48 |
/** @var moodle_url The URL to be used for uninstalling the selected existing language packs. */
|
|
|
49 |
protected $uninstallurl;
|
|
|
50 |
|
|
|
51 |
/** @var moodle_url The URL to be used for updating the installed language packs. */
|
|
|
52 |
protected $updateurl;
|
|
|
53 |
|
|
|
54 |
/** @var moodle_url The URL to be used for installing the selected language packs to be installed. */
|
|
|
55 |
protected $installurl;
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* langimport_page constructor.
|
|
|
60 |
*
|
|
|
61 |
* @param array $installedlanguages Array of currently installed languages.
|
|
|
62 |
* @param array $availablelanguages Array of languages that can be installed.
|
|
|
63 |
* @param moodle_url $uninstallurl The URL to be used for uninstalling the selected existing language packs.
|
|
|
64 |
* @param moodle_url $updateurl The URL to be used for updating the installed language packs.
|
|
|
65 |
* @param moodle_url $installurl The URL to be used for installing the selected language packs to be installed.
|
|
|
66 |
*/
|
|
|
67 |
public function __construct($installedlanguages, $availablelanguages, $uninstallurl, $updateurl, $installurl) {
|
|
|
68 |
$this->installedlanguages = $installedlanguages;
|
|
|
69 |
$this->availablelanguages = $availablelanguages;
|
|
|
70 |
$this->uninstallurl = $uninstallurl;
|
|
|
71 |
$this->updateurl = $updateurl;
|
|
|
72 |
$this->installurl = $installurl;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* Export the data.
|
|
|
77 |
*
|
|
|
78 |
* @param renderer_base $output
|
|
|
79 |
* @return stdClass
|
|
|
80 |
*/
|
|
|
81 |
public function export_for_template(renderer_base $output) {
|
|
|
82 |
$data = new stdClass();
|
|
|
83 |
$data->uninstallurl = $this->uninstallurl;
|
|
|
84 |
$data->sesskey = sesskey();
|
|
|
85 |
|
|
|
86 |
$data->installedoptions = [];
|
|
|
87 |
foreach ($this->installedlanguages as $code => $language) {
|
|
|
88 |
$option = new stdClass();
|
|
|
89 |
$option->value = $code;
|
|
|
90 |
$option->text = $language;
|
|
|
91 |
$data->installedoptions[] = $option;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
$data->updateurl = $this->updateurl;
|
|
|
95 |
|
|
|
96 |
if (!empty($this->availablelanguages)) {
|
|
|
97 |
$data->toinstalloptions = [];
|
|
|
98 |
|
|
|
99 |
core_collator::asort($this->availablelanguages);
|
|
|
100 |
foreach ($this->availablelanguages as $code => $language) {
|
|
|
101 |
$option = new stdClass();
|
|
|
102 |
$option->value = $code;
|
|
|
103 |
$option->text = $language;
|
|
|
104 |
$data->toinstalloptions[] = $option;
|
|
|
105 |
}
|
|
|
106 |
$data->installurl = $this->installurl;
|
|
|
107 |
$data->caninstall = true;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
if (count($this->installedlanguages) > 3) {
|
|
|
111 |
$data->hasmanyinstalledlanguages = true;
|
|
|
112 |
$data->updatelangstaskname = get_string('updatelangs', 'tool_langimport');
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
return $data;
|
|
|
116 |
}
|
|
|
117 |
}
|