/**
  * Group updated
  *
  * @param \core\event\group_updated $event
  * @return void
  */
 public static function group_updated(\core\event\group_updated $event)
 {
     global $DB;
     $group = $event->get_record_snapshot('groups', $event->objectid);
     $courseids = local_metagroups_parent_courses($group->courseid);
     foreach ($courseids as $courseid) {
         $course = get_course($courseid);
         if ($metagroup = $DB->get_record('groups', array('courseid' => $course->id, 'idnumber' => $group->id))) {
             $metagroup->name = $group->name;
             groups_update_group($metagroup, false, false);
         }
     }
 }
Example #2
0
                events_trigger('group_deleted', $eventdata);
                redirect('index.php?id=' . $course->id);
            } else {
                print_error('erroreditgroup', 'group', $returnurl);
            }
        }
    }
}
/// First create the form
$editform = new group_form();
$editform->set_data($group);
if ($editform->is_cancelled()) {
    redirect($returnurl);
} elseif ($data = $editform->get_data()) {
    if ($data->id) {
        if (!groups_update_group($data, $editform->_upload_manager)) {
            error('Error updating group');
        }
    } else {
        if (!($id = groups_create_group($data, $editform->_upload_manager))) {
            error('Error creating group');
        }
        $returnurl = $CFG->wwwroot . '/group/index.php?id=' . $course->id . '&group=' . $id;
    }
    redirect($returnurl);
}
$strgroups = get_string('groups');
$strparticipants = get_string('participants');
if ($id) {
    $strheading = get_string('editgroupsettings', 'group');
} else {
Example #3
0
 public function test_group_updated_event_does_not_require_names()
 {
     global $DB;
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
     $sink = $this->redirectEvents();
     $data = new stdClass();
     $data->id = $group->id;
     $data->courseid = $course->id;
     $this->setCurrentTimeStart();
     groups_update_group($data);
     $group = $DB->get_record('groups', array('id' => $group->id));
     // Fetch record with modified timestamp.
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     $this->assertTimeCurrent($group->timemodified);
     $this->assertInstanceOf('\\core\\event\\group_updated', $event);
     $this->assertEventLegacyData($group, $event);
     $this->assertSame('groups_group_updated', $event->get_legacy_eventname());
     $this->assertEquals(context_course::instance($course->id), $event->get_context());
     $this->assertEquals($group->id, $event->objectid);
     $url = new moodle_url('/group/group.php', array('id' => $event->objectid));
     $this->assertEquals($url, $event->get_url());
 }
      break;
  case 'rename':
      // Rename to...
      $groupid = required_param('groupid', PARAM_INT);
      require_capability('mod/grouptool:administrate_groups', $context);
      $name = required_param('name', PARAM_TEXT);
      $group = groups_get_group_by_name($course->id, $name);
      $group = $DB->get_record('groups', array('id' => $group));
      if (!empty($group) && $group->id != $groupid) {
          $result->error = get_string('groupnameexists', 'group', $name);
      } else {
          $group = new stdClass();
          $group->id = $groupid;
          $group->name = $name;
          $group->courseid = (int) $course->id;
          groups_update_group($group);
          if ($name != $DB->get_field('groups', 'name', array('id' => $groupid))) {
              // Error happened...
              $result->error = get_string('couldnt_rename_group', 'grouptool', $name);
          } else {
              $result->message = get_string('renamed_group', 'grouptool', $name);
          }
      }
      break;
  case 'resize':
      // Resize to...
      $groupid = required_param('groupid', PARAM_INT);
      require_capability('mod/grouptool:administrate_groups', $context);
      $size = required_param('size', PARAM_TEXT);
      $sql = '
 SELECT COUNT(reg.id) AS regcnt
Example #5
0
    $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id);
} else {
    $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
}
/// First create the form
$editform = new group_form(null, array('editoroptions' => $editoroptions));
$editform->set_data($group);
if ($editform->is_cancelled()) {
    redirect($returnurl);
} elseif ($data = $editform->get_data()) {
    if (!has_capability('moodle/course:changeidnumber', $context)) {
        // Remove the idnumber if the user doesn't have permission to modify it
        unset($data->idnumber);
    }
    if ($data->id) {
        groups_update_group($data, $editform, $editoroptions);
    } else {
        $id = groups_create_group($data, $editform, $editoroptions);
        $returnurl = $CFG->wwwroot . '/group/index.php?id=' . $course->id . '&group=' . $id;
    }
    redirect($returnurl);
}
$strgroups = get_string('groups');
$strparticipants = get_string('participants');
if ($id) {
    $strheading = get_string('editgroupsettings', 'group');
} else {
    $strheading = get_string('creategroup', 'group');
}
$PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id' => $courseid)));
$PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id' => $courseid)));
function blended_update_group($courseid, $teamname, $mem, $groupid, $ya)
{
    global $DB;
    $data = new object();
    $data->courseid = $courseid;
    $data->name = $teamname;
    $data->description_editor['text'] = ' ';
    $data->description_editor['format'] = 1;
    $data->id = $groupid;
    groups_update_group($data);
    $oldmems = $DB->get_records('groups_members', array('groupid' => $groupid));
    if ($ya == null) {
        foreach ($oldmems as $oldmem) {
            groups_remove_member($groupid, $oldmem->userid);
        }
        $us = $DB->get_records('user');
        for ($y = 0; $y < count($mem); $y++) {
            $use = array();
            foreach ($us as $f => $u) {
                $use[$f] = blended_clean_idnumber($u->idnumber);
                if ($use[$f] == $mem[$y]) {
                    groups_add_member($groupid, $u->id);
                }
            }
        }
    } else {
        if ($ya == true) {
            $memid = $DB->get_records('user');
            foreach ($memid as $mid) {
                if ($mem == substr($mid->idnumber, 0, 8)) {
                    groups_add_member($groupid, $mid->id);
                    $DB->insert_record_raw('blended_member', array('userid' => $mid->id, 'id_member' => $mem, 'id_team' => $groupid, 'leader' => 0));
                    break;
                }
            }
        }
    }
    groups_update_grouping($data);
}
Example #7
0
            if (groups_delete_group($id)) {
                redirect('index.php?id=' . $course->id);
            } else {
                print_error('erroreditgroup', 'group', $returnurl);
            }
        }
    }
}
/// First create the form
$editform = new group_form();
$editform->set_data($group);
if ($editform->is_cancelled()) {
    redirect($returnurl);
} elseif ($data = $editform->get_data()) {
    if ($data->id) {
        groups_update_group($data, $editform);
    } else {
        $id = groups_create_group($data, $editform);
        $returnurl = $CFG->wwwroot . '/group/index.php?id=' . $course->id . '&amp;group=' . $id;
    }
    redirect($returnurl);
}
$strgroups = get_string('groups');
$strparticipants = get_string('participants');
if ($id) {
    $strheading = get_string('editgroupsettings', 'group');
} else {
    $strheading = get_string('creategroup', 'group');
}
$navlinks = array(array('name' => $strparticipants, 'link' => $CFG->wwwroot . '/user/index.php?id=' . $courseid, 'type' => 'misc'), array('name' => $strgroups, 'link' => $CFG->wwwroot . '/group/index.php?id=' . $courseid, 'type' => 'misc'), array('name' => $strheading, 'link' => '', 'type' => 'misc'));
$navigation = build_navigation($navlinks);
Example #8
0
    if (!has_capability('mod/groupselect:select', $context)) {
        $problems[] = get_string('cannotselectnocap', 'mod_groupselect');
    } else {
        if ($groupselect->timedue != 0 and $groupselect->timedue < time()) {
            $problems[] = get_string('notavailableanymore', 'mod_groupselect', userdate($groupselect->timedue));
        }
    }
}
// Group description edit
if ($groupid and $canedit and isset($mygroups[$groupid]) and data_submitted()) {
    $egroup = $DB->get_record_sql("SELECT *\n                                 FROM {groups} g\n                                WHERE g.id = ?", array($groupid));
    if (strlen($newdescription) > create_form::DESCRIPTION_MAXLEN) {
        $newdescription = substr($newdescription, 0, create_form::DESCRIPTION_MAXLEN);
    }
    $egroup->description = $newdescription;
    groups_update_group($egroup);
    echo strip_tags(groupselect_get_group_info($egroup));
    die;
}
// Student group self-creation
if ($cancreate and $isopen) {
    $data = array('id' => $id, 'description' => '');
    $mform = new create_form(null, array($data, $groupselect));
    if ($mform->is_cancelled()) {
        redirect($PAGE->url);
    }
    if ($formdata = $mform->get_data()) {
        // Create a new group and add the creator as a member of it
        $params = array($course->id);
        $names = $DB->get_records_sql("SELECT g.name\n                   FROM {groups} g\n                  WHERE g.courseid = ?", $params);
        $max = 0;
 /**
  * Outputs the content of the administration tab and manages actions taken in this tab
  */
 public function view_administration()
 {
     global $SESSION, $OUTPUT, $PAGE, $DB, $USER, $CFG;
     $output = $PAGE->get_renderer('mod_grouptool');
     $id = $this->cm->id;
     $context = context_course::instance($this->course->id);
     // Get applicable roles!
     $rolenames = array();
     if ($roles = get_profile_roles($context)) {
         foreach ($roles as $role) {
             $rolenames[$role->id] = strip_tags(role_get_name($role, $context));
         }
     }
     $filter = optional_param('filter', null, PARAM_INT);
     if ($filter !== null) {
         set_user_preference('mod_grouptool_group_filter', $filter, $USER->id);
     } else {
         $filter = get_user_preferences('mod_grouptool_group_filter', self::FILTER_ACTIVE, $USER->id);
     }
     $inactivetabs = array();
     $filtertabs['active'] = new tabobject(self::FILTER_ACTIVE, $CFG->wwwroot . '/mod/grouptool/view.php?id=' . $id . '&amp;tab=group_admin&filter=' . self::FILTER_ACTIVE, get_string('active', 'grouptool'), '', false);
     $filtertabs['inactive'] = new tabobject(self::FILTER_INACTIVE, $CFG->wwwroot . '/mod/grouptool/view.php?id=' . $id . '&amp;tab=group_admin&filter=' . self::FILTER_INACTIVE, get_string('inactive'), '', false);
     $filtertabs['all'] = new tabobject(self::FILTER_ALL, $CFG->wwwroot . '/mod/grouptool/view.php?id=' . $id . '&amp;tab=group_admin&filter=' . self::FILTER_ALL, get_string('all'), '', false);
     echo html_writer::tag('div', $OUTPUT->tabtree($filtertabs, $filter, $inactivetabs), array('id' => 'filtertabs'));
     // Check if everything has been confirmed, so we can finally start working!
     if (optional_param('confirm', 0, PARAM_BOOL)) {
         if (isset($SESSION->grouptool->view_administration->createGroupings)) {
             require_capability('mod/grouptool:create_groupings', $this->context);
             $target = required_param('target', PARAM_INT);
             switch ($target) {
                 // ...grpg_target | grpg_groupingname | use_all (0 sel | 1 all).
                 case 0:
                     // Invalid - no action! TODO Add message!
                     $error = true;
                     $preview = '';
                     break;
                 case -2:
                     // One grouping per group!
                     list($error, $preview) = $this->create_group_groupings();
                     break;
                 case -1:
                     // One new grouping for all!
                     list($error, $preview) = $this->update_grouping($target, required_param('name', PARAM_ALPHANUMEXT));
                     break;
                 default:
                     list($error, $preview) = $this->update_grouping($target);
                     break;
             }
             $preview = html_writer::tag('div', $preview, array('class' => 'centered'));
             echo $OUTPUT->box($preview, 'generalbox');
         }
         unset($SESSION->grouptool->view_administration);
     }
     if ($rename = optional_param('rename', 0, PARAM_INT)) {
         // Show Rename Form!
         $gform = new \mod_grouptool\group_rename_form(null, array('id' => $this->cm->id, 'instance' => $this->cm->instance, 'rename' => $rename));
         if (!$gform->is_cancelled() && ($fromform = $gform->get_data())) {
             $group = new stdClass();
             $group->id = $fromform->rename;
             $group->name = $fromform->name;
             $group->courseid = $fromform->courseid;
             groups_update_group($group);
         } else {
             if (!$gform->is_cancelled()) {
                 $data = new stdClass();
                 $data->name = $DB->get_field('groups', 'name', array('id' => $rename));
                 $gform->set_data($data);
                 $gform->display();
                 echo $OUTPUT->footer();
                 die;
             }
         }
     }
     if ($resize = optional_param('resize', 0, PARAM_INT)) {
         // Show Rename Form!
         $gform = new \mod_grouptool\group_resize_form(null, array('id' => $this->cm->id, 'instance' => $this->cm->instance, 'resize' => $resize));
         if (!$gform->is_cancelled() && ($fromform = $gform->get_data())) {
             if (empty($fromform->size)) {
                 $DB->set_field('grouptool_agrps', 'grpsize', null, array('groupid' => $fromform->resize, 'grouptoolid' => $this->cm->id));
             } else {
                 $group = new stdClass();
                 $group->id = $DB->get_field('grouptool_agrps', 'id', array('groupid' => $fromform->resize, 'grouptoolid' => $this->cm->instance));
                 $group->grpsize = $fromform->size;
                 $DB->update_record('grouptool_agrps', $group);
             }
         } else {
             if (!$gform->is_cancelled()) {
                 $data = new stdClass();
                 $data->size = $DB->get_field('grouptool_agrps', 'grpsize', array('groupid' => $resize, 'grouptoolid' => $this->cm->instance));
                 $gform->set_data($data);
                 $gform->display();
                 echo $OUTPUT->footer();
                 die;
             }
         }
     }
     if ($delete = optional_param('delete', 0, PARAM_INT)) {
         if (!optional_param('confirm', 0, PARAM_BOOL)) {
             // Show Confirm!
             $cancel = new moodle_url($PAGE->url);
             $continue = new moodle_url($cancel, array('confirm' => 1, 'delete' => $delete));
             $cancel = new single_button($cancel, get_string('no'), 'post');
             $continue = new single_button($continue, get_string('yes'), 'post');
             $confirmtext = get_string('confirm_delete', 'grouptool');
             echo $this->confirm($confirmtext, $continue, $cancel);
             echo $OUTPUT->footer();
             die;
         } else {
             // Delete it!
             groups_delete_group($delete);
         }
     }
     if ($toggle = optional_param('toggle', 0, PARAM_INT)) {
         if (!empty($toggle)) {
             $conditions = array('grouptoolid' => $this->cm->instance, 'groupid' => $toggle);
             if (!$DB->record_exists('grouptool_agrps', $conditions)) {
                 echo $OUTPUT->box($OUTPUT->notification(get_string('group_not_found', 'grouptool'), 'notifyproblem', $conditions), 'generalbox');
             } else {
                 $record = $DB->get_record('grouptool_agrps', $conditions);
                 if (!empty($record->active)) {
                     $DB->set_field('grouptool_agrps', 'active', 0, $conditions);
                 } else {
                     $DB->set_field('grouptool_agrps', 'active', 1, $conditions);
                 }
             }
         }
     }
     if (($bulkaction = optional_param('bulkaction', null, PARAM_ALPHA)) && ($selected = optional_param_array('selected', array(), PARAM_INT)) && optional_param('start_bulkaction', 0, PARAM_BOOL)) {
         switch ($bulkaction) {
             case 'activate':
                 // ...also via ajax bulk action?
                 // Activate now!
                 $groups = optional_param_array('selected', null, PARAM_INT);
                 if (!empty($groups)) {
                     list($grpsql, $grpparams) = $DB->get_in_or_equal($groups);
                     $DB->set_field_select("grouptool_agrps", "active", 1, " grouptoolid = ? AND groupid " . $grpsql, array_merge(array($this->cm->instance), $grpparams));
                 }
                 echo $OUTPUT->notification(get_string('activated_groups', 'grouptool'), 'notifysuccess');
                 $continue = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
                 echo $this->confirm('', $continue);
                 break;
             case 'deactivate':
                 // ...also via ajax bulk action?
                 // Deactivate now!
                 $groups = optional_param_array('selected', null, PARAM_INT);
                 if (!empty($groups)) {
                     list($grpsql, $grpparams) = $DB->get_in_or_equal($groups);
                     $DB->set_field_select("grouptool_agrps", "active", 0, " grouptoolid = ? AND groupid " . $grpsql, array_merge(array($this->cm->instance), $grpparams));
                 }
                 echo $OUTPUT->notification(get_string('deactivated_groups', 'grouptool'), 'notifysuccess');
                 $continue = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
                 echo $this->confirm('', $continue);
                 break;
             case 'delete':
                 // ...also via ajax bulk action?
                 // Show confirmation dialogue!
                 if (optional_param('confirm', 0, PARAM_BOOL)) {
                     $groups = optional_param_array('selected', null, PARAM_INT);
                     $groups = $DB->get_records_list('groups', 'id', $groups);
                     foreach ($groups as $group) {
                         groups_delete_group($group);
                     }
                     echo $OUTPUT->notification(get_string('successfully_deleted_groups', 'grouptool'), 'notifysuccess');
                     $continue = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
                     echo $this->confirm('', $continue);
                 } else {
                     $cancel = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
                     $params = array('confirm' => 1, 'bulkaction' => 'delete', 'start_bulkaction' => 1);
                     $text = get_string('confirm_delete', 'grouptool') . html_writer::start_tag('ul');
                     $groups = $DB->get_records_list('groups', 'id', $selected);
                     foreach ($selected as $select) {
                         $params['selected[' . $select . ']'] = $select;
                         $text .= html_writer::tag('li', $groups[$select]->name);
                     }
                     $text .= html_writer::end_tag('ul');
                     $continue = new moodle_url($cancel, $params);
                     echo $this->confirm($text, $continue, $cancel);
                     echo $OUTPUT->footer();
                     die;
                 }
                 break;
             case 'grouping':
                 // Show grouping creation form!
                 $selected = optional_param_array('selected', array(), PARAM_INT);
                 $mform = new \mod_grouptool\groupings_creation_form(null, array('id' => $id, 'selected' => $selected));
                 $groups = $DB->get_records_list('groups', 'id', $selected);
                 if ($mform->is_cancelled()) {
                     $bulkaction = null;
                     $selected = array();
                 } else {
                     if ($fromform = $mform->get_data()) {
                         // Some groupings should be created...
                         if ($fromform->target == -2) {
                             // One new grouping per group!
                             foreach ($groups as $group) {
                                 $grouping = new stdClass();
                                 if (!($grouping->id = groups_get_grouping_by_name($this->course->id, $group->name))) {
                                     $grouping = new stdClass();
                                     $grouping->courseid = $this->course->id;
                                     $grouping->name = $group->name;
                                     $grouping->id = groups_create_grouping($grouping);
                                 }
                                 // Insert group!
                                 groups_assign_grouping($grouping->id, $group->id);
                             }
                         } else {
                             if ($fromform->target == -1) {
                                 // One new grouping!
                                 // Create grouping if it doesn't exist...
                                 $grouping = new stdClass();
                                 if (!($grouping->id = groups_get_grouping_by_name($this->course->id, $fromform->name))) {
                                     $grouping = new stdClass();
                                     $grouping->courseid = $this->course->id;
                                     $grouping->name = trim($fromform->name);
                                     $grouping->id = groups_create_grouping($grouping);
                                 }
                                 // Insert groups!
                                 foreach ($groups as $group) {
                                     groups_assign_grouping($grouping->id, $group->id);
                                 }
                             } else {
                                 if ($fromform->target > 0) {
                                     // Existing Grouping!
                                     $grouping = groups_get_grouping($fromform->target);
                                     if ($grouping) {
                                         foreach ($groups as $group) {
                                             groups_assign_grouping($grouping->id, $group->id);
                                         }
                                     }
                                 }
                             }
                         }
                         // ...redirect to show sortlist again!
                         $url = new moodle_url('/mod/grouptool/view.php', array('id' => $this->cm->id, 'tab' => 'group_admin', 'filter' => $filter));
                         $text = $OUTPUT->notification(get_string('groupings_created_and_groups_added', 'grouptool'), 'notifymessage');
                         echo $this->confirm($text, $url);
                     } else {
                         $mform->display();
                     }
                 }
                 break;
         }
     }
     if (!$bulkaction || !$selected || !optional_param('start_bulkaction', 0, PARAM_BOOL)) {
         // Show form!
         $formaction = new moodle_url('/mod/grouptool/view.php', array('id' => $this->cm->id, 'tab' => 'group_admin', 'filter' => $filter));
         $mform = new MoodleQuickForm('bulk', 'post', $formaction, '');
         $mform->addElement('hidden', 'sesskey');
         $mform->setDefault('sesskey', sesskey());
         $sortlist = new \mod_grouptool\output\sortlist($this->course->id, $this->cm, $filter);
         $sortlistcontroller = new \mod_grouptool\output\sortlist_controller($sortlist);
         $mform->addElement('html', $output->render($sortlistcontroller));
         $mform->addElement('html', $output->render($sortlist));
         $actions = array('' => get_string('choose', 'grouptool'), 'activate' => get_string('setactive', 'grouptool'), 'deactivate' => get_string('setinactive', 'grouptool'), 'delete' => get_string('delete'), 'grouping' => get_string('createinsertgrouping', 'grouptool'));
         $grp = array();
         $grp[] =& $mform->createElement('static', 'with_selection', '', get_string('with_selection', 'grouptool'));
         $grp[] =& $mform->createElement('select', 'bulkaction', '', $actions);
         $grp[] =& $mform->createElement('submit', 'start_bulkaction', get_string('start', 'grouptool'));
         $mform->addGroup($grp, 'actiongrp', '', ' ', false);
         $mform->disable_form_change_checker();
         $mform->display();
         switch ($filter) {
             case self::FILTER_ACTIVE:
                 $curfilter = 'active';
                 break;
             case self::FILTER_INACTIVE:
                 $curfilter = 'inactive';
                 break;
             case self::FILTER_ALL:
                 $curfilter = 'all';
                 break;
         }
         $PAGE->requires->yui_module('moodle-mod_grouptool-administration', 'M.mod_grouptool.init_administration', array(array('lang' => current_language(), 'contextid' => $this->context->id, 'filter' => $curfilter, 'filterid' => $filter, 'globalsize' => $this->grouptool->grpsize)));
         $PAGE->requires->strings_for_js(array('active', 'inactive', 'confirm_delete'), 'mod_grouptool');
         $PAGE->requires->string_for_js('ajax_edit_size_help', 'mod_grouptool');
         $PAGE->requires->strings_for_js(array('yes', 'no'), 'moodle');
     }
 }
 /**
  * Create or update new group and return id of group.
  *
  * @param object $booking
  * @param object $option
  * @return int
  */
 public function group($bookingtmp = NULL, $optiontmp = NULL)
 {
     global $DB;
     $booking = clone $bookingtmp;
     $option = clone $optiontmp;
     if ($booking->addtogroup == 1 && $option->courseid > 0) {
         $cm = get_coursemodule_from_instance('booking', $booking->id);
         $tags = new booking_tags($cm);
         $booking = $tags->bookingReplace($booking);
         $option = $tags->optionReplace($option);
         $newGroupData = new stdClass();
         if (isset($option->id)) {
             $groupid = $DB->get_field('booking_options', 'groupid', array('id' => $option->id));
             if (!is_null($groupid) && $groupid > 0) {
                 $newGroupData->id = $groupid;
             }
             $newGroupData->courseid = $option->courseid;
             $newGroupData->name = $booking->name . ' - ' . $option->text . ' - ' . $option->id;
             $newGroupData->description = $booking->name . ' - ' . $option->text;
             $newGroupData->descriptionformat = FORMAT_HTML;
             if (isset($newGroupData->id)) {
                 groups_update_group($newGroupData);
                 return $newGroupData->id;
             } else {
                 return groups_create_group($newGroupData);
             }
         }
     } else {
         return 0;
     }
 }
/**
 * This function is called when a 'group_updated' event is triggered.
 *
 *  @param object $eventdata The course object created.
 *  @return boolean Always return true so that the event gets cleared.
 *
 */
function fn_group_updated_handler($eventdata)
{
    global $CFG;
    static $eventinprogress;
    require_once "{$CFG->dirroot}/enrol/enrol.class.php";
    /// Set a semaphore so that we don't do this for any group updated from here.
    /// Without this, we would do the same operations again for every update made in this function.
    if (!empty($eventinprogress)) {
        return true;
    } else {
        $eventinprogress = true;
    }
    /// If we aren't using site groups, do nothing.
    if (empty($CFG->block_fn_site_groups_enabled)) {
        return true;
    }
    /// Only care about site groups.
    if ($eventdata->courseid != SITEID) {
        return true;
    }
    /// If no courses, nothing to do.
    if (!($courses = get_records('block_fn_site_groups', 'sitegroupid', $eventdata->id))) {
        return true;
    }
    foreach ($courses as $course) {
        if ($course->courseid != SITEID) {
            $um = false;
            $grpdata = new Object();
            $grpdata->id = $course->coursegroupid;
            if (isset($eventdata->name)) {
                $grpdata->name = $eventdata->name;
            }
            if (isset($eventdata->description)) {
                $grpdata->description = $eventdata->description;
            }
            if (isset($eventdata->enrolmentkey)) {
                $grpdata->enrolmentkey = $eventdata->enrolmentkey;
            }
            if (isset($eventdata->hidepicture)) {
                $grpdata->hidepicture = $eventdata->hidepicture;
            }
            $grpdata->courseid = $course->courseid;
            if (isset($eventdata->picture)) {
                $grpdata->picture = $eventdata->picture;
                //// *** NEED TO FIGURE OUT HOW TO GET A PICTURE COPIED *** ////
                //                    $um = true;
            }
            /// This will generate another group create event. Will that be a problem?
            groups_update_group($grpdata, $um);
        }
    }
    return true;
}
Example #12
0
    } else {
        // Updating group
        $group = groups_get_group($data->id);
        if (groups_group_name_exists($courseid, $data->name) && $group->name != $data->name) {
            $error = get_string('groupnameexists', 'group', $data->name);
            $success = false;
        } elseif (!groups_update_group($data, $course->id)) {
            print_error('groupnotupdated');
        }
    }
    // Handle file upload
    if ($success) {
        require_once "{$CFG->libdir}/gdlib.php";
        if (save_profile_image($id, $editform->_upload_manager, 'groups')) {
            $data->picture = 1;
            $success = $success && groups_update_group($data, $course->id);
        }
    }
    if ($success) {
        redirect(groups_home_url($course->id, $id, $groupingid, false));
    } elseif (empty($error)) {
        print_error('erroreditgroup', 'group', groups_home_url($course->id));
    }
}
$strgroups = get_string('groups');
$strparticipants = get_string('participants');
if ($id) {
    $strheading = get_string('editgroupsettings', 'group');
} else {
    $strheading = get_string('creategroup', 'group');
}
Example #13
-1
function blended_actualizar_agrupamiento($updated_teams, grade_item $item, $blended, $delete_empty)
{
    global $DB;
    $output = '';
    $r = 0;
    //obtengo el identificador del curso
    $grouping = blended_get_grouping($item, $blended);
    //groups_get_grouping($groupingid,'*',MUST_EXIST);//$DB->get_record('groupings',array('id'=>$groupingid));
    $courseid = $grouping->courseid;
    //Obtención de la  lista de id de los usuarios introducidos en el curso:
    $lista_usuarios = get_enrolled_users(context_course::instance($courseid), '', 0, 'u.id,u.idnumber');
    $lista_idnumbers = array();
    // 	//Obtenci�n de la lista de 'idnumber' de estos usuarios
    foreach ($lista_usuarios as $id => $lista) {
        if (!empty($lista->idnumber)) {
            $lista_idnumbers[$id] = $lista->idnumber;
        }
        // 		$r++;
    }
    // 	$r=0;
    // 	$lista_id=array();
    // 	foreach($lista_idnumbers as $lista){
    // 		$lista_id[$r]=blended_clean_idnumber($lista);
    // 		$r++;
    // 	}
    $members_processed = array();
    /* Actualizo los grupos actualizando el nombre del grupo
       y volviendo a introducir los miembros comprobando que el usuario introducido existe */
    $r = 0;
    foreach ($updated_teams as $i => $updatedteam) {
        // Check members
        $form_members = array();
        foreach ($updatedteam->members as $memberid) {
            //compruebo que el usuario introducido existe y si es as� que lo guarde
            if (key_exists($memberid, $lista_idnumbers)) {
                // user is specified by moodle id
                if (array_search($memberid, $form_members) === false) {
                    $form_members[] = $memberid;
                }
            } else {
                if (key_exists($memberid, $lista_usuarios)) {
                    // user is specified by id_number
                    if (array_search($memberid, $form_members) === false) {
                        $form_members[] = $memberid;
                    }
                }
            }
        }
        // Update/Create/delete Group
        // Create/Update Group information
        //
        if (count($form_members) == 0 && $delete_empty) {
            // An empty membership deletes the group ??
            groups_delete_group($updatedteam->id);
        } else {
            //guardo los miembros en un array
            $current_team = blended_get_team($updatedteam->id);
            if ($current_team) {
                //si existe lo actualizo
                $current_team->name = $updatedteam->name;
                groups_update_group($current_team);
            } else {
                if (count($form_members) > 0 || $updatedteam->name != '') {
                    //si no existe lo creo
                    $itemname = blended_get_item_name($item);
                    $data = new stdClass();
                    $data->courseid = $courseid;
                    $data->name = $updatedteam->name;
                    $data->description_editor['text'] = "Group for activity:  '{$itemname}'.";
                    $data->description_editor['format'] = FORMAT_PLAIN;
                    $updatedteam->id = groups_create_group($data);
                    groups_assign_grouping($grouping->id, $updatedteam->id, time(), true);
                } else {
                    continue;
                    // team with no id, no name, and no components
                }
            }
            $current_team = blended_get_team($updatedteam->id, true);
            $current_members = array_keys($current_team->members);
            // find members to remove
            $members_to_delete = array_diff($current_members, $form_members);
            $members_to_add = array_diff($form_members, $current_members);
            // remove old members
            $need_reelect_leader = false;
            foreach ($members_to_delete as $memberid) {
                $need_reelect_leader = $current_team->leaderid == $memberid;
                blended_remove_team_member($current_team, $memberid);
                //				     groups_remove_member($team->id, $member->id);
            }
            // update team conf
            $current_team = blended_get_team($current_team);
            // Add current members
            foreach ($members_to_add as $memberid) {
                groups_add_member($current_team->id, $memberid);
                if ($memberid == $current_team->leaderid) {
                    $need_reelect_leader = false;
                }
                if (key_exists($memberid, $members_processed)) {
                    $members_processed[$memberid]++;
                } else {
                    $members_processed[$memberid] = 1;
                }
            }
            if (!isset($current_team->leaderid)) {
                $need_reelect_leader = true;
            }
            // check leadership
            if (count($members_to_add) > 0 && count($members_to_delete) > 0 && $need_reelect_leader) {
                // elect new leader
                blended_set_team_leaderid($current_team->id, $form_members[0]);
                global $OUTPUT, $DB;
                $a = new stdClass();
                $a->username = fullname($DB->get_record('user', array('id' => $form_members[0])));
                $a->teamname = $current_team->name;
                $output .= $OUTPUT->notification(get_string('userpromotedtoleader', 'blended', $a));
            }
        }
    }
    return $output;
    // 	//Actualizaci�n de las calificaciones(si existen) : comparar los miembros con los de "grade_grades" y si
    // 	//no estan en el vector borrarlos de la tabla
    $grades_moodle = grade_get_grades($courseid, $item->itemtype, $item->itemmodule, $item->iteminstance);
    $grades_item = $grades_moodle->items[0];
    $grades = $grades_item->grades;
    //Para cada miembro de la tabla miro si esta en el vector $miembros_grupos
    $cont_gr = 0;
    $cont_group = 0;
    foreach ($grades as $grade) {
        foreach ($miembros_grupos as $miembro_gr) {
            foreach ($miembro_gr as $miembro) {
                if ($grade->userid != $miembro->id) {
                    $cont_gr++;
                }
                if ($cont_gr == count($miembro_gr)) {
                    $cont_group++;
                    continue;
                }
            }
            if ($cont_gr == count($miembros_grupos)) {
                print_error("borra en tabla!!");
                //Entonces ese id no esta en los mimebros y hay que borrarlo de la tabla
                $DB->delete_records('grade_grades', array('itemid' => $grade_item->id, 'userid' => $grade->userid));
                continue;
            }
        }
    }
    // 	$DB->delete_records('grade_grades',array('itemid'=>$grade_item->id));
    //Comprobaci�n de la repetici�n de miembros en distintos equipos:
    $contador = array();
    foreach ($lista_idnumbers as $t) {
        $valor = 1;
        foreach ($miembros_grupos as $miembro_gr) {
            foreach ($miembro_gr as $miembro) {
                if ($miembro->idnumber == $t) {
                    //meto en un contador para el valor del id de cada usuario las veces que se repite
                    $contador[$miembro->id] = $valor;
                    $valor++;
                }
            }
        }
    }
    return $contador;
}