/**
  * Unassign a group from a grouping
  *
  * @param array $unassignments of arrays with keys groupid, groupingid
  * @return void
  * @since Moodle 2.3
  */
 public static function unassign_grouping($unassignments)
 {
     global $CFG, $DB;
     require_once "{$CFG->dirroot}/group/lib.php";
     $params = self::validate_parameters(self::unassign_grouping_parameters(), array('unassignments' => $unassignments));
     $transaction = $DB->start_delegated_transaction();
     foreach ($params['unassignments'] as $unassignment) {
         // Validate params.
         $groupingid = $unassignment['groupingid'];
         $groupid = $unassignment['groupid'];
         $grouping = groups_get_grouping($groupingid, 'id, courseid', MUST_EXIST);
         $group = groups_get_group($groupid, 'id, courseid', MUST_EXIST);
         if (!$DB->record_exists('groupings_groups', array('groupingid' => $groupingid, 'groupid' => $groupid))) {
             // Continue silently if the group is not assigned to the grouping.
             continue;
         }
         // Now security checks.
         $context = context_course::instance($grouping->courseid);
         try {
             self::validate_context($context);
         } catch (Exception $e) {
             $exceptionparam = new stdClass();
             $exceptionparam->message = $e->getMessage();
             $exceptionparam->courseid = $group->courseid;
             throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
         }
         require_capability('moodle/course:managegroups', $context);
         groups_unassign_grouping($groupingid, $groupid);
     }
     $transaction->allow_commit();
 }
