Example #1
0
 /**
  * Create groups
  *
  * @param array $groups array of group description arrays (with keys groupname and courseid)
  * @return array of newly created groups
  * @since Moodle 2.2
  */
 public static function create_groups($groups)
 {
     global $CFG, $DB;
     require_once "{$CFG->dirroot}/group/lib.php";
     $params = self::validate_parameters(self::create_groups_parameters(), array('groups' => $groups));
     $transaction = $DB->start_delegated_transaction();
     $groups = array();
     foreach ($params['groups'] as $group) {
         $group = (object) $group;
         if (trim($group->name) == '') {
             throw new invalid_parameter_exception('Invalid group name');
         }
         if ($DB->get_record('groups', array('courseid' => $group->courseid, 'name' => $group->name))) {
             throw new invalid_parameter_exception('Group with the same name already exists in the course');
         }
         // now security checks
         $context = get_context_instance(CONTEXT_COURSE, $group->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);
         // finally create the group
         $group->id = groups_create_group($group, false);
         $groups[] = (array) $group;
     }
     $transaction->allow_commit();
     return $groups;
 }
Example #2
0
 private function _createNewGroup($groupObj)
 {
     global $CFG;
     require_once $CFG->dirroot . '/group/lib.php';
     return groups_create_group($groupObj);
     /* group/lib.php */
 }
 function test_group_matches()
 {
     $groupinfo->name = 'Group Testname:' . $this->getLabel();
     $groupinfo->description = 'Group Test Description:' . $this->getLabel();
     $this->assertTrue($this->groupid = groups_create_group($this->courseid, $groupinfo));
     $this->assertTrue(groups_group_matches($this->courseid, $groupinfo->name, $groupinfo->description));
 }
Example #4
0
 function create_object($args)
 {
     if (!isset($args['creator_id'])) {
         $args['creator_id'] = get_current_user_id();
     }
     $group_id = groups_create_group($args);
     groups_update_groupmeta($group_id, 'total_member_count', 1);
     groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
     return $this->get_object_by_id($group_id);
 }
/**
 * Function for creating groups with parents programmatically
 * @param array Args same as groups_create_group, but accepts a 'parent_id' param
 */
function groups_hierarchy_create_group($args = '')
{
    if ($group_id = groups_create_group($args)) {
        if (isset($args['parent_id'])) {
            $group = new BP_Groups_Hierarchy($group_id);
            $group->parent_id = (int) $args['parent_id'];
            $group->save();
        }
        return $group_id;
    }
    return false;
}
function local_syncgroups_do_sync($groups, $destinations, $trace)
{
    global $DB;
    foreach ($groups as $group) {
        $trace->output('Grupo: ' . $group->name);
        if (!($members = $DB->get_records_menu('groups_members', array('groupid' => $group->id), '', 'userid, id'))) {
            $trace->output('group with no members, skipping');
            continue;
        }
        foreach ($destinations as $dest) {
            $trace->output("Curso: {$dest->shortname}");
            if ($dgr = $DB->get_record('groups', array('courseid' => $dest->id, 'name' => $group->name), 'id, courseid, idnumber, name')) {
                $trace->output('grupo existente');
            } else {
                $trace->output("criado grupo");
                $dgr = new Stdclass();
                $dgr->courseid = $dest->id;
                $dgr->timecreated = time();
                $dgr->timemodified = $dgr->timecreated;
                $dgr->name = $group->name;
                $dgr->description = $group->description;
                $dgr->descriptionformat = $group->descriptionformat;
                if (!($dgr->id = groups_create_group($dgr))) {
                    print_error("?? erro ao criar grupo");
                }
            }
            $trace->output("inserindo membros: ");
            foreach ($members as $userid => $memberid) {
                if (!$DB->get_field('groups_members', 'id', array('groupid' => $dgr->id, 'userid' => $userid))) {
                    if ($DB->get_field('role_assignments', 'id', array('contextid' => $dest->context->id, 'userid' => $userid))) {
                        groups_add_member($dgr->id, $userid);
                        $trace->output('Usuário inserido no grupo: ' . $userid);
                    } else {
                        $trace->output("?? usuario id: {$userid} não inscrito no curso");
                    }
                }
            }
            $trace->output("removendo membros: ");
            $members_dest = $DB->get_records('groups_members', array('groupid' => $dgr->id), '', 'id, groupid, userid');
            foreach ($members_dest as $id => $usum) {
                if (!isset($members[$usum->userid])) {
                    groups_remove_member($dgr->id, $usum->userid);
                    $trace->output('Usuário removido do grupo: ' . $usum->userid);
                }
            }
        }
    }
    $trace->output('Concluído.');
    $trace->finished();
}
 /**
  * This function creates a group with a particular name, adds it to the grouping,
  * and then adds the current user to that group.
  *
  * @param string $name The name to assign to the newly created group.
  * @return int The ID of the group that was group that was created.
  *
  */
 public function create_group($name)
 {
     global $DB, $USER;
     $sgs = new skills_group_setting($this->courseid);
     $group = new stdClass();
     if ($name === null || trim($name) == '') {
         $name = $this->name_empty_group();
     }
     $group->name = $name;
     $group->courseid = $this->courseid;
     $groupid = groups_create_group($group);
     groups_assign_grouping($sgs->get_grouping_id(), $groupid);
     groups_add_member($groupid, $USER->id);
     return $groupid;
 }
 /**
  * setUp/tearDown: Better in a constructor/destructor, but PHP4 doesn't do destructors :(
  */
 function setUp()
 {
     parent::setUp();
     if ($course = groups_get_course_info(1)) {
         $this->courseid = $course->id;
     }
     if ($user = groups_get_user(2)) {
         //Primary admin.
         $this->userid = $user->id;
     }
     $this->groupid = groups_create_group($this->courseid);
     $groupinfo = groups_set_default_group_settings();
     $bok = groups_set_group_settings($this->groupid, $groupinfo);
     $bok = groups_add_member($this->groupid, $this->userid);
 }
Example #9
0
 /**
  * Create the fixture
  *
  * This method must be safe to call multiple times.
  *
  * @return void
  * @throws moodle_exception
  */
 public function build()
 {
     global $DB;
     if (!$this->exists()) {
         // Dependents
         $this->get_course()->build();
         $group = (object) $this->get_options();
         $group->courseid = $this->get_course()->get('id');
         // Helping...!?!
         if (!property_exists($group, 'name')) {
             $group->name = '';
         }
         $groupid = groups_create_group($group);
         $this->set_results($DB->get_record('groups', array('id' => $groupid), '*', MUST_EXIST));
     }
 }
