classes/page/acp.php [1053:1117]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                throw new \moodle_exception('acp_teamconnections_exception_team_already_connected', 'local_o365', $redirecturl);
            }

            // Create record in local_o365_object table.
            if ($grouprecord = $DB->get_record('local_o365_objects',
                ['type' => 'group', 'subtype' => 'course', 'moodleid' => $courseid])) {
                $grouprecord->objectid = $teamcacherecord->objectid;
                $grouprecord->o365name = $teamcacherecord->name;
                $grouprecord->metadata = null;
                $DB->update_record('local_o365_objects', $grouprecord);
            } else {
                $grouprecord = new \stdClass();
                $grouprecord->type = 'group';
                $grouprecord->subtype = 'course';
                $grouprecord->objectid = $teamcacherecord->objectid;
                $grouprecord->moodleid = $courseid;
                $grouprecord->o365name = $teamcacherecord->name;
                $grouprecord->timecreated = time();
                $grouprecord->timemodified = $grouprecord->timecreated;
                $DB->insert_record('local_o365_objects', $grouprecord);
            }

            if ($teamrecord = $DB->get_record('local_o365_objects',
                ['type' => 'group', 'subtype' => 'courseteam', 'moodleid' => $courseid])) {
                $teamrecord->objectid = $teamcacherecord->objectid;
                $teamrecord->o365name = $teamcacherecord->name;
                $DB->update_record('local_o365_objects', $teamrecord);
            } else {
                $teamrecord = new \stdClass();
                $teamrecord->type = 'group';
                $teamrecord->subtype = 'courseteam';
                $teamrecord->objectid = $teamcacherecord->objectid;
                $teamrecord->moodleid = $courseid;
                $teamrecord->o365name = $teamcacherecord->name;
                $teamrecord->timecreated = time();
                $teamrecord->timemodified = $teamrecord->timecreated;
                $DB->insert_record('local_o365_objects', $teamrecord);
            }

            // Update course sync settings.
            \local_o365\feature\usergroups\utils::set_course_group_enabled($courseid, true, false);
            \local_o365\feature\usergroups\utils::set_course_group_feature_enabled($courseid, ['team'], true);

            // Sync users and create team tab.
            $graphclient = \local_o365\feature\usergroups\utils::get_graphclient();
            $coursegroups = new \local_o365\feature\usergroups\coursegroups($graphclient);

            // Sync users.
            $coursegroups->resync_group_membership($courseid, $teamcacherecord->objectid);

            // Provision app, add tab.
            $moodleappid = get_config('local_o365', 'moodle_app_id');
            if ($moodleappid) {
                $coursegroups->add_moodle_tab_in_teams($courseid, $teamcacherecord->objectid, $moodleappid);
            }

            redirect($redirecturl, get_string('acp_teamconnections_course_connected', 'local_o365'));
        } else {
            $url = new \moodle_url($this->url, ['mode' => 'teamconnections']);
            $PAGE->navbar->add(get_string('acp_teamconnections', 'local_o365'), $url);
            $PAGE->requires->jquery();
            $this->standard_header();
            echo \html_writer::tag('h4', get_string('acp_teamconnections_form_connect_course', 'local_o365', $course->fullname));
            $mform->display();
            $this->standard_footer();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



classes/page/acp.php [1173:1238]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                    throw new \moodle_exception('acp_teamconnections_exception_team_already_connected', 'local_o365', $redirecturl);
                }
            }

            // Create record in local_o365_object table.
            if ($grouprecord = $DB->get_record('local_o365_objects',
                ['type' => 'group', 'subtype' => 'course', 'moodleid' => $courseid])) {
                $grouprecord->objectid = $teamcacherecord->objectid;
                $grouprecord->o365name = $teamcacherecord->name;
                $grouprecord->metadata = null;
                $DB->update_record('local_o365_objects', $grouprecord);
            } else {
                $grouprecord = new \stdClass();
                $grouprecord->type = 'group';
                $grouprecord->subtype = 'course';
                $grouprecord->objectid = $teamcacherecord->objectid;
                $grouprecord->moodleid = $courseid;
                $grouprecord->o365name = $teamcacherecord->name;
                $grouprecord->timecreated = time();
                $grouprecord->timemodified = $grouprecord->timecreated;
                $DB->insert_record('local_o365_objects', $grouprecord);
            }

            if ($teamrecord = $DB->get_record('local_o365_objects',
                ['type' => 'group', 'subtype' => 'courseteam', 'moodleid' => $courseid])) {
                $teamrecord->objectid = $teamcacherecord->objectid;
                $teamrecord->o365name = $teamcacherecord->name;
                $DB->update_record('local_o365_objects', $teamrecord);
            } else {
                $teamrecord = new \stdClass();
                $teamrecord->type = 'group';
                $teamrecord->subtype = 'courseteam';
                $teamrecord->objectid = $teamcacherecord->objectid;
                $teamrecord->moodleid = $courseid;
                $teamrecord->o365name = $teamcacherecord->name;
                $teamrecord->timecreated = time();
                $teamrecord->timemodified = $teamrecord->timecreated;
                $DB->insert_record('local_o365_objects', $teamrecord);
            }

            // Update course sync settings.
            \local_o365\feature\usergroups\utils::set_course_group_enabled($courseid, true, false);
            \local_o365\feature\usergroups\utils::set_course_group_feature_enabled($courseid, ['team'], true);

            // Sync users and create team tab.
            $graphclient = \local_o365\feature\usergroups\utils::get_graphclient();
            $coursegroups = new \local_o365\feature\usergroups\coursegroups($graphclient);

            // Sync users.
            $coursegroups->resync_group_membership($courseid, $teamcacherecord->objectid);

            // Provision app, add tab.
            $moodleappid = get_config('local_o365', 'moodle_app_id');
            if ($moodleappid) {
                $coursegroups->add_moodle_tab_in_teams($courseid, $teamcacherecord->objectid, $moodleappid);
            }

            redirect($redirecturl, get_string('acp_teamconnections_course_connected', 'local_o365'));
        } else {
            $url = new \moodle_url($this->url, ['mode' => 'teamconnections']);
            $PAGE->navbar->add(get_string('acp_teamconnections', 'local_o365'), $url);
            $PAGE->requires->jquery();
            $this->standard_header();
            echo \html_writer::tag('h4', get_string('acp_teamconnections_form_connect_course', 'local_o365', $course->fullname));
            $mform->display();
            $this->standard_footer();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



