コード例 #1
0
ファイル: dbcleanup.php プロジェクト: veritech/pare-project
/**
 * Cleans up all the groups and groupings in a course (it does this best-effort 
 * i.e. if one deletion fails, it still attempts further deletions).
 * IMPORTANT: Note that if the groups and groupings are used by other courses 
 * somehow, they will still be deleted - it doesn't protect against this. 
 * @param int $courseid The id of the course
 * @return boolean True if the clean up was successful, false otherwise. 
 */
function groups_cleanup_groups($courseid)
{
    $success = true;
    // Delete all the groupings
    $groupings = groups_get_groupings($courseid);
    if ($groupings != false) {
        foreach ($groupings as $groupingid) {
            $groupingdeleted = groups_delete_grouping($groupingid);
            if (!$groupingdeleted) {
                $success = false;
            }
        }
    }
    // Delete all the groups
    $groupids = groups_get_groups($courseid);
    if ($groupids != false) {
        foreach ($groupids as $groupid) {
            $groupdeleted = groups_delete_group($groupid);
            if (!$groupdeleted) {
                $success = false;
            }
        }
    }
    return $success;
}
コード例 #2
0
ファイル: lib_test.php プロジェクト: evltuma/moodle
 public function test_grouping_deleted_event()
 {
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $group = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
     $sink = $this->redirectEvents();
     groups_delete_grouping($group->id);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     $this->assertInstanceOf('\\core\\event\\grouping_deleted', $event);
     $this->assertEventLegacyData($group, $event);
     $this->assertSame('groups_grouping_deleted', $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/groupings.php', array('id' => $event->courseid));
     $this->assertEquals($url, $event->get_url());
 }
コード例 #3
0
 /**
  * Delete groupings
  *
  * @param array $groupingids array of grouping ids
  * @return void
  * @since Moodle 2.3
  */
 public static function delete_groupings($groupingids)
 {
     global $CFG, $DB;
     require_once "{$CFG->dirroot}/group/lib.php";
     $params = self::validate_parameters(self::delete_groupings_parameters(), array('groupingids' => $groupingids));
     $transaction = $DB->start_delegated_transaction();
     foreach ($params['groupingids'] as $groupingid) {
         if (!($grouping = groups_get_grouping($groupingid, 'id, courseid', IGNORE_MISSING))) {
             // Silently ignore attempts to delete nonexisting groupings.
             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 = $grouping->courseid;
             throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
         }
         require_capability('moodle/course:managegroups', $context);
         groups_delete_grouping($grouping);
     }
     $transaction->allow_commit();
 }
コード例 #4
0
                break;
            }
            $createdgroups[] = $groupid;
            foreach ($group['members'] as $user) {
                groups_add_member($groupid, $user->id);
            }
            if ($grouping) {
                groups_assign_grouping($grouping->id, $groupid);
            }
        }
        if ($failed) {
            foreach ($createdgroups as $groupid) {
                groups_delete_group($groupid);
            }
            if ($createdgrouping) {
                groups_delete_grouping($createdgrouping);
            }
        } else {
            redirect($returnurl);
        }
    }
}
/// Print header
print_header_simple($strgroups, ': ' . $strgroups, $navigation, '', '', true, '', navmenu($course));
print_heading($strautocreategroups);
if ($error != '') {
    notify($error);
}
/// Display the form
$editform->display();
if ($preview !== '') {
コード例 #5
0
ファイル: lib.php プロジェクト: rushi963/moodle
/**
 * Delete all groupings from course
 *
 * @param int $courseid
 * @param bool $showfeedback
 * @return bool success
 */
function groups_delete_groupings($courseid, $showfeedback = false)
{
    global $DB, $OUTPUT;
    $groupings = $DB->get_recordset_select('groupings', 'courseid = ?', array($courseid));
    foreach ($groupings as $grouping) {
        groups_delete_grouping($grouping);
    }
    // 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_deleted').
    // 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_deleted', $courseid);
    if ($showfeedback) {
        echo $OUTPUT->notification(get_string('deleted') . ' - ' . get_string('groupings', 'group'), 'notifysuccess');
    }
    return true;
}
コード例 #6
0
ファイル: grouping.php プロジェクト: veritech/pare-project
if ($id) {
    if (!($grouping = get_record('groups_groupings', 'id', $id))) {
        error('Grouping ID was incorrect');
    }
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    require_capability('moodle/course:managegroups', $context);
}
/// First create the form
$editform = new grouping_edit_form('grouping.php', compact('grouping', 'courseid'));
/// Override defaults if group is set
if (!empty($grouping)) {
    $editform->set_data($grouping);
}
// preprocess data
if ($delete) {
    if (groups_delete_grouping($id)) {
        redirect(groups_home_url($course->id));
    } else {
        print_error('erroreditgrouping', 'group', groups_home_url($course->id));
    }
}
if ($editform->is_cancelled()) {
    redirect(groups_home_url($courseid, false, $id, false));
} elseif ($data = $editform->get_data()) {
    $success = true;
    if (empty($grouping)) {
        // New grouping
        if (!($id = groups_create_grouping($course->id, $data))) {
            print_error('erroreditgrouping');
        } else {
            $success = (bool) $id;
コード例 #7
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));
        }
    }
}
コード例 #8
0
 public function test_groups_get_grouping()
 {
     $this->resetAfterTest(true);
     $generator = $this->getDataGenerator();
     // Create a course category and course.
     $cat = $generator->create_category(array('parent' => 0));
     $course = $generator->create_course(array('category' => $cat->id));
     $name1 = 'Grouping 1';
     $name2 = 'Grouping 2';
     // Test with an empty and a null idnumber.
     $this->assertFalse(groups_get_grouping_by_name($course->id, ''));
     $this->assertFalse(groups_get_grouping_by_name($course->id, null));
     // Even when a group exists.
     $generator->create_group(array('courseid' => $course->id));
     $this->assertFalse(groups_get_grouping_by_name($course->id, ''));
     $this->assertFalse(groups_get_grouping_by_name($course->id, null));
     // Test with a valid name, but one that doesn't exist yet.
     $this->assertFalse(groups_get_grouping_by_name($course->id, $name1));
     $this->assertFalse(groups_get_grouping_by_name($course->id, $name2));
     // We should now have a valid group returned by the name search.
     $group1 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name1));
     $this->assertEquals($group1->id, groups_get_grouping_by_name($course->id, $name1));
     $this->assertFalse(groups_get_grouping_by_name($course->id, $name2));
     // We should now have a two valid groups returned by the name search.
     $group2 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name2));
     $this->assertEquals($group1->id, groups_get_grouping_by_name($course->id, $name1));
     $this->assertEquals($group2->id, groups_get_grouping_by_name($course->id, $name2));
     // Delete a group.
     $this->assertTrue(groups_delete_grouping($group1));
     $this->assertFalse(groups_get_grouping_by_name($course->id, $name1));
     $this->assertEquals($group2->id, groups_get_grouping_by_name($course->id, $name2));
     /*
      * Group idnumbers are unique within a course so test that we don't
      * retrieve groups for the first course.
      */
     // Create a second course.
     $course = $generator->create_course(array('category' => $cat->id));
     // An empty name should always return a false value.
     $this->assertFalse(groups_get_grouping_by_name($course->id, ''));
     $this->assertFalse(groups_get_grouping_by_name($course->id, null));
     // Our existing names shouldn't be returned here as we're in a different course.
     $this->assertFalse(groups_get_grouping_by_name($course->id, $name1));
     $this->assertFalse(groups_get_grouping_by_name($course->id, $name2));
     // We should be able to reuse the idnumbers again since this is a different course.
     $group1 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name1));
     $this->assertEquals($group1->id, groups_get_grouping_by_name($course->id, $name1));
     $group2 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name2));
     $this->assertEquals($group2->id, groups_get_grouping_by_name($course->id, $name2));
 }