Example #10
0
 /**
  * Create some groups
  * @param array|struct $params
  * @subparam string $params:group->groupname
  * @subparam integer $params:group->courseid
  * @return array $return
  * @subparam integer $return:groupid
  */
 static function create_groups($params)
 {
     global $USER;
     $groupids = array();
     if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
         foreach ($params as $groupparam) {
             $group = new stdClass();
             $group->courseid = clean_param($groupparam['courseid'], PARAM_INTEGER);
             $group->name = clean_param($groupparam['groupname'], PARAM_ALPHANUMEXT);
             $groupids[] = groups_create_group($group, false);
         }
         return $groupids;
     } else {
         throw new moodle_exception('wscouldnotcreategroupnopermission');
     }
 }
/**
 * This function creates the course groups and associates with it the site group.
 *
 * @param int $groupid The site group id.
 * @param object $group The course group data.
 * @return boolean success.
 *
 */
function fn_sg_create_group($groupid, $group)
{
    /// This will generate another group create event. Will that be a problem?
    if (!($newid = groups_create_group($group))) {
        trigger_error('Could not create course group!');
        return false;
    }
    $sgrec = new Object();
    $sgrec->sitegroupid = $groupid;
    $sgrec->coursegroupid = $newid;
    $sgrec->courseid = $group->courseid;
    if (insert_record('block_fn_site_groups', $sgrec)) {
        return $newid;
    } else {
        return false;
    }
}
 public static function SavePost($post_id, $post, $update)
 {
     if (wp_is_post_revision($post_id) || $post->post_status != 'publish' || $post->post_type != 'namaste_course') {
         return;
     }
     $meta = get_post_meta($post_id, 'buddypress_id', true);
     if (empty($meta)) {
         $group_id = groups_create_group(array('creator_id' => get_current_user_id(), 'name' => $post->post_title, 'description' => 'Обсуждение курса ' . $post->post_title, 'enable_forum' => 1));
         update_post_meta($post_id, 'buddypress_id', $group_id);
         groups_edit_group_settings($group_id, 1, 'private', 'mods');
         $forum_id = bbp_insert_forum($forum_data = array('post_status' => bbp_get_private_status_id(), 'post_type' => bbp_get_forum_post_type(), 'post_author' => bbp_get_current_user_id(), 'post_content' => 'Обсуждение курса ' . $post->post_title, 'post_title' => $post->post_title), $forum_meta = array());
         bbp_update_group_forum_ids($group_id, (array) $forum_id);
         bbp_update_forum_group_ids($forum_id, (array) $group_id);
     }
     bbp_add_user_forum_subscription(bbp_get_current_user_id(), $forum_id);
     update_post_meta($forum_id, '_forum_course_id', $post_id);
 }
/**
 * On blog creation, create a new group
 */
function thatcamp_create_group_for_new_blog($blog_id)
{
    // Assemble some data to create the group
    $create_args = array();
    // The group admin should be the blog admin. If no blog admin is found, default to Amanda (id 7)
    $blog_admin = get_user_by('email', get_blog_option($blog_id, 'admin_email'));
    $create_args['creator_id'] = is_a($blog_admin, 'WP_User') ? $blog_admin->ID : '7';
    $create_args['name'] = get_blog_option($blog_id, 'blogname');
    $create_args['description'] = $create_args['name'];
    $create_args['slug'] = sanitize_title($create_args['name']);
    $create_args['status'] = 'public';
    $create_args['enable_forum'] = false;
    $create_args['date_created'] = bp_core_current_time();
    $group_id = groups_create_group($create_args);
    groups_update_groupmeta($group_id, 'blog_id', $blog_id);
    groups_update_groupmeta($group_id, 'total_member_count', 1);
    groups_update_groupmeta($group_id, 'invite_status', 'members');
    return $group_id;
}
Example #14
0
function appear_add_instance($data)
{
    global $DB, $CFG, $USER;
    $appear = new stdClass();
    $appear->course = $data->course;
    $appear->name = $data->name;
    $appear->intro = $data->intro;
    $appear->revision = $data->revision;
    $appear->timemodified = time();
    $appear->timecreated = time();
    $appear->timestart = $data->starttime;
    $appear->id = $DB->insert_record('appear', $appear);
    //creating group
    $group = new stdClass();
    $group->name = $data->name . '_group_' . $appear->id;
    $group->courseid = $data->course;
    $group->hidepicture = 0;
    $group->id = groups_create_group($group);
    // creating event subscription
    $sub = new stdClass();
    $sub->url = $CFG->wwwroot . '/mod/appear/view.php?id=' . $data->coursemodule;
    $sub->courseid = $data->course;
    $sub->groupid = $group->id;
    $sub->userid = $USER->id;
    $sub->pollinterval = 0;
    $subid = $DB->insert_record('event_subscriptions', $sub, true);
    // creating calender event
    $event = new stdClass();
    $event->name = $data->name;
    $event->description = '';
    $event->timestart = $data->starttime;
    $event->modulename = 'appear';
    $event->timeduration = 3600;
    $event->uuid = 'uuid';
    $event->subscriptionid = $subid;
    $event->userid = $USER->id;
    $event->groupid = $group->id;
    $event->courseid = $data->course;
    $event->eventtype = 'feedbackcloses';
    $eventobj = calendar_event::create($event, false);
    return $appear->id;
}
 /**
  * Group created
  *
  * @param \core\event\group_created $event
  * @return void
  */
 public static function group_created(\core\event\group_created $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 parent course doesn't use groups, we can skip synchronization.
         if (groups_get_course_groupmode($course) == NOGROUPS) {
             continue;
         }
         if (!$DB->record_exists('groups', array('courseid' => $course->id, 'idnumber' => $group->id))) {
             $metagroup = new \stdClass();
             $metagroup->courseid = $course->id;
             $metagroup->idnumber = $group->id;
             $metagroup->name = $group->name;
             groups_create_group($metagroup, false, false);
         }
     }
 }
Example #16
0
 /**
  * Test that a new group with the name of the cohort is created.
  */
 public function test_enrol_cohort_create_new_group()
 {
     global $DB;
     $this->resetAfterTest();
     // Create a category.
     $category = $this->getDataGenerator()->create_category();
     // Create two courses.
     $course = $this->getDataGenerator()->create_course(array('category' => $category->id));
     $course2 = $this->getDataGenerator()->create_course(array('category' => $category->id));
     // Create a cohort.
     $cohort = $this->getDataGenerator()->create_cohort(array('context' => context_coursecat::instance($category->id)->id));
     // Run the function.
     $groupid = enrol_cohort_create_new_group($course->id, $cohort->id);
     // Check the results.
     $group = $DB->get_record('groups', array('id' => $groupid));
     // The group name should match the cohort name.
     $this->assertEquals($cohort->name . ' cohort', $group->name);
     // Group course id should match the course id.
     $this->assertEquals($course->id, $group->courseid);
     // Create a group that will have the same name as the cohort.
     $groupdata = new stdClass();
     $groupdata->courseid = $course2->id;
     $groupdata->name = $cohort->name . ' cohort';
     groups_create_group($groupdata);
     // Create a group for the cohort in course 2.
     $groupid = enrol_cohort_create_new_group($course2->id, $cohort->id);
     $groupinfo = $DB->get_record('groups', array('id' => $groupid));
     // Check that the group name has been changed.
     $this->assertEquals($cohort->name . ' cohort (2)', $groupinfo->name);
     // Create another group that will have the same name as a generated cohort.
     $groupdata = new stdClass();
     $groupdata->courseid = $course2->id;
     $groupdata->name = $cohort->name . ' cohort (2)';
     groups_create_group($groupdata);
     // Create a group for the cohort in course 2.
     $groupid = enrol_cohort_create_new_group($course2->id, $cohort->id);
     $groupinfo = $DB->get_record('groups', array('id' => $groupid));
     // Check that the group name has been changed.
     $this->assertEquals($cohort->name . ' cohort (3)', $groupinfo->name);
 }
