function test_groups_grouping_matches() { $groupinginfo->name = 'Grouping Testname:' . $this->getLabel(); $groupinginfo->description = 'Grouing Test Description:' . $this->getLabel(); $this->assertTrue($this->groupingid = groups_create_grouping($this->courseid, $groupinginfo)); $this->assertTrue(groups_grouping_matches($this->courseid, $groupinginfo->name, $groupinginfo->description)); }
function restore_create_groupings($restore, $xml_file) { global $CFG, $db; $status = true; $status2 = true; //Check it exists if (!file_exists($xml_file)) { $status = false; } //Get info from xml if ($status) { //groupings will contain the old_id of every group //in backup_ids->info will be the real info (serialized) $groupings = restore_read_xml_groupings($restore, $xml_file); } //Now, if we have anything in groupings, we have to restore that grouping if ($groupings) { if ($groupings !== true) { //Iterate over each group foreach ($groupings as $grouping) { //Get record from backup_ids $data = backup_getid($restore->backup_unique_code, "groupings", $grouping->id); //Init variables $create_grouping = false; if ($data) { //Now get completed xmlized object $info = $data->info; //Now build the GROUPING record structure $gro = new Object(); ///$gro->id = backup_todb($info['GROUPING']['#']['ID']['0']['#']); $gro->name = backup_todb($info['GROUPING']['#']['NAME']['0']['#']); $gro->description = backup_todb($info['GROUPING']['#']['DESCRIPTION']['0']['#']); $gro->timecreated = backup_todb($info['GROUPING']['#']['TIMECREATED']['0']['#']); //Now search if that group exists (by name and description field) in //restore->course_id course $gro_db = groups_grouping_matches($restore->course_id, $gro->name, $gro->description); //If it doesn't exist, create if (!$gro_db) { $create_grouping = true; } //If we must create the group if ($create_grouping) { //The structure is equal to the db, so insert the grouping TODO: RESTORE. $newid = groups_create_grouping($restore->course_id, $gro); } else { //get current group id $newid = $gro_db->id; } if ($newid) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, "groupings", $grouping->id, $newid); } //Now restore links from groupings to groups $status2 = restore_create_groupings_groups($newid, $info, $restore); } } //(Now, restore grouping_files) } } else { $status = false; } return $status && $status2; }