コード例 #9
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);
 }
コード例 #10
0
 function test_delete_grouping()
 {
     $this->assertTrue(groups_delete_grouping($this->groupingid));
     $this->assertFalse(groups_grouping_exists($this->groupingid));
 }
コード例 #11
0
     /// Add people to a group
     if (!empty($data->nonmembers) && !empty($data->groupid) && is_numeric($data->groupid)) {
         $groupmodified = false;
         foreach ($data->nonmembers as $userid) {
             groups_add_member($data->groupid, $userid);
         }
     }
     $selectedgroup = $data->groupid;
 } else {
     if (!empty($data->groupsremove)) {
         if (is_numeric($data->groups)) {
             /// Remove a group, all members become nonmembers
             groups_delete_group($data->groups);
         } else {
             $grpingid = substr($data->groups, 2);
             groups_delete_grouping($grpingid);
         }
     } else {
         if (!empty($data->groupsadd)) {
             /// Create a new group
             if (!empty($data->newgroupname)) {
                 $newgroup->name = $data->newgroupname;
                 $newgroup->courseid = $course->id;
                 $newgroup->description = '';
                 $newgroup->enrolmentkey = '';
                 $newgroup->picture = 0;
                 $newgroup->hidepicture = 0;
                 $newgroup->id = groups_create_group($newgroup);
                 if (!empty($data->groups) && !is_numeric($data->groups)) {
                     $groupingid = substr($data->groups, 2);
                     groups_assign_grouping($groupingid, $newgroup->id);