-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from saylordotorg/feat/sync-cohorts
Feat/sync cohorts
- Loading branch information
Showing
13 changed files
with
1,553 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
// 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/>. | ||
|
||
/** | ||
* local_discoursesso | ||
* | ||
* | ||
* @package local | ||
* @subpackage discoursesso | ||
* @copyright 2019 Saylor Academy | ||
* @author John Azinheira | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$observers = array( | ||
// Listen for when a user profile is updated. | ||
array( | ||
'eventname' => '\core\event\cohort_deleted', | ||
'includefile' => '/local/discoursesso/locallib.php', | ||
'callback' => 'local_discoursesso_cohort_deleted_handler', | ||
'internal' => false | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<XMLDB PATH="local/discoursesso/db" VERSION="20141217" COMMENT="XMLDB file for Moodle local discoursesso" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" | ||
> | ||
<TABLES> | ||
<TABLE NAME="discoursesso_cohorts" COMMENT="Defines cohorts to sync"> | ||
<FIELDS> | ||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> | ||
<FIELD NAME="cohortid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> | ||
<FIELD NAME="cohortname" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/> | ||
</FIELDS> | ||
<KEYS> | ||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for cohort to sync"/> | ||
</KEYS> | ||
</TABLE> | ||
</TABLES> | ||
</XMLDB> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
// 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/>. | ||
/** | ||
* local_discoursesso | ||
* | ||
* | ||
* @package local | ||
* @subpackage discoursesso | ||
* @copyright 2017 Saylor Academy | ||
* @author John Azinheira | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* upgrade this assignment instance - this function could be skipped but it will be needed later | ||
* @param int $oldversion The old version of the assign module | ||
* @return bool | ||
*/ | ||
function xmldb_local_discoursesso_upgrade($oldversion) { | ||
global $CFG, $DB; | ||
|
||
$dbman = $DB->get_manager(); | ||
|
||
if ($oldversion < 2019052200) { | ||
|
||
// Define table discoursesso_cohorts to be created. | ||
$table = new xmldb_table('discoursesso_cohorts'); | ||
|
||
// Adding fields to table discoursesso_cohorts. | ||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | ||
$table->add_field('cohortid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | ||
$table->add_field('certificatename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'timecreated'); | ||
|
||
// Adding keys to table discoursesso_cohorts. | ||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); | ||
|
||
// Conditionally launch create table for discoursesso_cohorts. | ||
if (!$dbman->table_exists($table)) { | ||
$dbman->create_table($table); | ||
} | ||
|
||
// Discoursesso savepoint reached. | ||
upgrade_plugin_savepoint(true, 2019052200, 'local', 'discoursesso'); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
// 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/>. | ||
|
||
/** | ||
* local_discoursesso | ||
* | ||
* | ||
* @package local | ||
* @subpackage discoursesso | ||
* @copyright 2017 Saylor Academy | ||
* @author John Azinheira | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require_once('../../config.php'); | ||
require_once('./locallib.php'); | ||
|
||
$confirmadd = optional_param('confirmadd', 0, PARAM_INT); | ||
$confirmdel = optional_param('confirmdel', 0, PARAM_INT); | ||
|
||
require_login(); | ||
// Add proper permissions check. | ||
if (!is_siteadmin()) { | ||
die; | ||
} | ||
|
||
$PAGE->set_context(context_system::instance()); | ||
$PAGE->set_url('/local/discoursesso/groups.php'); | ||
$PAGE->set_title(format_string(get_string('plugingrouppagename', 'local_discoursesso'))); | ||
$PAGE->set_heading(format_string(get_string('plugingrouppagename', 'local_discoursesso'))); | ||
$PAGE->navbar->add(get_string('plugingrouppagename', 'local_discoursesso')); | ||
|
||
$returnurl = new moodle_url('/admin/search.php'); | ||
|
||
if (optional_param('cancel', false, PARAM_BOOL)) { | ||
redirect($returnurl); | ||
} | ||
|
||
echo $OUTPUT->header(); | ||
format_string(get_string('plugingrouppagename', 'local_discoursesso')); | ||
|
||
|
||
// Get the user_selector we will need. | ||
$potentialuserselector = new discoursesso_cohort_candidate_selector('addselect', array()); | ||
$existinguserselector = new discoursesso_cohort_existing_selector('removeselect', array()); | ||
|
||
// Process incoming user assignments to the cohort | ||
|
||
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { | ||
$userstoassign = $potentialuserselector->get_selected_users(); | ||
if (!empty($userstoassign)) { | ||
|
||
foreach ($userstoassign as $adduser) { | ||
if (discoursesso_add_group($adduser->id) === false) { | ||
echo $OUTPUT->notification('The cohort was not added.', NOTIFY_ERROR); | ||
} | ||
} | ||
|
||
$potentialuserselector->invalidate_selected_users(); | ||
$existinguserselector->invalidate_selected_users(); | ||
} | ||
} | ||
|
||
// Process removing user assignments to the cohort | ||
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { | ||
$userstoremove = $existinguserselector->get_selected_users(); | ||
if (!empty($userstoremove)) { | ||
foreach ($userstoremove as $removeuser) { | ||
if (discoursesso_remove_group($removeuser->id) === false) { | ||
echo $OUTPUT->notification('The cohort was not removed.', NOTIFY_ERROR); | ||
} | ||
} | ||
$potentialuserselector->invalidate_selected_users(); | ||
$existinguserselector->invalidate_selected_users(); | ||
} | ||
} | ||
|
||
// Print the form. | ||
?> | ||
<form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div> | ||
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" /> | ||
<input type="hidden" name="returnurl" value="<?php echo $returnurl->out_as_local_url() ?>" /> | ||
|
||
<table summary="" class="generaltable generalbox boxaligncenter" cellspacing="0"> | ||
<tr> | ||
<td id="existingcell"> | ||
<p><label for="removeselect"><?php print_string('currentcohorts', 'local_discoursesso'); ?></label></p> | ||
<?php $existinguserselector->display() ?> | ||
</td> | ||
<td id="buttonscell"> | ||
<div id="addcontrols"> | ||
<input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().' '.s(get_string('add')); ?>" title="<?php p(get_string('add')); ?>" /><br /> | ||
</div> | ||
|
||
<div id="removecontrols"> | ||
<input name="remove" id="remove" type="submit" value="<?php echo s(get_string('remove')).' '.$OUTPUT->rarrow(); ?>" title="<?php p(get_string('remove')); ?>" /> | ||
</div> | ||
</td> | ||
<td id="potentialcell"> | ||
<p><label for="addselect"><?php print_string('potcohorts', 'local_discoursesso'); ?></label></p> | ||
<?php $potentialuserselector->display() ?> | ||
</td> | ||
</tr> | ||
<tr><td colspan="3" id='backcell'> | ||
<input class="btn btn-primary" type="submit" name="cancel" value="<?php p(get_string('back')); ?>" /> | ||
</td></tr> | ||
</table> | ||
</div></form> | ||
|
||
<?php | ||
|
||
echo $OUTPUT->footer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.