/**
 * Run synchronization process
 *
 * @param progress_trace $trace
 * @param int|null $courseid or null for all courses
 * @return void
 */
function local_metagroups_sync(progress_trace $trace, $courseid = null)
{
    global $DB;
    if ($courseid !== null) {
        $courseids = array($courseid);
    } else {
        $courseids = local_metagroups_parent_courses();
    }
    foreach (array_unique($courseids) as $courseid) {
        $parent = get_course($courseid);
        // If parent course doesn't use groups, we can skip synchronization.
        if (groups_get_course_groupmode($parent) == NOGROUPS) {
            continue;
        }
        $trace->output($parent->fullname, 1);
        $children = local_metagroups_child_courses($parent->id);
        foreach ($children as $childid) {
            $child = get_course($childid);
            $trace->output($child->fullname, 2);
            $groups = groups_get_all_groups($child->id);
            foreach ($groups as $group) {
                if (!($metagroup = $DB->get_record('groups', array('courseid' => $parent->id, 'idnumber' => $group->id)))) {
                    $metagroup = new stdClass();
                    $metagroup->courseid = $parent->id;
                    $metagroup->idnumber = $group->id;
                    $metagroup->name = $group->name;
                    $metagroup->id = groups_create_group($metagroup, false, false);
                }
                $trace->output($metagroup->name, 3);
                $users = groups_get_members($group->id);
                foreach ($users as $user) {
                    groups_add_member($metagroup->id, $user->id, 'local_metagroups', $group->id);
                }
            }
        }
    }
}
 /**
  * Make a role assignment in the specified course using the specified role
  * id for the user whose id information is passed in the line data.
  *
  * @access public
  * @static
  * @param stdClass      $course           Course in which to make the role assignment
  * @param stdClass      $enrol_instance   Enrol instance to use for adding users to course
  * @param string        $ident_field      The field (column) name in Moodle user rec against which to query using the imported data
  * @param int           $role_id          Id of the role to use in the role assignment
  * @param boolean       $group_assign     Whether or not to assign users to groups
  * @param int           $group_id         Id of group to assign to, 0 indicates use group name from import file
  * @param boolean       $group_create     Whether or not to create new groups if needed
  * @param stored_file   $import_file      File in local repository from which to get enrollment and group data
  * @return string                         String message with results
  *
  * @uses $DB
  */
 public static function import_file(stdClass $course, stdClass $enrol_instance, $ident_field, $role_id, $group_assign, $group_id, $group_create, stored_file $import_file)
 {
     global $DB;
     // Default return value
     $result = '';
     // Need one of these in the loop
     $course_context = context_course::instance($course->id);
     // Choose the regex pattern based on the $ident_field
     switch ($ident_field) {
         case 'email':
             $regex_pattern = '/^"?\\s*([a-z0-9][\\w.%-]*@[a-z0-9][a-z0-9.-]{0,61}[a-z0-9]\\.[a-z]{2,6})\\s*"?(?:\\s*[;,\\t]\\s*"?\\s*([a-z0-9][\\w\' .,&-]*))?\\s*"?$/Ui';
             break;
         case 'idnumber':
             $regex_pattern = '/^"?\\s*(\\d{1,32})\\s*"?(?:\\s*[;,\\t]\\s*"?\\s*([a-z0-9][\\w\' .,&-]*))?\\s*"?$/Ui';
             break;
         default:
             $regex_pattern = '/^"?\\s*([a-z0-9][\\w@.-]*)\\s*"?(?:\\s*[;,\\t]\\s*"?\\s*([a-z0-9][\\w\' .,&-]*))?\\s*"?$/Ui';
             break;
     }
     // If doing group assignments, want to know the valid
     // groups for the course
     $selected_group = null;
     if ($group_assign) {
         if (false === ($existing_groups = groups_get_all_groups($course->id))) {
             $existing_groups = array();
         }
         if ($group_id > 0) {
             if (array_key_exists($group_id, $existing_groups)) {
                 $selected_group = $existing_groups[$group_id];
             } else {
                 // Error condition
                 return sprintf(get_string('ERR_INVALID_GROUP_ID', self::PLUGIN_NAME), $group_id);
             }
         }
     }
     // Iterate the list of active enrol plugins looking for
     // the meta course plugin
     $metacourse = false;
     $enrols_enabled = enrol_get_instances($course->id, true);
     foreach ($enrols_enabled as $enrol) {
         if ($enrol->enrol == 'meta') {
             $metacourse = true;
             break;
         }
     }
     // Get an instance of the enrol_manual_plugin (not to be confused
     // with the enrol_instance arg)
     $manual_enrol_plugin = enrol_get_plugin('manual');
     $user_rec = $new_group = $new_grouping = null;
     // Open and fetch the file contents
     $fh = $import_file->get_content_file_handle();
     $line_num = 0;
     while (false !== ($line = fgets($fh))) {
         $line_num++;
         // Clean these up for each iteration
         unset($user_rec, $new_group, $new_grouping);
         if (!($line = trim($line))) {
             continue;
         }
         // Parse the line, from which we may get one or two
         // matches since the group name is an optional item
         // on a line by line basis
         if (!preg_match($regex_pattern, $line, $matches)) {
             $result .= sprintf(get_string('ERR_PATTERN_MATCH', self::PLUGIN_NAME), $line_num, $line);
             continue;
         }
         $ident_value = $matches[1];
         $group_name = isset($matches[2]) ? $matches[2] : '';
         // User must already exist, we import enrollments
         // into courses, not users into the system. Exclude
         // records marked as deleted. Because idnumber is
         // not enforced unique, possible multiple records
         // returned when using that identifying field, so
         // use ->get_records method to make that detection
         // and inform user
         $user_rec_array = $DB->get_records('user', array($ident_field => addslashes($ident_value), 'deleted' => 0));
         // Should have one and only one record, otherwise
         // report it and move on to the next
         $user_rec_count = count($user_rec_array);
         if ($user_rec_count == 0) {
             // No record found
             $result .= sprintf(get_string('ERR_USERID_INVALID', self::PLUGIN_NAME), $line_num, $ident_value);
             continue;
         } elseif ($user_rec_count > 1) {
             // Too many records
             $result .= sprintf(get_string('ERR_USER_MULTIPLE_RECS', self::PLUGIN_NAME), $line_num, $ident_value);
             continue;
         }
         $user_rec = array_shift($user_rec_array);
         // Fetch all the role assignments this user might have for this course's context
         $roles = get_user_roles($course_context, $user_rec->id, false);
         // If a user has a role in this course, then we leave it alone and move on
         // to the group assignment if there is one. If they have no role, then we
         // should go ahead and add one, as long as it is not a metacourse.
         if (!$roles && $role_id > 0) {
             if ($metacourse) {
                 $result .= sprintf(get_string('ERR_ENROLL_META', self::PLUGIN_NAME), $line_num, $ident_value);
             } else {
                 try {
                     $manual_enrol_plugin->enrol_user($enrol_instance, $user_rec->id, $role_id);
                 } catch (Exception $exc) {
                     $result .= sprintf(get_string('ERR_ENROLL_FAILED', self::PLUGIN_NAME), $line_num, $ident_value);
                     $result .= $exc->getMessage();
                     continue;
                 }
             }
         }
         // If no group assignments, or group is from file, but no
         // group found, next line
         if (!$group_assign || $group_id == 0 && empty($group_name)) {
             continue;
         }
         // If no group pre-selected, see if group from import already
         // created for that course
         $assign_group_id = 0;
         $assign_group_name = '';
         if ($selected_group != null) {
             $assign_group_id = $selected_group->id;
             $assign_group_name = $selected_group->name;
         } else {
             foreach ($existing_groups as $existing_group) {
                 if ($existing_group->name != $group_name) {
                     continue;
                 }
                 $assign_group_id = $existing_group->id;
                 $assign_group_name = $existing_group->name;
                 break;
             }
             // No group by that name
             if ($assign_group_id == 0) {
                 // Can not create one, next line
                 if (!$group_create) {
                     continue;
                 }
                 // Make a new group for this course
                 $new_group = new stdClass();
                 $new_group->name = addslashes($group_name);
                 $new_group->courseid = $course->id;
                 if (false === ($assign_group_id = groups_create_group($new_group))) {
                     $result .= sprintf(get_string('ERR_CREATE_GROUP', self::PLUGIN_NAME), $line_num, $group_name);
                     continue;
                 } else {
                     // Add the new group to our list for the benefit of
                     // the next contestant. Strip the slashes off the
                     // name since we do a name comparison earlier when
                     // trying to find the group in our local cache and
                     // an escaped semi-colon will cause the test to fail.
                     $new_group->name = $assign_group_name = stripslashes($new_group->name);
                     $new_group->id = $assign_group_id;
                     $existing_groups[] = $new_group;
                 }
             }
             // if ($assign_group_id == 0)
         }
         // Put the user in the group if not aleady in it
         if (!groups_is_member($assign_group_id, $user_rec->id) && !groups_add_member($assign_group_id, $user_rec->id)) {
             $result .= sprintf(get_string('ERR_GROUP_MEMBER', self::PLUGIN_NAME), $line_num, $ident_value, $assign_group_name);
             continue;
         }
         // Any other work...
     }
     // while fgets
     fclose($fh);
     return empty($result) ? get_string('INF_IMPORT_SUCCESS', self::PLUGIN_NAME) : $result;
 }
