-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlib.php
174 lines (155 loc) · 5.5 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
// This file is part of Timeline course format for moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains main class for the course format timeline social
*
* @package format_timeline
* @copyright 2020 onwards Willian Mano {@link https://conecti.me}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/course/format/lib.php');
/**
* Main class for the Timeline course format
*
* @copyright 2020 onwards Willian Mano {@link https://conecti.me}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class format_timeline extends core_courseformat\base {
/**
* Returns true if this course format uses sections
*
* @return bool
*/
public function uses_sections() {
return false;
}
/**
* Returns the display name of the given section that the course prefers.
*
* Use section name is specified by user. Otherwise use default ("Timeline #")
*
* @param int|stdClass $section Section object from database or just field section.section
*
* @return string Display name that the course format prefers, e.g. "Timeline 2"
*
* @throws moodle_exception
*/
public function get_section_name($section) {
$section = $this->get_section($section);
if ((string)$section->name !== '') {
return format_string($section->name, true,
array('context' => core\context\course::instance($this->courseid)));
} else {
return $this->get_default_section_name($section);
}
}
/**
* Returns the default section name for the timeline course format.
*
* If the section number is 0, it will use the string with key = section0name from the course format's lang file.
* If the section number is not 0, the base implementation of format_base::get_default_section_name which uses
* the string with the key = 'sectionname' from the course format's lang file + the section number will be used.
*
* @param stdClass $section Section object from database or just field course_sections section
*
* @return string The default value for the section name.
*
* @throws coding_exception
*/
public function get_default_section_name($section) {
if ($section->section == 0) {
// Return the general section.
return get_string('sectionname', 'format_timeline');
} else {
// Use format_base::get_default_section_name implementation which
// will display the section name in "Topic n" format.
return parent::get_default_section_name($section);
}
}
/**
* Returns the list of blocks to be automatically added for the newly created course
*
* @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT
* each of values is an array of block names (for left and right side columns)
*/
public function get_default_blocks() {
return array(
BLOCK_POS_LEFT => array(),
BLOCK_POS_RIGHT => array()
);
}
/**
* Whether this format allows to delete sections
*
* Do not call this function directly, instead use course_can_delete_section()
*
* @param int|stdClass|section_info $section
* @return bool
*/
public function can_delete_section($section) {
return false;
}
/**
* Indicates whether the course format supports the creation of a news forum.
*
* @return bool
*/
public function supports_news() {
return false;
}
/**
* Returns the information about the ajax support in the given source format
*
* The returned object's property (boolean)capable indicates that
* the course format supports Moodle course ajax features.
*
* @return stdClass
*/
public function supports_ajax() {
$ajaxsupport = new stdClass();
$ajaxsupport->capable = true;
return $ajaxsupport;
}
}
/**
* Fragment used in add post modal
*
* @param array $args
*
* @return string
*/
function format_timeline_output_fragment_createpost_form($args) {
$args = (object) $args;
$context = $args->context;
$o = '';
$formdata = [];
if (!empty($args->jsonformdata)) {
$serialiseddata = json_decode($args->jsonformdata);
$formdata = (array)$serialiseddata;
}
list($ignored, $course) = get_context_info_array($context->id);
$mform = new format_timeline\local\forms\createpost_form($formdata, ['courseid' => $course->id]);
if (!empty($args->jsonformdata)) {
// If we were passed non-empty form data we want the mform to call validation functions and show errors.
$mform->is_validated();
}
ob_start();
$mform->display();
$o .= ob_get_contents();
ob_end_clean();
return $o;
}