function wiki_get_default_entry(&$wiki, &$course, $userid = 0, $groupid = 0) { /// Returns the wiki entry according to the wiki type. /// Optionally, will return wiki entry for $userid student wiki, or /// $groupid group or teacher wiki. /// Creates one if it needs to and it can. global $USER; /// If there is a groupmode, get the user's group id. $groupmode = groups_get_activity_groupmode($wiki); // if groups mode is in use and no group supplied, use the first one found if ($groupmode && !$groupid) { if (($mygroupids = mygroupid($course->id)) && count($mygroupids) > 0) { // Use first group. They ought to be able to change later $groupid = $mygroupids[0]; } else { // Whatever groups are in the course, pick one $coursegroups = groups_get_all_groups($course->id); if (!$coursegroups || count($coursegroups) == 0) { error("Can't access wiki in group mode when no groups are configured for the course"); } $unkeyed = array_values($coursegroups); // Make sure first item is index 0 $groupid = $unkeyed[0]->id; } } /// If the wiki entry doesn't exist, can this user create it? if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false) { if (wiki_can_add_entry($wiki, $USER, $course, $userid, $groupid)) { wiki_add_entry($wiki, $course, $userid, $groupid); if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false) { error("Could not add wiki entry."); } } } //print_object($wiki_entry); return $wiki_entry; }
/** * Returns the wiki entry according to the wiki type. * * Optionally, will return wiki entry for $userid student wiki, or * $groupid group or teacher wiki. * Creates one if it needs to and it can. * * @global object * @param object $wiki By reference * @param object $course By reference * @param int $userid * @param int $groupid * @return object */ function wiki_get_default_entry(&$wiki, &$course, $userid = 0, $groupid = 0) { global $USER; /// If there is a groupmode, get the user's group id. $groupmode = groups_get_activity_groupmode($wiki); // if groups mode is in use and no group supplied, use the first one found if ($groupmode && !$groupid) { if (($mygroupids = mygroupid($course->id)) && count($mygroupids) > 0) { // Use first group. They ought to be able to change later $groupid = $mygroupids[0]; } else { // Whatever groups are in the course, pick one $coursegroups = groups_get_all_groups($course->id); if (!$coursegroups || count($coursegroups) == 0) { print_error('groupmodeerror', 'wiki'); } $unkeyed = array_values($coursegroups); // Make sure first item is index 0 $groupid = $unkeyed[0]->id; } } /// If the wiki entry doesn't exist, can this user create it? if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false) { if (wiki_can_add_entry($wiki, $USER, $course, $userid, $groupid)) { wiki_add_entry($wiki, $course, $userid, $groupid); if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false) { print_error('cannotaddentry', 'wiki'); } } } //print_object($wiki_entry); return $wiki_entry; }