Example #19
0
                        $newgroup->courseid = $id;
                    }
                }
                //if courseid is set
                if (isset($newgroup->courseid)) {
                    $linenum++;
                    $groupname = $newgroup->name;
                    $newgrpcoursecontext = get_context_instance(CONTEXT_COURSE, $newgroup->courseid);
                    ///Users cannot upload groups in courses they cannot update.
                    if (!has_capability('moodle/course:managegroups', $newgrpcoursecontext) or !is_enrolled($newgrpcoursecontext) and !has_capability('moodle/course:view', $newgrpcoursecontext)) {
                        echo $OUTPUT->notification(get_string('nopermissionforcreation', 'group', $groupname));
                    } else {
                        if ($groupid = groups_get_group_by_name($newgroup->courseid, $groupname)) {
                            echo $OUTPUT->notification("{$groupname} :" . get_string('groupexistforcourse', 'error', $groupname));
                        } else {
                            if (groups_create_group($newgroup)) {
                                echo $OUTPUT->notification(get_string('groupaddedsuccesfully', 'group', $groupname), 'notifysuccess');
                            } else {
                                echo $OUTPUT->notification(get_string('groupnotaddederror', 'error', $groupname));
                            }
                        }
                    }
                }
                unset($newgroup);
            }
        }
        echo $OUTPUT->single_button($returnurl, get_string('continue'), 'get');
        echo $OUTPUT->footer();
        die;
    }
}
 /**
  * Create a test group for the specified course
  *
  * $record should be either an array or a stdClass containing infomation about the group to create.
  * At the very least it needs to contain courseid.
  * Default values are added for name, description, and descriptionformat if they are not present.
  *
  * This function calls {@see groups_create_group()} to create the group within the database.
  *
  * @param array|stdClass $record
  * @return stdClass group record
  */
 public function create_group($record)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/group/lib.php';
     $this->groupcount++;
     $i = $this->groupcount;
     $record = (array) $record;
     if (empty($record['courseid'])) {
         throw new coding_exception('courseid must be present in phpunit_util::create_group() $record');
     }
     if (!isset($record['name'])) {
         $record['name'] = 'group-' . $i;
     }
     if (!isset($record['description'])) {
         $record['description'] = "Test Group {$i}\n{$this->loremipsum}";
     }
     if (!isset($record['descriptionformat'])) {
         $record['descriptionformat'] = FORMAT_MOODLE;
     }
     $id = groups_create_group((object) $record);
     return $DB->get_record('groups', array('id' => $id));
 }