Пример #2
0
if ($frm = data_submitted() and confirm_sesskey()) {
    if (isset($frm->cancel)) {
        redirect($returnurl);
    } else {
        if (isset($frm->add) and !empty($frm->addselect)) {
            foreach ($frm->addselect as $groupid) {
                // Ask this method not to purge the cache, we'll do it ourselves afterwards.
                groups_assign_grouping($grouping->id, (int) $groupid, null, false);
            }
            // Invalidate the course groups cache seeing as we've changed it.
            cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($courseid));
        } else {
            if (isset($frm->remove) and !empty($frm->removeselect)) {
                foreach ($frm->removeselect as $groupid) {
                    // Ask this method not to purge the cache, we'll do it ourselves afterwards.
                    groups_unassign_grouping($grouping->id, (int) $groupid, false);
                }
                // Invalidate the course groups cache seeing as we've changed it.
                cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($courseid));
            }
        }
    }
}
$currentmembers = array();
$potentialmembers = array();
if ($groups = $DB->get_records('groups', array('courseid' => $courseid), 'name')) {
    if ($assignment = $DB->get_records('groupings_groups', array('groupingid' => $grouping->id))) {
        foreach ($assignment as $ass) {
            $currentmembers[$ass->groupid] = $groups[$ass->groupid];
            unset($groups[$ass->groupid]);
        }
Пример #3
0
/**
 * Remove all groups from all groupings in course
 *
 * @param int $courseid
 * @param bool $showfeedback
 * @return bool success
 */
function groups_delete_groupings_groups($courseid, $showfeedback = false)
{
    global $DB, $OUTPUT;
    $groupssql = "SELECT id FROM {groups} g WHERE g.courseid = ?";
    $results = $DB->get_recordset_select('groupings_groups', "groupid IN ({$groupssql})", array($courseid), '', 'groupid, groupingid');
    foreach ($results as $result) {
        groups_unassign_grouping($result->groupingid, $result->groupid, false);
    }
    // Invalidate the grouping cache for the course
    cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($courseid));
    // TODO MDL-41312 Remove events_trigger_legacy('groups_groupings_groups_removed').
    // This event is kept here for backwards compatibility, because it cannot be
    // translated to a new event as it is wrong.
    events_trigger_legacy('groups_groupings_groups_removed', $courseid);
    // no need to show any feedback here - we delete usually first groupings and then groups
    return true;
}
Пример #4
0
function blended_delete_sign_member_or_group($idteam, $member, $option)
{
    global $DB;
    $blended_teams = $DB->get_records('blended_team');
    foreach ($blended_teams as $blended_team) {
        if ($blended_team->id_team == $idteam) {
            $f = $blended_team;
        }
    }
    $g = $DB->get_record('groups', array('id' => $idteam));
    $l = $DB->get_record('blended_assign_grouping', array('id_assign' => $f->id_assignment));
    if ($option == 'member') {
        $del = groups_remove_member($idteam, $member->userid);
        blended_delete_team_member($idteam, $member->id);
    }
    if ($option == 'group') {
        $del = groups_delete_group($idteam);
        groups_unassign_grouping($l->id_grouping, $idteam);
        blended_delete_team($idteam, $f->id_assignment);
        blended_delete_team_member($idteam);
        //Se debe realizar la comprobación de que si no hay mas equipos se borre el agrupamiento
        if (!($teams = $DB->get_records('groupings_groups', array('groupingid' => $l->id_grouping)))) {
            groups_delete_grouping($l->id_grouping);
            $DB->delete_records('blended_assign_grouping', array('id_grouping' => $l->id_grouping));
        }
    }
}
Пример #5
0
 /**
  * Create a grouping for each selected groupmoodle-groups
  *
  * Uses $SESSION->grouptool->view_administration->use_all to determin if groupings for all
  * or just selected groups should be created and also uses
  * $SESSION->grouptool->view_administration->grouplist[$group->id]['active']
  * to determin which groups have been selected
  *
  * @param int $courseid optional id of course to create for
  * @param bool $previewonly optional only show preview of created groups
  * @return array ( 0 => error, 1 => message )
  */
 private function create_group_groupings($courseid = null, $previewonly = false)
 {
     global $SESSION, $PAGE, $OUTPUT;
     require_capability('mod/grouptool:create_groupings', $this->context);
     // Create groupings!
     $created = array();
     $error = false;
     $return = "";
     $table = new html_table();
     $table->attributes['class'] = 'centeredblock';
     $table->head = array(new html_table_cell(get_string('grouping', 'group')), new html_table_cell(get_string('info') . '/' . get_string('groups')));
     // Get all course-groups!
     if ($courseid == null) {
         if (isset($this->course->id)) {
             $courseid = $this->course->id;
         } else {
             print_error('coursemisconf');
         }
     }
     $groups = groups_get_all_groups($courseid);
     $ids = array();
     foreach ($groups as $group) {
         $row = array(new html_table_cell($group->name));
         $active = $SESSION->grouptool->view_administration->grouplist[$group->id]['active'];
         if (empty($SESSION->grouptool->view_administration->use_all) && !$active) {
             continue;
         }
         $groupid = $group->id;
         if (groups_get_grouping_by_name($courseid, $group->name)) {
             // Creation of grouping failed!
             if ($previewonly) {
                 $text = get_string('grouping_exists_error_prev', 'grouptool');
             } else {
                 $text = get_string('grouping_exists_error', 'grouptool');
             }
             $cell = new html_table_cell($OUTPUT->notification($text, 'notifyproblem'));
             $row[] = $cell;
             $error = true;
         } else {
             $ids[] = $group->id;
             $groupingid = groups_create_grouping($group);
             if ($groupingid) {
                 if (!groups_assign_grouping($groupingid, $groupid)) {
                     if ($previewonly) {
                         $text = get_string('group_assign_error_prev', 'grouptool');
                     } else {
                         $text = get_string('group_assign_error', 'grouptool');
                     }
                     $cell = new html_table_cell($OUTPUT->notification($text, 'notifyproblem'));
                     $row[] = $cell;
                     $error = true;
                 } else {
                     if ($previewonly) {
                         $content = $group->name;
                     } else {
                         $content = $OUTPUT->notification(get_string('grouping_creation_success', 'grouptool', $group->name), 'notifysuccess');
                     }
                     $cell = new html_table_cell($content);
                     $row[] = $cell;
                     $created[] = $groupingid;
                 }
             } else {
                 if ($previewonly) {
                     $text = get_string('grouping_creation_error_prev', 'grouptool');
                 } else {
                     $text = get_string('grouping_creation_error', 'grouptool');
                 }
                 $cell = new html_table_cell($OUTPUT->notification($text, 'notifyproblem'));
                 $row[] = $cell;
                 $error = true;
             }
         }
         $table->data[] = new html_table_row($row);
         $return = html_writer::table($table);
     }
     if ($previewonly || $error && !$previewonly) {
         // Undo everything!
         foreach ($created as $groupingid) {
             $groupingsgroups = groups_get_all_groups($courseid, 0, $groupingid);
             foreach ($groupingsgroups as $group) {
                 groups_unassign_grouping($groupingid, $group->id);
             }
             groups_delete_grouping($groupingid);
         }
     } else {
         if (!$previewonly) {
             // Trigger the event!
             \mod_grouptool\event\groupings_created::create_from_object($this->cm, $ids)->trigger();
         }
     }
     return array(0 => $error, 1 => $return);
 }
 if (!empty($data->groupsremovefrom)) {
     /// Remove group from groupings
     if (!empty($data->groups) && is_numeric($data->groups)) {
         if ($groupings = get_records('groupings_groups', 'groupid', $data->groups)) {
             foreach ($groupings as $grouping) {
                 groups_unassign_grouping($grouping->groupingid, $data->groups);
             }
         }
     }
 } else {
     if (!empty($data->groupingsmove)) {
         /// Move group to groupings
         if (!empty($data->groups) && is_numeric($data->groups)) {
             if ($groupings = get_records('groupings_groups', 'groupid', $data->groups)) {
                 foreach ($groupings as $grouping) {
                     groups_unassign_grouping($grouping->groupingid, $data->groups);
                 }
             }
             groups_assign_grouping($data->groupingsmove, $data->groups);
         }
     } else {
         if (!empty($data->membersremove)) {
             /// Remove selected people from a particular group
             if (!empty($data->members) && !empty($data->groupid) && is_numeric($data->groupid)) {
                 foreach ($data->members as $userid) {
                     groups_remove_member($data->groupid, $userid);
                     //                            og_deassign_group_registrar($userid);
                     //                            og_set_student($userid); /// Deassigns as a designated teacher.
                 }
             }
             $selectedgroup = $data->groupid;