forked from KaraBeason/sentiment_analysis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecute_task.php
72 lines (60 loc) · 3.01 KB
/
execute_task.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
<?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/>.
/**
* block_sentimentanalysis
*
* @author Kara Beason <[email protected]>
* @copyright (c) 2019 Appalachian State Universtiy, Boone, NC
* @license GNU General Public License version 3
* @package block_sentimentanalysis
*/
require_once('../../config.php');
require_once(__DIR__ . '/lib.php');
require_once(__DIR__ . '/classes/task/block_sentimentanalysis_task.php');
use block_sentimentanalysis\task\block_sentimentanalysis_task;
use \core\task\manager;
defined('MOODLE_INTERNAL') || die();
// We pass/fetch the block instance id
$id = required_param('id', PARAM_INT);
// Get the instance record using the block id
$instancerec = $DB->get_record('block_instances', array('id' => $id));
if (!$instancerec) {
// No instance, no service
throw new moodle_exception(get_string('invalidblockinstance', 'error', 'sentimentanalysis'));
}
$block = block_instance("sentimentanalysis", $instancerec);
// Block instance rec leads to parent (course) context
$coursecontext = context::instance_by_id($block->instance->parentcontextid);
// Now I got the course id in the instanceid member. If anytihing goes wrong
// want to go back to the course view.
$PAGE->set_url('/course/view.php', array('id' => $coursecontext->instanceid));
// Know which course we're in, so can authorize the user
require_login($coursecontext->instanceid);
// Check current user's capabilities.
require_capability('moodle/course:manageactivities', $coursecontext);
// If assignment list has not been configured, nothing to run.
if (!$block->config) {
redirect($PAGE->url, get_string("noconfigprompt", "block_sentimentanalysis"));
}
// Config is deserialized from text column, assignments in
// array, create the ad hoc task and supply the needed ids
$task = new block_sentimentanalysis_task();
$task->set_userid($USER->id);
$task->set_custom_data($block->config->assignments);
// Queue it, then back to the course.
manager::queue_adhoc_task($task);
//Adding message to redirect until/unless I can figure out how to display it in the block upon clicking the execute button.
redirect($PAGE->url, get_string("submitprompt", "block_sentimentanalysis"));