Example #21
0
 private function process_course_cohort_membership_node($membershipnode, $xpath, $role = '01')
 {
     global $DB, $CFG;
     $idnumber = $xpath->evaluate("sourcedid/id", $membershipnode)->item(0);
     $course = $DB->get_record('course', array('idnumber' => $idnumber->nodeValue), '*', MUST_EXIST);
     $members = $xpath->evaluate("member", $membershipnode);
     foreach ($members as $mmember) {
         $midnumber = $xpath->evaluate("sourcedid/id", $mmember)->item(0);
         $idtype = $xpath->evaluate("idtype", $mmember)->item(0);
         if ($midnumber) {
             $member = new stdClass();
             $member->idnumber = $midnumber->nodeValue;
             $cohortid = $DB->get_field('cohort', 'id', array('idnumber' => $member->idnumber));
             $cohortname = $DB->get_field('cohort', 'name', array('idnumber' => $member->idnumber));
             if ($idtype->nodeValue == 'Add' && $cohortid) {
                 if (!($cohortinstanceid = $DB->get_field('enrol', 'id', array('enrol' => 'cohort', 'customint1' => $cohortid, 'courseid' => $course->id)))) {
                     $enrol = enrol_get_plugin('cohort');
                     $enrol->add_instance($course, array('name' => $cohortname, 'status' => 0, 'customint1' => $cohortid, 'roleid' => 5, 'customint2' => 0));
                     $trace = new null_progress_trace();
                     enrol_cohort_sync($trace, $course->id);
                     $trace->finished();
                 }
                 if (substr($idnumber->nodeValue, 0, 8) == 'UOFAB-XL') {
                     $data = new stdClass();
                     if (!($data->id = $DB->get_field('groups', 'id', array('courseid' => $course->id, 'name' => $cohortname)))) {
                         $data->timecreated = time();
                         $data->timemodified = time();
                         $data->name = trim($cohortname);
                         $data->description = '';
                         $data->descriptionformat = '1';
                         $data->courseid = $course->id;
                         $data->id = groups_create_group($data);
                     }
                     $cohortrec = $DB->get_fieldset_select('cohort_members', 'userid', 'cohortid=' . $cohortid);
                     foreach ($cohortrec as $curmember) {
                         $latestlist[$curmember] = $curmember;
                         groups_add_member($data->id, $curmember);
                     }
                     $grouprec = $DB->get_fieldset_select('groups_members', 'userid', 'groupid=' . $data->id);
                     foreach ($grouprec as $grpmember) {
                         if (!isset($latestlist[$grpmember])) {
                             groups_remove_member($data->id, $grpmember);
                         }
                     }
                 }
             } else {
                 if ($idtype->nodeValue == 'Delete') {
                     if ($cohortinstance = $DB->get_record('enrol', array('enrol' => 'cohort', 'customint1' => $cohortid, 'courseid' => $course->id))) {
                         $enrol = enrol_get_plugin('cohort');
                         $enrol->delete_instance($cohortinstance);
                     }
                 }
             }
         }
     }
 }
