/** * Test contexts for userset_groups * * Covers: * local/elisprogram/plugins/usetgroups/lib.php:643 * local/elisprogram/plugins/usetgroups/lib.php:308 * local/elisprogram/plugins/usetgroups/lib.php:601 */ public function test_usersetgroups() { global $DB; set_config('userset_groupings', true, 'elisprogram_usetgroups'); $field = new field(array('shortname' => 'userset_groupings')); $field->load(); $userset = $this->create_userset($field); userset_groups_grouping_helper($userset->id, $userset->name); $field = new field(array('shortname' => 'userset_group')); $field->load(); $userset = $this->create_userset($field); userset_groups_userset_allows_groups($userset->id); }
/** * Updates all parent cluster's groupings with the existence of a group for this cluster * * @param int $clusterid The cluster to check the parents for * @param boolean $include_children If true, make child cluster-groups trickle up the tree * @return boolean Returns true to satisfy event handlers */ function userset_groups_update_grouping_closure($clusterid, $include_children = false) { global $CFG; $enabled = get_config('elisprogram_usetgroups', 'userset_groupings'); if (empty($enabled) || !userset_groups_grouping_allowed($clusterid)) { return true; } $cluster = new userset($clusterid); //get the group id for this cluster if ($groupid = groups_get_group_by_name(SITEID, $cluster->name)) { //go through the chain of parent clusters while (!empty($cluster->parent)) { $cluster = new userset($cluster->parent); //add this to grouping if applicable $grouping = groups_get_grouping_by_name(SITEID, $cluster->name); if ($grouping = groups_get_grouping($grouping)) { groups_assign_grouping($grouping->id, $groupid); //recurse into children if possible if ($include_children) { //get all child clusters $child_cluster_ids = userset_groups_get_child_usersets($cluster->id); foreach ($child_cluster_ids as $child_cluster_id) { //children only if ($child_cluster_id != $cluster->id) { $child_cluster = new userset($child_cluster_id); //make sure the group exists if ($child_groupid = groups_get_group_by_name(SITEID, $child_cluster->name) and userset_groups_userset_allows_groups($child_cluster->id)) { groups_assign_grouping($grouping->id, $child_groupid); } } } } } } } return true; }