Skip to content

Commit

Permalink
Merge pull request #38 from catalyst/issue37
Browse files Browse the repository at this point in the history
issue #37: add auth method condition
  • Loading branch information
dmitriim authored Mar 8, 2024
2 parents cec01f9 + 1e1afd3 commit 3df13c7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
78 changes: 78 additions & 0 deletions classes/local/tool_dynamic_cohorts/condition/auth_method.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

namespace tool_dynamic_cohorts\local\tool_dynamic_cohorts\condition;

use core_plugin_manager;

/**
* Condition using user auth method.
*
* This is a simplified version of user_profile that allows matching only by an auth method.
*
* @package tool_dynamic_cohorts
* @copyright 2024 Catalyst IT
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_method extends user_profile {

/**
* Condition name.
*
* @return string
*/
public function get_name(): string {
return get_string('condition:auth_method', 'tool_dynamic_cohorts');
}

/**
* Add config form elements.
*
* @param \MoodleQuickForm $mform
*/
public function config_form_add(\MoodleQuickForm $mform): void {
$fields = $this->get_fields_info();

$mform->addElement('hidden', self::FIELD_NAME, 'auth');
$mform->setType(self::FIELD_NAME, PARAM_ALPHA);

$group = [];
$this->add_menu_field($mform, $group, $fields['auth'], 'auth');

$mform->addGroup($group, 'profilefieldgroup', get_string('condition:auth_method', 'tool_dynamic_cohorts'), '', false);
}

/**
* Returns a list of all fields with extra data (shortname, name, datatype, param1 and type).
*
* @return \stdClass[]
*/
protected function get_fields_info(): array {

$field = 'auth';
$options = [];
foreach (core_plugin_manager::instance()->get_plugins_of_type('auth') as $plugin) {
$options[$plugin->name] = $plugin->displayname;
}
$fields = [];
$fields[$field] = new \stdClass();
$fields[$field]->name = get_string('type_auth', 'plugin');
$fields[$field]->datatype = self::FIELD_DATA_TYPE_MENU;
$fields[$field]->param1 = $options;

return $fields;
}
}
1 change: 1 addition & 0 deletions lang/en/tool_dynamic_cohorts.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$string['conditionsformtitle'] = 'Rule conditions';
$string['conditionchnagesnotapplied'] = 'Condition changes are not applied until you save the rule form';
$string['conditionformtitle'] = 'Rule condition';
$string['condition:auth_method'] = 'Authentication method';
$string['condition:cohort_membership'] = 'Cohort membership';
$string['condition:cohort_membership_description'] = 'A user {$a->operator} {$a->cohorts}';
$string['condition:cohort_membership_broken_description'] = 'Condition is broken. Using the same cohort that the given rule is configured to manage to.';
Expand Down

0 comments on commit 3df13c7

Please sign in to comment.