Example #22
0
         if ($existing = groups_get_group_by_idnumber($newgroup->courseid, $newgroup->idnumber)) {
             // idnumbers must be unique to a course but we shouldn't ignore group creation for duplicates
             $existing->name = s($existing->name);
             $existing->idnumber = s($existing->idnumber);
             $existing->problemgroup = $groupname;
             echo $OUTPUT->notification(get_string('groupexistforcoursewithidnumber', 'error', $existing));
             unset($newgroup->idnumber);
         }
     }
     // Always drop the groupidnumber key. It's not a valid database field
     unset($newgroup->groupidnumber);
 }
 if ($groupid = groups_get_group_by_name($newgroup->courseid, $groupname)) {
     echo $OUTPUT->notification("{$groupname} :" . get_string('groupexistforcourse', 'error', $groupname));
 } else {
     if ($groupid = groups_create_group($newgroup)) {
         echo $OUTPUT->notification(get_string('groupaddedsuccesfully', 'group', $groupname), 'notifysuccess');
     } else {
         echo $OUTPUT->notification(get_string('groupnotaddederror', 'error', $groupname));
         continue;
     }
 }
 // Add group to grouping
 if (!empty($newgroup->groupingname) || is_numeric($newgroup->groupingname)) {
     $groupingname = $newgroup->groupingname;
     if (!($groupingid = groups_get_grouping_by_name($newgroup->courseid, $groupingname))) {
         $data = new stdClass();
         $data->courseid = $newgroup->courseid;
         $data->name = $groupingname;
         if ($groupingid = groups_create_grouping($data)) {
             echo $OUTPUT->notification(get_string('groupingaddedsuccesfully', 'group', $groupingname), 'notifysuccess');
Example #23
0
 /**
  * Test that a new group with the name of the course is created.
  */
 public function test_enrol_meta_create_new_group()
 {
     global $DB;
     $this->resetAfterTest();
     // Create two courses.
     $course = $this->getDataGenerator()->create_course(array('fullname' => 'Mathematics'));
     $course2 = $this->getDataGenerator()->create_course(array('fullname' => 'Physics'));
     $metacourse = $this->getDataGenerator()->create_course(array('fullname' => 'All sciences'));
     // Run the function.
     $groupid = enrol_meta_create_new_group($metacourse->id, $course->id);
     // Check the results.
     $group = $DB->get_record('groups', array('id' => $groupid));
     // The group name should match the course name.
     $this->assertEquals('Mathematics course', $group->name);
     // Group course id should match the course id.
     $this->assertEquals($metacourse->id, $group->courseid);
     // Create a group that will have the same name as the course.
     $groupdata = new stdClass();
     $groupdata->courseid = $metacourse->id;
     $groupdata->name = 'Physics course';
     groups_create_group($groupdata);
     // Create a group for the course 2 in metacourse.
     $groupid = enrol_meta_create_new_group($metacourse->id, $course2->id);
     $groupinfo = $DB->get_record('groups', array('id' => $groupid));
     // Check that the group name has been changed.
     $this->assertEquals('Physics course (2)', $groupinfo->name);
     // Create a group for the course 2 in metacourse.
     $groupid = enrol_meta_create_new_group($metacourse->id, $course2->id);
     $groupinfo = $DB->get_record('groups', array('id' => $groupid));
     // Check that the group name has been changed.
     $this->assertEquals('Physics course (3)', $groupinfo->name);
 }
         $createdgrouping = $grouping->id;
     } else {
         $grouping = groups_get_grouping($data->grouping);
     }
 }
 // Save the groups data
 foreach ($groups as $key => $group) {
     if (groups_get_group_by_name($courseid, $group['name'])) {
         $error = get_string('groupnameexists', 'group', $group['name']);
         $failed = true;
         break;
     }
     $newgroup = new object();
     $newgroup->courseid = $data->courseid;
     $newgroup->name = $group['name'];
     if (!($groupid = groups_create_group(addslashes_recursive($newgroup)))) {
         $error = 'Can not create group!';
         // should not happen
         $failed = true;
         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) {
Example #25
0
function create_course_group($data,$id) {
	global $DB,$CFG;
	 /**Group functionality Starting **/
	  //    if(!empty($data->assign_quizes)){

              require_once $CFG->dirroot.'/group/lib.php';
              $groupdata=new stdClass();
              $groupdata->courseid=$data->assign_courses;
              $groupdata->timecreated=time();
			//  $groupdata->idnumber=$data->batchid.''.$data->assign_courses;
              $groupdata->name=$DB->get_field('facetoface','name',array('id'=>$data->batchid));
              //$groupdata->name='Tgsgroup';
			 $groupcreated=$DB->get_field('groups','id',array('name'=>$groupdata->name,'courseid'=>$data->assign_courses));
			
			 if(empty($groupcreated))
             $groupcreated= groups_create_group($groupdata,$editform = false, $editoroptions = false);
		     			  
		$updategroup=new stdClass();
		$updategroup->id=$id;
		$updategroup->groupid=$groupcreated;
        $assigned_course=$DB->update_record('local_batch_courses',$updategroup);
		$cm = get_coursemodule_from_instance('quiz', $data->assign_quizes, 0, false, MUST_EXIST);
			$availability=$DB->get_field('course_modules','availability',array('id'=>$cm->id));
			if($availability==NULL) {
				$st='';
				$st .='{"op":"|","c":[';
			    $st .='{"type":"group","id":'.$groupcreated.'}';
			    $st .='],"show":false}';
				$availability=$st;
				
			}
			else {
				$st=''; 
				$st .='{"op":"|","c":[';
				$newst = str_replace('{"op":"|","c":[','',$availability);
				$newst = str_replace('],"show":false}','',$newst);
				$st .='{"type":"group","id":'.$groupcreated.'}'.','.$newst;			    
				$st .='],"show":false}';
				$availability=str_replace(',]','',$st);
			
			}
			
			//exit;
		   $DB->set_field('course_modules', 'availability',$availability, array('id' => $cm->id));
         //  }
	 
	 /**End of the function **/
}
Example #26
0
 public function test_sync_all_courses()
 {
     global $DB;
     $this->resetAfterTest();
     $trace = new null_progress_trace();
     // Setup a few courses and categories.
     $cohortplugin = enrol_get_plugin('cohort');
     $manualplugin = enrol_get_plugin('manual');
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->assertNotEmpty($studentrole);
     $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
     $this->assertNotEmpty($teacherrole);
     $managerrole = $DB->get_record('role', array('shortname' => 'manager'));
     $this->assertNotEmpty($managerrole);
     $cat1 = $this->getDataGenerator()->create_category();
     $cat2 = $this->getDataGenerator()->create_category();
     $course1 = $this->getDataGenerator()->create_course(array('category' => $cat1->id));
     $course2 = $this->getDataGenerator()->create_course(array('category' => $cat1->id));
     $course3 = $this->getDataGenerator()->create_course(array('category' => $cat2->id));
     $course4 = $this->getDataGenerator()->create_course(array('category' => $cat2->id));
     $maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     $user3 = $this->getDataGenerator()->create_user();
     $user4 = $this->getDataGenerator()->create_user();
     $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid' => context_coursecat::instance($cat1->id)->id));
     $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid' => context_coursecat::instance($cat2->id)->id));
     $cohort3 = $this->getDataGenerator()->create_cohort();
     $this->disable_plugin();
     // Prevents event sync.
     $manualplugin->enrol_user($maninstance1, $user4->id, $teacherrole->id);
     $manualplugin->enrol_user($maninstance1, $user3->id, $managerrole->id);
     $this->assertEquals(2, $DB->count_records('role_assignments', array()));
     $this->assertEquals(2, $DB->count_records('user_enrolments', array()));
     $id = $cohortplugin->add_instance($course1, array('customint1' => $cohort1->id, 'roleid' => $studentrole->id));
     $cohortinstance1 = $DB->get_record('enrol', array('id' => $id));
     $id = $cohortplugin->add_instance($course1, array('customint1' => $cohort2->id, 'roleid' => $teacherrole->id));
     $cohortinstance2 = $DB->get_record('enrol', array('id' => $id));
     $id = $cohortplugin->add_instance($course2, array('customint1' => $cohort2->id, 'roleid' => $studentrole->id));
     $cohortinstance3 = $DB->get_record('enrol', array('id' => $id));
     cohort_add_member($cohort1->id, $user1->id);
     cohort_add_member($cohort1->id, $user2->id);
     cohort_add_member($cohort1->id, $user4->id);
     cohort_add_member($cohort2->id, $user3->id);
     cohort_add_member($cohort3->id, $user3->id);
     $this->assertEquals(2, $DB->count_records('role_assignments', array()));
     $this->assertEquals(2, $DB->count_records('user_enrolments', array()));
     // Test sync of one course only.
     enrol_cohort_sync($trace, null);
     $this->assertEquals(2, $DB->count_records('role_assignments', array()));
     $this->assertEquals(2, $DB->count_records('user_enrolments', array()));
     $this->enable_plugin();
     enrol_cohort_sync($trace, null);
     $this->assertEquals(7, $DB->count_records('user_enrolments', array()));
     $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid' => $cohortinstance1->id, 'userid' => $user1->id)));
     $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid' => $cohortinstance1->id, 'userid' => $user2->id)));
     $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid' => $cohortinstance1->id, 'userid' => $user4->id)));
     $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid' => $cohortinstance2->id, 'userid' => $user3->id)));
     $this->assertEquals(7, $DB->count_records('role_assignments', array()));
     $this->assertTrue($DB->record_exists('role_assignments', array('contextid' => context_course::instance($course1->id)->id, 'userid' => $user1->id, 'roleid' => $studentrole->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
     $this->assertTrue($DB->record_exists('role_assignments', array('contextid' => context_course::instance($course1->id)->id, 'userid' => $user2->id, 'roleid' => $studentrole->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
     $this->assertTrue($DB->record_exists('role_assignments', array('contextid' => context_course::instance($course1->id)->id, 'userid' => $user4->id, 'roleid' => $studentrole->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
     $this->assertTrue($DB->record_exists('role_assignments', array('contextid' => context_course::instance($course1->id)->id, 'userid' => $user3->id, 'roleid' => $teacherrole->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance2->id)));
     $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
     $DB->delete_records('cohort_members', array('cohortid' => $cohort2->id, 'userid' => $user3->id));
     // Use low level DB api to prevent events!
     enrol_cohort_sync($trace, $course1->id);
     $this->assertEquals(7, $DB->count_records('user_enrolments', array()));
     $this->assertEquals(6, $DB->count_records('role_assignments', array()));
     $this->assertFalse($DB->record_exists('role_assignments', array('contextid' => context_course::instance($course1->id)->id, 'userid' => $user3->id, 'roleid' => $teacherrole->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance2->id)));
     $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
     $DB->delete_records('cohort_members', array('cohortid' => $cohort1->id, 'userid' => $user1->id));
     // Use low level DB api to prevent events!
     enrol_cohort_sync($trace, $course1->id);
     $this->assertEquals(5, $DB->count_records('user_enrolments', array()));
     $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid' => $cohortinstance2->id, 'userid' => $user3->id)));
     $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid' => $cohortinstance1->id, 'userid' => $user1->id)));
     $this->assertEquals(5, $DB->count_records('role_assignments', array()));
     $this->assertFalse($DB->record_exists('role_assignments', array('contextid' => context_course::instance($course1->id)->id, 'userid' => $user3->id, 'roleid' => $teacherrole->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance2->id)));
     $this->assertFalse($DB->record_exists('role_assignments', array('contextid' => context_course::instance($course1->id)->id, 'userid' => $user1->id, 'roleid' => $studentrole->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
     $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
     $DB->delete_records('cohort_members', array('cohortid' => $cohort1->id));
     // Use low level DB api to prevent events!
     $DB->delete_records('cohort', array('id' => $cohort1->id));
     // Use low level DB api to prevent events!
     enrol_cohort_sync($trace, $course1->id);
     $this->assertEquals(5, $DB->count_records('user_enrolments', array()));
     $this->assertEquals(3, $DB->count_records('role_assignments', array()));
     $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
     enrol_cohort_sync($trace, $course1->id);
     $this->assertEquals(3, $DB->count_records('user_enrolments', array()));
     $this->assertEquals(3, $DB->count_records('role_assignments', array()));
     // Test group sync.
     $this->disable_plugin();
     // No event sync
     // Trigger sync to remove extra role assignments.
     enrol_cohort_sync($trace, $course1->id);
     $this->assertEquals(2, $DB->count_records('role_assignments', array()));
     $id = groups_create_group((object) array('name' => 'Group 1', 'courseid' => $course1->id));
     $group1 = $DB->get_record('groups', array('id' => $id), '*', MUST_EXIST);
     $id = groups_create_group((object) array('name' => 'Group 2', 'courseid' => $course1->id));
     $group2 = $DB->get_record('groups', array('id' => $id), '*', MUST_EXIST);
     $id = groups_create_group((object) array('name' => 'Group 2', 'courseid' => $course2->id));
     $group3 = $DB->get_record('groups', array('id' => $id), '*', MUST_EXIST);
     $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid' => context_coursecat::instance($cat1->id)->id));
     $id = $cohortplugin->add_instance($course1, array('customint1' => $cohort1->id, 'roleid' => $studentrole->id, 'customint2' => $group1->id));
     $cohortinstance1 = $DB->get_record('enrol', array('id' => $id));
     $this->assertTrue(groups_add_member($group1, $user4));
     $this->assertTrue(groups_add_member($group2, $user4));
     $this->assertEquals(3, $DB->count_records('user_enrolments', array()));
     $this->assertEquals(2, $DB->count_records('role_assignments', array()));
     $this->assertFalse(groups_is_member($group1->id, $user1->id));
     cohort_add_member($cohort1->id, $user1->id);
     cohort_add_member($cohort1->id, $user4->id);
     cohort_add_member($cohort2->id, $user4->id);
     cohort_add_member($cohort2->id, $user3->id);
     $this->enable_plugin();
     enrol_cohort_sync($trace, null);
     $this->assertEquals(8, $DB->count_records('user_enrolments', array()));
     $this->assertEquals(8, $DB->count_records('role_assignments', array()));
     $this->assertTrue(groups_is_member($group1->id, $user1->id));
     $this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
     $this->assertTrue(is_enrolled(context_course::instance($course1->id), $user4));
     $this->assertTrue(groups_is_member($group1->id, $user4->id));
     $this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user4->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
     $this->assertTrue(is_enrolled(context_course::instance($course2->id), $user3));
     $this->assertFalse(groups_is_member($group3->id, $user3->id));
     $cohortinstance1->customint2 = $group2->id;
     $DB->update_record('enrol', $cohortinstance1);
     $cohortinstance3->customint2 = $group3->id;
     $DB->update_record('enrol', $cohortinstance3);
     enrol_cohort_sync($trace, null);
     $this->assertFalse(groups_is_member($group1->id, $user1->id));
     $this->assertTrue(groups_is_member($group2->id, $user1->id));
     $this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user1->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
     $this->assertTrue(groups_is_member($group1->id, $user4->id));
     $this->assertTrue(groups_is_member($group2->id, $user4->id));
     $this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user4->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
     $this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user4->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
     $this->assertTrue(groups_is_member($group3->id, $user3->id));
     $this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group3->id, 'userid' => $user3->id, 'component' => 'enrol_cohort', 'itemid' => $cohortinstance3->id)));
     cohort_remove_member($cohort1->id, $user1->id);
     $this->assertFalse(groups_is_member($group1->id, $user1->id));
     cohort_remove_member($cohort1->id, $user4->id);
     $this->assertTrue(groups_is_member($group1->id, $user4->id));
     $this->assertTrue(groups_is_member($group2->id, $user4->id));
 }
 function save_course_settings()
 {
     $user_id = get_current_user_id();
     $course_id = $_POST['course_id'];
     $course_setting['vibe_course_auto_eval'] = $_POST['vibe_course_auto_eval'];
     $course_setting['vibe_duration'] = $_POST['vibe_duration'];
     $course_setting['vibe_pre_course'] = $_POST['vibe_pre_course'];
     $course_setting['vibe_course_drip'] = $_POST['vibe_course_drip'];
     $course_setting['vibe_course_drip_duration'] = $_POST['vibe_course_drip_duration'];
     $course_setting['vibe_course_certificate'] = $_POST['vibe_certificate'];
     $course_setting['vibe_course_passing_percentage'] = $_POST['vibe_course_passing_percentage'];
     $course_setting['vibe_certificate_template'] = $_POST['vibe_certificate_template'];
     $course_setting['vibe_badge'] = $_POST['vibe_badge'];
     $course_setting['vibe_course_badge_percentage'] = $_POST['vibe_course_badge_percentage'];
     $course_setting['vibe_course_badge_title'] = $_POST['vibe_course_badge_title'];
     $course_setting['vibe_course_badge'] = $_POST['vibe_course_badge'];
     $course_setting['vibe_max_students'] = $_POST['vibe_max_students'];
     $course_setting['vibe_start_date'] = $_POST['vibe_start_date'];
     $course_setting['vibe_course_retakes'] = $_POST['vibe_course_retakes'];
     $course_setting['vibe_group'] = $_POST['vibe_group'];
     $course_setting['vibe_forum'] = $_POST['vibe_forum'];
     $course_setting['vibe_course_instructions'] = $_POST['vibe_course_instructions'];
     $course_setting['vibe_course_message'] = $_POST['vibe_course_message'];
     $flag = 0;
     //Error Flag
     if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'create_course' . $user_id) || !current_user_can('edit_posts')) {
         _e('Security check Failed. Contact Administrator.', 'wplms-front-end');
         die;
     }
     if (!is_numeric($course_id) || get_post_type($course_id) != 'course') {
         _e('Invalid Course id, please edit a course', 'wplms-front-end');
         die;
     }
     $the_post = get_post($course_id);
     if ($the_post->post_author != $user_id && !current_user_can('manage_options')) {
         _e('Invalid Course Instructor', 'wplms-front-end');
         die;
     }
     if ($course_setting['vibe_badge'] == 'H') {
         $course_setting['vibe_course_badge'] = '';
     }
     foreach ($course_setting as $key => $value) {
         $prev_val = get_post_meta($course_id, $key, true);
         if ($prev_val != $value) {
             update_post_meta($course_id, $key, $value);
         }
     }
     if ($course_setting['vibe_group'] == 'add_new' && !$flag) {
         $the_course = get_post($course_id);
         $t = wp_get_attachment_image_src(get_post_thumbnail_id($course_id, 'thumbnail'));
         $f = wp_get_attachment_image_src(get_post_thumbnail_id($course_id, 'full'));
         $group_slug = $the_course->post_name;
         //groups_check_slug( sanitize_title( esc_attr( $the_course->post_name ) ) );
         $group_settings = array('creator_id' => $user_id, 'name' => $the_course->post_title, 'slug' => $group_slug, 'description' => $the_course->post_excerpt, 'status' => 'private', 'date_created' => current_time('mysql'));
         $group_settings = apply_filters('wplms_front_end_group_vars', $group_settings);
         if ($course_setting['vibe_forum'] == 'add_group_forum') {
             $group_settings['enable_forum'] = 1;
         }
         global $bp;
         $new_group_id = groups_create_group($group_settings);
         bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $new_group_id, 'original_file' => $f[0], 'crop_x' => 0, 'crop_y' => 0, 'crop_w' => $f[1], 'crop_h' => $f[2]));
         groups_update_groupmeta($new_group_id, 'total_member_count', 1);
         groups_update_groupmeta($new_group_id, 'last_activity', gmdate("Y-m-d H:i:s"));
         update_post_meta($course_id, 'vibe_group', $new_group_id);
         if ($course_setting['vibe_forum'] == 'add_group_forum') {
             $forum_settings = array('post_title' => stripslashes($the_course->post_title), 'post_content' => stripslashes($the_course->post_excerpt), 'post_name' => $the_course->post_name, 'post_status' => 'private', 'post_type' => 'forum');
             $forum_settings = apply_filters('wplms_front_end_forum_vars', $forum_settings);
             $new_forum_id = wp_insert_post($forum_settings);
             //Linkage
             $linkage = vibe_get_option('linkage');
             if (isset($linkage) && $linkage) {
                 $course_linkage = wp_get_post_terms($course_id, 'linkage', array("fields" => "names"));
                 if (isset($course_linkage) && is_array($course_linkage)) {
                     wp_set_post_terms($new_forum_id, $course_linkage, 'linkage');
                 }
             }
             groups_update_groupmeta($new_group_id, 'forum_id', array($new_forum_id));
             update_post_meta($course_id, 'vibe_forum', $new_forum_id);
         }
     }
     if ($course_setting['vibe_forum'] == 'add_new' && !$flag) {
         $forum_settings = array('post_title' => stripslashes($the_post->post_title), 'post_content' => stripslashes($the_post->post_excerpt), 'post_name' => $the_post->post_name, 'post_status' => 'private', 'post_type' => 'forum');
         $forum_settings = apply_filters('wplms_front_end_forum_vars', $forum_settings);
         $new_forum_id = wp_insert_post($forum_settings);
         update_post_meta($course_id, 'vibe_forum', $new_forum_id);
     }
     if (isset($_POST['level']) && $_POST['level']) {
         $level = $_POST['level'];
         if (is_numeric($level)) {
             wp_set_post_terms($course_id, $level, 'level');
         }
     }
     if ($flag) {
         echo $message;
     } else {
         echo $course_id;
         do_action('wplms_course_settings_updated', $course_id);
     }
     die;
 }
Example #28
0
                 // only non-numeric names are supported!!!
                 $ccache[$shortname]->groups[$group->name] = new stdClass();
                 $ccache[$shortname]->groups[$group->name]->id = $gid;
                 $ccache[$shortname]->groups[$group->name]->name = $group->name;
             }
         }
     }
 }
 // group exists?
 $addgroup = $user->{'group' . $i};
 if (!array_key_exists($addgroup, $ccache[$shortname]->groups)) {
     // if group doesn't exist,  create it
     $newgroupdata = new stdClass();
     $newgroupdata->name = $addgroup;
     $newgroupdata->courseid = $ccache[$shortname]->id;
     if ($ccache[$shortname]->groups[$addgroup]->id = groups_create_group($newgroupdata)) {
         $ccache[$shortname]->groups[$addgroup]->name = $newgroupdata->name;
     } else {
         $upt->track('enrolments', get_string('unknowngroup', 'error', s($addgroup)), 'error');
         continue;
     }
 }
 $gid = $ccache[$shortname]->groups[$addgroup]->id;
 $gname = $ccache[$shortname]->groups[$addgroup]->name;
 try {
     if (groups_add_member($gid, $user->id)) {
         $upt->track('enrolments', get_string('addedtogroup', '', s($gname)));
     } else {
         $upt->track('enrolments', get_string('addedtogroupnot', '', s($gname)), 'error');
     }
 } catch (moodle_exception $e) {
Example #29
0
            }
        }
    }
}
/// 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 {
    $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 #30
0
                 $ccache[$shortname]->groups[$group->name] = new stdClass();
                 $ccache[$shortname]->groups[$group->name]->id = $gid;
                 $ccache[$shortname]->groups[$group->name]->name = $group->name;
             }
         }
     }
 }
 // group exists?
 $addgroup = $user->{'group' . $i};
 if (!array_key_exists($addgroup, $ccache[$shortname]->groups)) {
     // if group doesn't exist,  create it
     $newgroupdata = new stdClass();
     $newgroupdata->name = $addgroup;
     $newgroupdata->courseid = $ccache[$shortname]->id;
     $newgroupdata->description = '';
     $gid = groups_create_group($newgroupdata);
     if ($gid) {
         $ccache[$shortname]->groups[$addgroup] = new stdClass();
         $ccache[$shortname]->groups[$addgroup]->id = $gid;
         $ccache[$shortname]->groups[$addgroup]->name = $newgroupdata->name;
     } else {
         $upt->track('enrolments', get_string('unknowngroup', 'error', s($addgroup)), 'error');
         continue;
     }
 }
 $gid = $ccache[$shortname]->groups[$addgroup]->id;
 $gname = $ccache[$shortname]->groups[$addgroup]->name;
 try {
     if (groups_add_member($gid, $user->id)) {
         $upt->track('enrolments', get_string('addedtogroup', '', s($gname)));
     } else {