Beispiel #1
0
 function get_records($filter)
 {
     global $DB, $USER;
     $id = $this->required_param('id', PARAM_INT);
     $sort = $this->optional_param('sort', 'name', PARAM_ALPHA);
     $dir = $this->optional_param('dir', 'ASC', PARAM_ALPHA);
     $pagenum = $this->optional_param('page', 0, PARAM_INT);
     $perpage = $this->optional_param('perpage', 30, PARAM_INT);
     $filters = array();
     // find users who do not have a manual assignment already
     $filters[] = new join_filter('id', clusterassignment::TABLE, 'userid', new AND_filter(array(new field_filter('clusterid', $id), new field_filter('plugin', 'manual'))), true);
     // user-defined filter
     list($extrasql, $params) = $filter->get_sql_filter();
     if ($extrasql) {
         $filters[] = new select_filter($extrasql, $params);
     }
     // TODO: Ugly, this needs to be overhauled
     $upage = new usersetpage();
     if (!$upage->_has_capability('local/elisprogram:userset_enrol')) {
         //perform SQL filtering for the more "conditional" capability
         //get the context for the "indirect" capability
         $context = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:userset_enrol_userset_user', $USER->id);
         $allowed_clusters = userset::get_allowed_clusters($id);
         if (empty($allowed_clusters)) {
             $filters[] = new select_filter('FALSE');
         } else {
             $filters[] = new join_filter('id', clusterassignment::TABLE, 'userid', new in_list_filter('clusterid', $allowed_clusters));
         }
     }
     $count = user::count($filters);
     $users = user::find($filters, array($sort => $dir), $pagenum * $perpage, $perpage);
     return array($users, $count);
 }
