-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathlocallib.php
More file actions
145 lines (126 loc) · 5.14 KB
/
Copy pathlocallib.php
File metadata and controls
145 lines (126 loc) · 5.14 KB
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
<?php
// This file is part of 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/>.
/**
* Helper functions for tool_lifecycle.
* @package tool_lifecycle
* @copyright 2025 Thomas Niedermaier University Münster
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Check if a plugin is installed.
* @param string $plugin name of the plugin
* @param string $plugintype name of the plugin's plugin type
* @return bool
*/
function lifecycle_is_plugin_installed($plugin, $plugintype) {
$pluginsinstalled = core_component::get_plugin_list($plugintype);
$found = false;
foreach ($pluginsinstalled as $installed => $path) {
if ($plugin == $installed) {
$found = true;
break;
}
}
return $found;
}
/**
* Generates html for a select field to switch from one workflow to another
*
* @param string $activewf the current workflow
* @return void
* @throws \core\exception\moodle_exception
* @throws coding_exception
* @throws dml_exception
*/
function lifecycle_select_change_workflow($activewf) {
global $OUTPUT, $DB, $PAGE;
$records = $DB->get_records_sql(
'SELECT id, title, timeactive, timedeactive FROM {tool_lifecycle_workflow} ORDER BY title ASC');
$url = $PAGE->url;
$actionmenu = new \action_menu();
foreach ($records as $record) {
if ($record->id == $activewf) {
continue;
}
$actionmenu->add_secondary_action(
new \action_menu_link_secondary(
new \moodle_url($url, ['wf' => $record->id]),
null,
$record->title
)
);
}
$actionmenu->set_menu_trigger(get_string('switchworkflow', 'tool_lifecycle'));
echo $OUTPUT->render_action_menu($actionmenu);
}
/**
* Check if a discussion for this workflow already exists and if not create one. Return the url to this discussion.
* @param int $workflowid id of the workflow
* @param int $forumid id of the dedicated workflows discussion forum instance
* @return int[] discussionid or postid when new discussion
*/
function lifecycle_get_workflow_discussion($workflowid, $forumid) {
global $DB, $USER;
if (!$forum = $DB->get_record('forum', ['id' => $forumid])) {
throw new moodle_exception('invalidcoursemodule', 'moodle');
}
$workflow = $DB->get_record('tool_lifecycle_workflow', ['id' => $workflowid]);
$postid = "";
if (!$discussionid = $DB->get_field('tool_lifecycle_workflow', 'forum_discussion', ['id' => $workflowid])) {
$timenow = time();
$discussion = new stdClass();
$discussion->course = $forum->course;
$discussion->forum = $forum->id;
$discussion->name = get_string('workflow', 'tool_lifecycle').": ".$workflow->title;
$discussion->assessed = $forum->assessed;
$discussion->message = "";
$discussion->messageformat = $forum->introformat;
$discussion->messagetrust = true;
$discussion->mailnow = false;
$discussion->groupid = -1;
$post = new \stdClass();
$post->discussion = 0;
$post->parent = 0;
$post->privatereplyto = 0;
$post->userid = $USER->id;
$post->created = $timenow;
$post->modified = $timenow;
$post->mailed = 0;
$post->subject = $discussion->name;
$post->message = "";
$post->messageformat = $discussion->messageformat;
$post->messagetrust = $discussion->messagetrust;
$post->attachments = null;
$post->forum = $forum->id;
$post->course = $forum->course;
$post->mailnow = $discussion->mailnow;
\mod_forum\local\entities\post::add_message_counts($post);
$post->id = $DB->insert_record("forum_posts", $post);
$discussion->firstpost = $post->id;
$discussion->timemodified = $timenow;
$discussion->usermodified = $post->userid;
$discussion->userid = $USER->id;
$discussion->assessed = 0;
$discussionid = $DB->insert_record("forum_discussions", $discussion);
// Set the pointer to the discussion on the post.
$DB->set_field("forum_posts", "discussion", $discussionid, ["id" => $post->id]);
// Make it the workflow's discussion.
$DB->set_field("tool_lifecycle_workflow", "forum_discussion", $discussionid, ["id" => $workflowid]);
$postid = $post->id;
$discussionid = "";
}
return [$discussionid, $postid];
}