Skip to content

Commit 81dc45b

Browse files
committed
Mecanismo para separação de turmas
1 parent 640c524 commit 81dc45b

File tree

10 files changed

+839
-0
lines changed

10 files changed

+839
-0
lines changed

report/ilbsplit/LICENSE

+340
Large diffs are not rendered by default.

report/ilbsplit/db/access.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
* Capabilities
19+
*
20+
* @package report_progress
21+
* @copyright 2008 Sam Marshall
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
$capabilities = array(
28+
29+
'report/ilbsplit:view' => array(
30+
'riskbitmask' => RISK_PERSONAL,
31+
'captype' => 'read',
32+
'contextlevel' => CONTEXT_COURSE,
33+
'archetypes' => array(
34+
'teacher' => CAP_ALLOW,
35+
'editingteacher' => CAP_ALLOW,
36+
'manager' => CAP_ALLOW
37+
),
38+
39+
'clonepermissionsfrom' => 'coursereport/progress:view',
40+
)
41+
);
42+
43+

report/ilbsplit/db/install.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
* Post installation and migration code.
19+
*
20+
* @package report
21+
* @subpackage progress
22+
* @copyright 2011 Petr Skoda {@link http://skodak.org}
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
defined('MOODLE_INTERNAL') || die;
27+
28+
function xmldb_report_ilbsplit_install() {
29+
global $DB;
30+
31+
}
32+

report/ilbsplit/form.php

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
// This file is part of Moodle - http://moodle.org/
4+
//
5+
// Moodle is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Moodle is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17+
18+
/**
19+
* This file defines the user filter form
20+
*
21+
* @package report-ilbsplit
22+
* @copyrigth 2014 Interlegis (http://www.interlegis.leg.br)
23+
*
24+
* @author Sesostris Vieira
25+
*
26+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html
27+
*/
28+
29+
if (!defined('MOODLE_INTERNAL')) {
30+
die('Direct access to this script is forbidden.');
31+
}
32+
33+
require_once("$CFG->libdir/formslib.php");
34+
35+
class split_form extends moodleform {
36+
protected $_courseid;
37+
protected $_options;
38+
39+
function split_form($courseid, $options, $action=null, $customdata=null, $method='get', $target='', $attributes=null, $editable=true) {
40+
$this->_courseid = $courseid;
41+
$this->_options = $options;
42+
parent::moodleform($action, $customdata, $method, $target, $attributes, $editable);
43+
}
44+
45+
public function definition() {
46+
global $CFG;
47+
global $DB;
48+
49+
$mform = $this->_form; // Don't forget the underscore!
50+
$courseid = $this->_courseid;
51+
$options = $this->_options;
52+
53+
$course = get_course($courseid);
54+
$courses = $DB->get_records('course', array('category'=>$course->category));
55+
56+
// Source options
57+
foreach ($options as $key=>$option) {
58+
$mform->addElement('header', "role_header_{$key}", $option[0]);
59+
foreach ($option[1] as $roleid=>$role) {
60+
$description = get_string('role_option','report_ilbsplit', $role);
61+
$mform->addElement('radio', 'role', '', $description, "{$key}:{$roleid}");
62+
}
63+
}
64+
$mform->addRule('role', null, 'required');
65+
66+
// Courses
67+
$coursesarray = array();
68+
foreach ($courses as $c) {
69+
if ($c->id !== $courseid) {
70+
$coursesarray[$c->id] = $c->fullname;
71+
}
72+
}
73+
74+
$mform->addElement('select', 'target', get_string('target_course','report_ilbsplit'), $coursesarray);
75+
$mform->addRule('target', null, 'required');
76+
$mform->addElement('text', 'qty', get_string('splitqty', 'report_ilbsplit'));
77+
$mform->setType('qty', PARAM_INT);
78+
$mform->addRule('qty', null, 'required');
79+
$mform->closeHeaderBefore('target');
80+
81+
$mform->addElement('submit', 'filterbutton', get_string('split', 'report_ilbsplit'));
82+
$mform->addElement('hidden', 'course', $courseid);
83+
// $mform->closeHeaderBefore('filterbutton');
84+
}
85+
}

report/ilbsplit/index.php

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
* ILB Enrol Confirmation reports
19+
*
20+
* @package report
21+
* @subpackage ilbsplit
22+
* @copyright 2008 Sam Marshall
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
require('../../config.php');
27+
require("{$CFG->dirroot}/enrol/locallib.php");
28+
require_once("$CFG->dirroot/user/profile/lib.php");
29+
require_once('form.php');
30+
31+
// Get course
32+
$id = required_param('course',PARAM_INT);
33+
$course = $DB->get_record('course',array('id'=>$id));
34+
35+
if (!$course) {
36+
print_error('invalidcourseid');
37+
}
38+
39+
$context = context_course::instance($course->id);
40+
41+
$url = new moodle_url('/report/ilbsplit/index.php', array('course'=>$id));
42+
$PAGE->set_url($url);
43+
$PAGE->set_pagelayout('report');
44+
45+
require_login($course);
46+
47+
// Check basic permission
48+
require_capability('report/ilbsplit:view',$context);
49+
50+
// Get group mode
51+
$group = groups_get_course_group($course,true); // Supposed to verify group
52+
if ($group===0 && $course->groupmode==SEPARATEGROUPS) {
53+
require_capability('moodle/site:accessallgroups',$context);
54+
}
55+
56+
// Get data for user filtering
57+
$manager = new course_enrolment_manager($PAGE, $course);
58+
59+
$options = array();
60+
$has_options = false;
61+
62+
foreach ($manager->get_enrolment_instances() as $e) {
63+
$options[$e->id] = array("{$e->name} ({$e->enrol})", array());
64+
$m = new course_enrolment_manager($PAGE, $course, $e->id);
65+
foreach ($m->get_all_roles() as $role) {
66+
$tm = new course_enrolment_manager($PAGE, $course, $e->id, $role->id);
67+
$tu = $tm->get_total_users();
68+
if ($tu > 0) {
69+
$options[$e->id][1][$role->id] = array('localname' => $role->localname, 'totalusers' => $tu);
70+
$has_options = true;
71+
}
72+
}
73+
}
74+
$pagetitle = get_string('title','report_ilbsplit');
75+
$PAGE->set_title($pagetitle);
76+
$PAGE->set_heading($course->fullname);
77+
echo $OUTPUT->header();
78+
echo $OUTPUT->heading($pagetitle);
79+
80+
if (!$has_options) {
81+
echo $OUTPUT->box(get_string('nouserstosplit', 'report_ilbsplit'), 'center');
82+
echo $OUTPUT->footer();
83+
die;
84+
}
85+
86+
$mform = new split_form($course->id, $options);
87+
88+
if ($formdata = $mform->get_data()) {
89+
$role = explode(':', $formdata->role);
90+
$enrolid = $role[0];
91+
$roleid = $role[1];
92+
$targetid = $formdata->target;
93+
$qty = $formdata->qty;
94+
95+
$course_target = $DB->get_record('course',array('id'=>$targetid));
96+
97+
if (!$course_target) {
98+
print_error('invalidcourseid');
99+
}
100+
101+
$context_target = context_course::instance($course_target->id);
102+
$manager_target = new course_enrolment_manager($PAGE, $course_target);
103+
104+
if (!array_key_exists($enrolid, $manager->get_enrolment_instances())) {
105+
echo $OUTPUT->box(get_string('invalidenrolid', 'report_ilbsplit'), 'center');
106+
echo $OUTPUT->footer();
107+
die;
108+
}
109+
110+
$enrol = $manager->get_enrolment_instances()[$enrolid];
111+
$enrol_target = null;
112+
113+
foreach ($manager_target->get_enrolment_instances() as $et) {
114+
if ($et->enrol == $enrol->enrol) {
115+
$enrol_target = $et;
116+
break;
117+
}
118+
}
119+
120+
if (is_null($enrol_target)) {
121+
echo $OUTPUT->box(get_string('noenroltarget', 'report_ilbsplit'), 'center');
122+
echo $OUTPUT->footer();
123+
die;
124+
}
125+
126+
// Mount parameters and sql-updates
127+
128+
$params = array('course_source' => $course->id,
129+
'course_target' => $course_target->id,
130+
'enrol_source' => $enrol->id,
131+
'enrol_target' => $enrol_target->id,
132+
'context_source' => $context->id,
133+
'context_target' => $context_target->id,
134+
'roleid' => $roleid,
135+
'qty' => $qty);
136+
137+
$sql_transfer_enrols = 'update {user_enrolments} set enrolid = :enrol_target where enrolid = :enrol_source and userid in (select userid from {role_assignments} where roleid = :roleid and contextid = :context_source limit :qty)';
138+
$sql_transfer_roles = 'update {role_assignments} set contextid = :context_target where roleid = :roleid and contextid = :context_source and userid in (select userid from {user_enrolments} where enrolid = :enrol_target)';
139+
140+
// Execute updates
141+
142+
$transaction = $DB->start_delegated_transaction();
143+
144+
try {
145+
$DB->execute($sql_transfer_enrols, $params);
146+
$DB->execute($sql_transfer_roles, $params);
147+
$transaction->allow_commit();
148+
} catch(Exception $e) {
149+
$transaction->rollback($e);
150+
echo $OUTPUT->box(get_string('nouserstransfered', 'report_ilbsplit'), 'center');
151+
echo $OUTPUT->footer();
152+
die;
153+
}
154+
155+
echo $OUTPUT->box(get_string('userstransfered', 'report_ilbsplit'), 'center');
156+
} else {
157+
echo $OUTPUT->box(get_string('alert', 'report_ilbsplit'), 'center');
158+
$mform->display();
159+
}
160+
161+
echo $OUTPUT->footer();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
* Lang strings
19+
*
20+
* @package report
21+
* @subpackage progress
22+
* @copyright 2008 Sam Marshall
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
$string['pluginname'] = 'ILB Split Course';
27+
$string['title'] = 'ILB Split Course Report';
28+
$string['alert'] = '<strong>ALERT</strong>
29+
<p>Users transferred by this plugin may be confused with users who are already in the destination course, preventing any subsequent separation</p><strong>Be careful</strong>';
30+
$string['nouserstosplit'] = 'No users to split';
31+
$string['role_option'] = '{$a->totalusers} enrolled users as {$a->localname}';
32+
$string['target_course'] = 'Target course';
33+
$string['split'] = 'Split';
34+
$string['splitqty'] = 'Split quantity';
35+
$string['invalidenrolid'] = 'Invalid enrol ID';
36+
$string['noenroltarget'] = 'No enrol method in target course that can receipt these users';
37+
$string['nouserstransfered'] = 'No user has been transferred';
38+
$string['userstransfered'] = 'Users has been transferred';
39+
$string['page-report-ilbsplit-x'] = 'Page to split users into different courses';
40+
$string['page-report-ilbsplit-index'] = 'Page index to split users into different courses';

0 commit comments

Comments
 (0)