Beispiel #2
0
 /**
  * items in the form
  */
 public function definition()
 {
     global $CURMAN, $CFG;
     parent::definition();
     $mform =& $this->_form;
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('text', 'name', get_string('userset_name', 'local_elisprogram'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', get_string('required'), 'required', NULL, 'client');
     $mform->addHelpButton('name', 'userset_name', 'local_elisprogram');
     $mform->addElement('textarea', 'display', get_string('userset_description', 'local_elisprogram'), array('cols' => 40, 'rows' => 2));
     $mform->setType('display', PARAM_CLEAN);
     $mform->addHelpButton('display', 'userset_description', 'local_elisprogram');
     $current_cluster_id = isset($this->_customdata['obj']->id) ? $this->_customdata['obj']->id : '';
     //obtain the non-child clusters that we could become the child of, with availability
     //determined based on the edit capability
     $contexts = usersetpage::get_contexts('local/elisprogram:userset_edit');
     $non_child_clusters = cluster_get_non_child_clusters($current_cluster_id, $contexts);
     //parent dropdown
     $mform->addElement('select', 'parent', get_string('userset_parent', 'local_elisprogram'), $non_child_clusters);
     $mform->addHelpButton('parent', 'userset_parent', 'local_elisprogram');
     // allow plugins to add their own fields
     $mform->addElement('header', 'userassociationfieldset', get_string('userset_userassociation', 'local_elisprogram'));
     $plugins = get_plugin_list(userset::ENROL_PLUGIN_TYPE);
     foreach ($plugins as $plugin => $plugindir) {
         require_once elis::plugin_file(userset::ENROL_PLUGIN_TYPE . '_' . $plugin, 'lib.php');
         call_user_func('cluster_' . $plugin . '_edit_form', $this, $mform, $current_cluster_id);
     }
     // custom fields
     $this->add_custom_fields('cluster', 'local/elisprogram:userset_edit', 'local/elisprogram:userset_view', 'cluster');
     $this->add_action_buttons();
 }
Beispiel #3
0
/**
 * Dynamically loads child menu items for a track entity
 *
 * @param   int             $id                    The entity id
 * @param   int             $parent_cluster_id     The last cluster passed going down the elisadmin tree, or 0 if none
 * @param   int             $parent_curriculum_id  The last curriculum passed going down the elisadmin tree, or 0 if none
 * @param   int             $num_block_icons       Max number of entries to display
 * @param   string          $parent_path           Path of parent curriculum elements in the tree
 * @return  menuitem array                         The appropriate child items
 */
function block_elisadmin_load_menu_children_track($id, $parent_cluster_id, $parent_curriculum_id, $num_block_icons, $parent_path = '')
{
    global $CFG;
    //page dependencies
    require_once elispm::file('pmclasspage.class.php');
    $result_items = array();
    /*****************************************
     * Track - Class Associations
     *****************************************/
    $class_css_class = block_elisadmin_get_item_css_class('class_instance');
    //permissions filter
    $class_filter = array('contexts' => pmclasspage::get_contexts('local/elisprogram:class_view'));
    $listing = track_assignment_get_listing($id, 'cls.idnumber', 'ASC', 0, $num_block_icons, '', '', $class_filter);
    foreach ($listing as $item) {
        $item->id = $item->classid;
        $params = array('id' => $item->id, 'action' => 'view');
        $result_items[] = block_elisadmin_get_menu_item('pmclass', $item, 'root', $class_css_class, $parent_cluster_id, $parent_curriculum_id, $params, false, $parent_path);
    }
    unset($listing);
    //summary item
    $num_records = track_assignment_count_records($id, '', '', $class_filter);
    if ($num_block_icons < $num_records) {
        $params = array('id' => $id);
        $result_items[] = block_elisadmin_get_menu_summary_item('trackassignment', $class_css_class, $num_records - $num_block_icons, $params, '', $parent_path);
    }
    /*****************************************
     * Track - Cluster Associations
     *****************************************/
    $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance');
    //permissions filter
    $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view'));
    $clusters = clustertrack::get_clusters($id, $parent_cluster_id, 'name', 'ASC', 0, $num_block_icons, $cluster_filter);
    //$clusters = clustertrack::get_clusters($id, 0, 'priority, name', 'ASC', $num_block_icons, $parent_cluster_id);
    if (!empty($clusters)) {
        foreach ($clusters as $cluster) {
            $cluster->id = $cluster->clusterid;
            $params = array('id' => $cluster->id, 'action' => 'view');
            $result_items[] = block_elisadmin_get_menu_item('cluster', $cluster, 'root', $cluster_css_class, $cluster->id, $parent_curriculum_id, $params, false, $parent_path);
        }
    }
    //summary item
    $num_records = clustertrack::count_clusters($id, $parent_cluster_id, $cluster_filter);
    if ($num_block_icons < $num_records) {
        $params = array('id' => $id);
        //add extra param if appropriate
        if (!empty($parent_cluster_id)) {
            $params['parent_clusterid'] = $parent_cluster_id;
        }
        $result_items[] = block_elisadmin_get_menu_summary_item('trackcluster', $cluster_css_class, $num_records - $num_block_icons, $params, 'clustertrackpage.class.php', $parent_path);
    }
    return $result_items;
}
 /**
  * Determine whether the current user can assign users to this userset.
  *
  * @return bool Whether the user can assign users to this userset or not.
  */
 public function can_do_add()
 {
     $id = $this->required_param('id', PARAM_INT);
     return usersetpage::can_enrol_into_cluster($id);
 }
Beispiel #5
0
 /**
  * Formats various attributes for human consumption.
  * @param array $row An array for a single result.
  * @return array The transformed result.
  */
 protected function results_row_transform(array $row)
 {
     static $canenrolintocluster = null;
     if ($canenrolintocluster === null) {
         $canenrolintocluster = usersetpage::can_enrol_into_cluster($this->usersetid);
     }
     $row = parent::results_row_transform($row);
     $row['canunassign'] = $canenrolintocluster === true ? '1' : '0';
     if (clusteruserpage::can_manage_assoc($row['element_id'], $this->usersetid) !== true) {
         $row['canunassign'] = '0';
     }
     if (isset($row['clstass_plugin'])) {
         if ($row['clstass_plugin'] !== 'manual') {
             $row['canunassign'] = '0';
         }
         $row['clstass_plugin'] = $row['clstass_plugin'] === 'manual' ? 'no' : 'yes';
         $row['clstass_plugin'] = get_string($row['clstass_plugin'], 'moodle');
     }
     return $row;
 }
Beispiel #6
0
 /**
  * Test creating a new userset entity with a default role assignment defined.
  */
 public function test_createusersetwithdefaultroleassignment()
 {
     global $USER, $DB;
     list($rcid, $reid) = $this->create_roles('userset');
     // Setup the editor role to be the default role for the userset context.
     elis::$config->local_elisprogram->default_cluster_role_id = $reid;
     $sysctx = context_system::instance();
     // Assign the test user the creator role.
     role_assign($rcid, $USER->id, $sysctx->id);
     // Create a new userset entity.
     $data = array('idnumber' => 'program100', 'name' => 'program100', 'description' => 'program100');
     $obj = new userset($data);
     $obj->save();
     // Initialize a new userset management page and invoke the code that handles default role assignments.
     $page = new usersetpage();
     $page->after_cm_entity_add($obj);
     $usersetctx = \local_elisprogram\context\userset::instance($obj->id);
     $params = array('roleid' => $reid, 'userid' => $USER->id, 'contextid' => $usersetctx->id);
     $this->assertTrue($DB->record_exists('role_assignments', $params));
 }
Beispiel #7
0
 function display_default()
 {
     global $OUTPUT;
     // Get parameters
     $sort = optional_param('sort', 'name', PARAM_ALPHA);
     $dir = optional_param('dir', 'ASC', PARAM_ALPHA);
     $page = optional_param('page', 0, PARAM_INT);
     $perpage = optional_param('perpage', 30, PARAM_INT);
     // how many per page
     $namesearch = trim(optional_param('search', '', PARAM_TEXT));
     $alpha = optional_param('alpha', '', PARAM_ALPHA);
     $parent = $this->optional_param('id', 0, PARAM_INT);
     $classification = $this->optional_param('classification', NULL, PARAM_SAFEDIR);
     if ($parent) {
         $this->print_tabs('subclusters', array('id' => $parent));
     }
     // Define columns
     $columns = array('name' => array('header' => get_string('userset_name', 'local_elisprogram')), 'display' => array('header' => get_string('userset_description', 'local_elisprogram')));
     // set sorting
     if ($dir !== 'DESC') {
         $dir = 'ASC';
     }
     if (isset($columns[$sort])) {
         $columns[$sort]['sortable'] = $dir;
     } else {
         $sort = 'defaultsortcolumn';
         $columns[$sort]['sortable'] = $dir;
     }
     $extrafilters = array('contexts' => self::get_contexts('local/elisprogram:userset_view'), 'parent' => $parent, 'classification' => $classification);
     $items = cluster_get_listing($sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha, $extrafilters);
     $numitems = cluster_count_records($namesearch, $alpha, $extrafilters);
     self::get_contexts('local/elisprogram:userset_edit');
     self::get_contexts('local/elisprogram:userset_delete');
     $this->print_list_view($items, $numitems, $columns, $filter = null, $alphaflag = true, $searchflag = true);
     if ($this->optional_param('id', 0, PARAM_INT)) {
         //get the non-parent clusters that are accessible based on the edit capability
         $contexts = usersetpage::get_contexts('local/elisprogram:userset_edit');
         $non_parent_clusters = cluster_get_possible_sub_clusters($this->optional_param('id', 0, PARAM_INT), $contexts);
         //display the dropdown if there are one or more available clusters
         if (count($non_parent_clusters) > 0) {
             echo html_writer::start_tag('div', array('align' => 'center'));
             echo get_string('cluster_subcluster_prompt', 'local_elisprogram') . ': ';
             $url = $this->get_new_page(array('action' => 'subcluster', 'id' => $this->optional_param('id', 0, PARAM_INT)))->url . '&amp;subclusterid=';
             echo $OUTPUT->single_select($url, 'subclusterid', $non_parent_clusters);
             echo html_writer::end_tag('div');
         }
     }
 }
Beispiel #8
0
 function get_content()
 {
     global $CFG, $ADMIN, $USER, $HTTPSPAGEREQUIRED, $PAGE, $DB, $SITE;
     require_once $CFG->libdir . '/adminlib.php';
     //dependencies on page classes
     require_once elispm::file('usersetpage.class.php');
     require_once elispm::file('curriculumpage.class.php');
     require_once elispm::file('coursepage.class.php');
     require_once elispm::file('trackpage.class.php');
     //require_once($CFG->dirroot . '/my/pagelib.php');
     /// Determine the users CM access level.
     $access = cm_determine_access($USER->id);
     //make sure local_elisprogram / custom contexts set up correctly
     //to prevent error before the upgrade to ELIS 2
     if (empty($access) || $this->content !== NULL || !defined('CONTEXT_ELIS_PROGRAM')) {
         return $this->content;
     }
     //if we are not on a PM page, disable the expansion of
     //entities in the curr admin tree (logic in curriculum/index.php)
     if (!is_a($PAGE, 'pm_page') && $PAGE->pagetype != 'admin-setting-local_elisprogram_settings') {
         unset($USER->currentitypath);
     }
     // Include Icon CSS.
     $PAGE->requires->css('/local/elisprogram/icons.css');
     //CM entities for placement at the top of the menu
     $cm_entity_pages = array();
     $cm_entity_pages[] = new menuitem('root');
     $num_block_icons = isset(elis::$config->local_elisprogram->num_block_icons) ? elis::$config->local_elisprogram->num_block_icons : 5;
     /*****************************************
      * Clusters
      *****************************************/
     if (!isset(elis::$config->local_elisprogram->display_clusters_at_top_level) || !empty(elis::$config->local_elisprogram->display_clusters_at_top_level)) {
         $manageclusters_css_class = block_elisadmin_get_item_css_class('manageclusters');
         $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance');
         require_once elispm::lib('contexts.php');
         $context_result = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:userset_view', $USER->id);
         $extrafilters = array('contexts' => $context_result, 'parent' => 0);
         $num_records = cluster_count_records('', '', $extrafilters);
         if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, $num_block_icons, '', '', $extrafilters)) {
             foreach ($clusters as $cluster) {
                 $params = array('id' => $cluster->id, 'action' => 'view');
                 //count sub-clusters
                 $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view'));
                 $cluster_count = cluster_count_records('', '', array('parent' => $cluster->id), $cluster_filter);
                 //count associated curricula
                 $curriculum_filter = array('contexts' => curriculumpage::get_contexts('local/elisprogram:program_view'));
                 $curriculum_count = clustercurriculum::count_curricula($cluster->id, $curriculum_filter);
                 $isLeaf = empty($cluster_count) && empty($curriculum_count);
                 $cm_entity_pages[] = block_elisadmin_get_menu_item('userset', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf);
             }
         }
         if ($num_block_icons < $num_records) {
             $cm_entity_pages[] = block_elisadmin_get_menu_summary_item('userset', $cluster_css_class, $num_records - $num_block_icons);
         }
     }
     /*****************************************
      * Curricula
      *****************************************/
     if (!empty(elis::$config->local_elisprogram->display_curricula_at_top_level)) {
         $managecurricula_css_class = block_elisadmin_get_item_css_class('managecurricula');
         $curriculum_css_class = block_elisadmin_get_item_css_class('curriculum_instance');
         require_once elispm::file('curriculumpage.class.php');
         $num_records = curriculum_count_records('', '', curriculumpage::get_contexts('local/elisprogram:program_view'));
         $curricula = $DB->get_recordset(curriculum::TABLE, null, 'priority ASC, name ASC', '*', 0, $num_block_icons);
         foreach ($curricula as $curriculum) {
             $params = array('id' => $curriculum->id, 'action' => 'view');
             //count associated courses
             $course_filter = array('contexts' => coursepage::get_contexts('local/elisprogram:course_view'));
             $course_count = curriculumcourse_count_records($curriculum->id, '', '', $course_filter);
             //count associated tracks
             $track_contexts = trackpage::get_contexts('local/elisprogram:track_view');
             $track_count = track_count_records('', '', $curriculum->id, 0, $track_contexts);
             //count associated clusters
             $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view'));
             $cluster_count = clustercurriculum::count_clusters($curriculum->id, 0, $cluster_filter);
             $isLeaf = empty($course_count) && empty($track_count) && empty($cluster_count);
             $cm_entity_pages[] = block_elisadmin_get_menu_item('curriculum', $curriculum, 'root', $managecurricula_css_class, 0, $curriculum->id, $params, $isLeaf);
         }
         unset($curricula);
         if ($num_block_icons < $num_records) {
             $cm_entity_pages[] = block_elisadmin_get_menu_summary_item('curriculum', $curriculum_css_class, $num_records - $num_block_icons);
         }
     }
     //general cm pages
     $pages = array(new menuitem('dashboard', new menuitempage('dashboardpage'), 'root', '', block_elisadmin_get_item_css_class('dashboard')), new menuitem('admn', null, 'root', get_string('admin'), block_elisadmin_get_item_css_class('admn', true)), new menuitem('bulkuser', new menuitempage('bulkuserpage'), null, get_string('userbulk', 'admin'), block_elisadmin_get_item_css_class('bulkuser')), new menuitem('resultsconfig', new menuitempage('resultsconfigpage'), null, 'Default Results Engine Score Settings', block_elisadmin_get_item_css_class('resultsconfig')));
     // ELIS-3208 - commented out this code as the Jasper reports no longer work in ELIS 2
     /*
             //show the Jasper report server link if applicable
             if (cm_jasper_link_enabled()) {
                 //page action
                 $jasper_link_params = array('action' => 'reportslist');
                 //page instance
                 $jasper_link_page = new menuitempage('jasperreportpage', '', $jasper_link_params);
                 //styling for the link
                 $jasper_link_css = block_elisadmin_get_item_css_class('reportslist');
     
                 $pages[] = new menuitem('reportslist', $jasper_link_page, null, '', $jasper_link_css);
             }
     */
     $pages = array_merge($pages, array(new menuitem('customfields', new menuitempage('customfieldpage', '', array('level' => 'user')), null, '', block_elisadmin_get_item_css_class('customfields')), new menuitem('clusterclassification', new menuitempage('usersetclassificationpage', 'plugins/usetclassify/usersetclassificationpage.class.php'), null, get_string('userset_classification', 'elisprogram_usetclassify'), block_elisadmin_get_item_css_class('clusterclassification')), new menuitem('users', null, 'root', '', block_elisadmin_get_item_css_class('users', true)), new menuitem('manageusers', new menuitempage('userpage'), null, '', block_elisadmin_get_item_css_class('manageusers')), new menuitem('manageclusters', new menuitempage('usersetpage'), null, '', block_elisadmin_get_item_css_class('manageclusters')), new menuitem('curr', null, 'root', get_string('curriculum', 'local_elisprogram'), block_elisadmin_get_item_css_class('curr', true)), new menuitem('certificatelist', new menuitempage('certificatelistpage'), null, '', block_elisadmin_get_item_css_class('certificatelist')), new menuitem('managecurricula', new menuitempage('curriculumpage'), null, '', block_elisadmin_get_item_css_class('managecurricula')), new menuitem('managecourses', new menuitempage('coursepage'), null, '', block_elisadmin_get_item_css_class('managecourses')), new menuitem('manageclasses', new menuitempage('pmclasspage'), null, '', block_elisadmin_get_item_css_class('manageclasses')), new menuitem('crscat', null, 'root', get_string('learningplan', 'local_elisprogram'), block_elisadmin_get_item_css_class('crscat', true)), new menuitem('currentcourses', new menuitempage('coursecatalogpage', '', array('action' => 'current')), null, '', block_elisadmin_get_item_css_class('currentcourses')), new menuitem('availablecourses', new menuitempage('coursecatalogpage', '', array('action' => 'available')), null, '', block_elisadmin_get_item_css_class('availablecourses')), new menuitem('waitlist', new menuitempage('coursecatalogpage', '', array('action' => 'waitlist')), null, get_string('waitlistcourses', 'local_elisprogram'), block_elisadmin_get_item_css_class('waitlist')), new menuitem('rept', null, 'root', get_string('reports', 'local_elisprogram'), block_elisadmin_get_item_css_class('rept', true))));
     if (has_capability('moodle/course:managegroups', context_course::instance($SITE->id))) {
         if (elis::$config->elisprogram_usetgroups->site_course_userset_groups) {
             $pages[] = new menuitem('frontpagegroups', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/index.php?id={$SITE->id}"), 'admn', get_string('frontpagegroups', 'elisprogram_usetgroups'), block_elisadmin_get_item_css_class('manageclusters'));
         }
         if (elis::$config->elisprogram_usetgroups->userset_groupings) {
             $pages[] = new menuitem('frontpagegroupings', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/groupings.php?id={$SITE->id}"), 'admn', get_string('frontpagegroupings', 'elisprogram_usetgroups'), block_elisadmin_get_item_css_class('manageclusters'));
         }
     }
     /**
      * This section adds all the necessary PHP reports to the menu
      */
     //get all report pages, including categories but not including the
     //topmost report element
     $report_pages = block_elisadmin_get_report_tree_items();
     //merge in the reporting page links
     $pages = array_merge($pages, $report_pages);
     if (empty(elis::$config->local_elisprogram->userdefinedtrack)) {
         $pages[] = new menuitem('managetracks', new menuitempage('trackpage'), null, '', block_elisadmin_get_item_css_class('managetracks'));
     }
     $syscontext = context_system::instance();
     if (has_capability('local/elisprogram:config', $syscontext)) {
         $pages[] = new menuitem('configmanager', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/admin/settings.php?section=local_elisprogram_settings"), 'admn', get_string('configuration'), block_elisadmin_get_item_css_class('configuration'));
     }
     $pages[] = new menuitem('notifications', new menuitempage('notifications', 'notificationspage.class.php', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('notifications'));
     //$pages[] = new menuitem('dataimport', new menuitempage('dataimportpage', 'elis_ip/elis_ip_page.php', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('integrationpoint'));
     $pages[] = new menuitem('defaultcls', new menuitempage('configclsdefaultpage', '', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('defaultcls'));
     $pages[] = new menuitem('defaultcrs', new menuitempage('configcrsdefaultpage', '', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('defaultcrs'));
     //turn all pages that have no children into leaf nodes
     menuitemlisting::flag_leaf_nodes($pages);
     //combine the specific entity page listing with the general CM listing
     $menuitemlisting = new menuitemlisting(array_merge($cm_entity_pages, $pages));
     $tree = new treerepresentation($menuitemlisting);
     $this->content = new stdClass();
     $this->content->text = $tree->convert_to_markup();
     $this->content->footer = '';
     $PAGE->requires->yui_module('moodle-local_elisprogram-menuitem', 'M.local_elisprogram.init_menuitem', array($tree->get_js_object(), $CFG->httpswwwroot), null, true);
     return $this->content;
 }
Beispiel #9
0
 /**
  * Test whether a user can enrol users into a sub-userset if they have the required capability on the
  * parent userset.
  */
 public function test_canenrolintoclusterwithparentpermission()
 {
     global $DB;
     $this->load_csv_data();
     // Create role with cap: 'local/elisprogram:class_view'.
     $testrole = new stdClass();
     $testrole->name = 'ELIS Sub-Userset Manager';
     $testrole->shortname = '_test_ELIS_3848';
     $testrole->description = 'ELIS userset enrol into sub-userser';
     $testrole->archetype = '';
     $testrole->id = create_role($testrole->name, $testrole->shortname, $testrole->description, $testrole->archetype);
     // Ensure our new role is assignable to ELIS class contexts.
     set_role_contextlevels($testrole->id, array(CONTEXT_ELIS_USERSET));
     // Ensure the role has our required capability assigned.
     $syscontext = context_system::instance();
     assign_capability('local/elisprogram:userset', CAP_ALLOW, $testrole->id, $syscontext->id, true);
     assign_capability('local/elisprogram:userset_view', CAP_ALLOW, $testrole->id, $syscontext->id, true);
     assign_capability('local/elisprogram:userset_create', CAP_ALLOW, $testrole->id, $syscontext->id, true);
     assign_capability('local/elisprogram:userset_enrol_userset_user', CAP_ALLOW, $testrole->id, $syscontext->id, true);
     $syscontext->mark_dirty();
     // Assign a test user a role within the parent userset.
     $context = \local_elisprogram\context\userset::instance(1);
     role_assign($testrole->id, 100, $context->id);
     $context->mark_dirty();
     // Switch to testuser.
     $USER = $DB->get_record('user', array('id' => 100));
     $USER->access = get_user_accessdata($USER->id);
     load_role_access_by_context($testrole->id, $context, $USER->access);
     // We need to force the accesslib cache to refresh.
     $GLOBALS['USER'] = $USER;
     // Check if the user can enrol users into the sub-userset.
     $this->assertTrue(usersetpage::can_enrol_into_cluster(2));
 }
Beispiel #10
0
 /**
  * Unassign the user from the userset.
  *
  * @param array $elements An array of elements to perform the action on.
  * @param bool $bulkaction Whether this is a bulk-action or not.
  * @return array An array to format as JSON and return to the Javascript.
  */
 protected function _respond_to_js(array $elements, $bulkaction)
 {
     global $DB;
     $usersetid = required_param('id', PARAM_INT);
     $userset = new userset($usersetid);
     // Permissions.
     if (usersetpage::can_enrol_into_cluster($userset->id) !== true) {
         return array('result' => 'fail', 'msg' => get_string('not_permitted', 'local_elisprogram'));
     }
     $unassignnotpermitted = false;
     foreach ($elements as $userid => $label) {
         if ($this->can_unassign($usersetid, $userid)) {
             $assignrec = $DB->get_record(clusterassignment::TABLE, array('userid' => $userid, 'clusterid' => $usersetid));
             if (!empty($assignrec) && $assignrec->plugin === 'manual') {
                 $curstu = new clusterassignment($assignrec);
                 $curstu->delete();
             }
         } else {
             $unassignnotpermitted = true;
         }
     }
     if ($unassignnotpermitted) {
         return array('result' => 'fail', 'msg' => get_string('not_permitted', 'local_elisprogram'));
     } else {
         return array('result' => 'success', 'msg' => 'Success');
     }
 }