Ejemplo n.º 1
0
 */
require_once dirname(__FILE__) . '/../../../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/tablelib.php';
$removeid = optional_param('removecohortroleassignment', 0, PARAM_INT);
admin_externalpage_setup('toolcohortroles');
$context = context_system::instance();
$pageurl = new moodle_url('/admin/tool/cohortroles/index.php');
$output = $PAGE->get_renderer('tool_cohortroles');
echo $output->header();
$title = get_string('assignroletocohort', 'tool_cohortroles');
echo $output->heading($title);
$form = new tool_cohortroles\form\assign_role_cohort();
if ($removeid) {
    require_sesskey();
    $result = \tool_cohortroles\api::delete_cohort_role_assignment($removeid);
    if ($result) {
        $notification = get_string('cohortroleassignmentremoved', 'tool_cohortroles');
        echo $output->notify_success($notification);
    } else {
        $notification = get_string('cohortroleassignmentnotremoved', 'tool_cohortroles');
        echo $output->notify_problem($notification);
    }
    echo $output->continue_button(new moodle_url($pageurl));
} else {
    if ($data = $form->get_data()) {
        require_sesskey();
        // We must create them all or none.
        $saved = 0;
        // Loop through userids and cohortids only if both of them are not empty.
        if (!empty($data->userids) && !empty($data->cohortids)) {
Ejemplo n.º 2
0
 public function test_delete_cohort_role_assignment()
 {
     $this->setAdminUser();
     $params = (object) array('userid' => $this->userassignto->id, 'roleid' => $this->roleid, 'cohortid' => $this->cohort->id);
     $result = api::create_cohort_role_assignment($params);
     $worked = api::delete_cohort_role_assignment($result->get_id());
     $this->assertTrue($worked);
 }