本文整理汇总了PHP中wiki_get_subwiki_by_group函数的典型用法代码示例。如果您正苦于以下问题:PHP wiki_get_subwiki_by_group函数的具体用法?PHP wiki_get_subwiki_by_group怎么用?PHP wiki_get_subwiki_by_group使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wiki_get_subwiki_by_group函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: page_index
public function page_index() {
global $CFG;
$output = '';
// Checking wiki instance
if (!$wiki = wiki_get_wiki($this->page->cm->instance)) {
return false;
}
// @TODO: Fix call to wiki_get_subwiki_by_group
$gid = groups_get_activity_group($this->page->cm);
$gid = !empty($gid) ? $gid : 0;
if (!$subwiki = wiki_get_subwiki_by_group($this->page->cm->instance, $gid)) {
return false;
}
$swid = $subwiki->id;
$pages = wiki_get_page_list($swid);
$selectoptions = array();
foreach ($pages as $page) {
$selectoptions[$page->id] = $page->title;
}
$label = get_string('pageindex', 'wiki') . ': ';
$select = new single_select(new moodle_url('/mod/wiki/view.php'), 'pageid', $selectoptions);
$select->label = $label;
return $this->output->container($this->output->render($select), 'wiki_index');
}
示例2: wiki_extend_navigation
function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm)
{
global $CFG, $PAGE, $USER;
require_once $CFG->dirroot . '/mod/wiki/locallib.php';
$context = context_module::instance($cm->id);
$url = $PAGE->url;
$userid = 0;
if ($module->wikimode == 'individual') {
$userid = $USER->id;
}
if (!($wiki = wiki_get_wiki($cm->instance))) {
return false;
}
if (!($gid = groups_get_activity_group($cm))) {
$gid = 0;
}
if (!($subwiki = wiki_get_subwiki_by_group($cm->instance, $gid, $userid))) {
return null;
} else {
$swid = $subwiki->id;
}
$pageid = $url->param('pageid');
$cmid = $url->param('id');
if (empty($pageid) && !empty($cmid)) {
// wiki main page
$page = wiki_get_page_by_title($swid, $wiki->firstpagetitle);
$pageid = $page->id;
}
if (wiki_can_create_pages($context)) {
$link = new moodle_url('/mod/wiki/create.php', array('action' => 'new', 'swid' => $swid));
$node = $navref->add(get_string('newpage', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (is_numeric($pageid)) {
if (has_capability('mod/wiki:viewpage', $context)) {
$link = new moodle_url('/mod/wiki/view.php', array('pageid' => $pageid));
$node = $navref->add(get_string('view', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (wiki_user_can_edit($subwiki)) {
$link = new moodle_url('/mod/wiki/edit.php', array('pageid' => $pageid));
$node = $navref->add(get_string('edit', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:viewcomment', $context)) {
$link = new moodle_url('/mod/wiki/comments.php', array('pageid' => $pageid));
$node = $navref->add(get_string('comments', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:viewpage', $context)) {
$link = new moodle_url('/mod/wiki/history.php', array('pageid' => $pageid));
$node = $navref->add(get_string('history', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:viewpage', $context)) {
$link = new moodle_url('/mod/wiki/map.php', array('pageid' => $pageid));
$node = $navref->add(get_string('map', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:viewpage', $context)) {
$link = new moodle_url('/mod/wiki/files.php', array('pageid' => $pageid));
$node = $navref->add(get_string('files', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:managewiki', $context)) {
$link = new moodle_url('/mod/wiki/admin.php', array('pageid' => $pageid));
$node = $navref->add(get_string('admin', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
}
}
示例3: optional_param
// User ID
$groupanduser = optional_param('groupanduser', null, PARAM_TEXT);
if (!($page = wiki_get_page($pageid))) {
print_error('incorrectpageid', 'wiki');
}
if ($groupanduser) {
list($currentgroup, $userid) = explode('-', $groupanduser);
$currentgroup = clean_param($currentgroup, PARAM_INT);
$userid = clean_param($userid, PARAM_INT);
}
if ($wid) {
// in group mode
if (!($wiki = wiki_get_wiki($wid))) {
print_error('incorrectwikiid', 'wiki');
}
if (!($subwiki = wiki_get_subwiki_by_group($wiki->id, $currentgroup, $userid))) {
// create subwiki if doesn't exist
$subwikiid = wiki_add_subwiki($wiki->id, $currentgroup, $userid);
$subwiki = wiki_get_subwiki($subwikiid);
}
} else {
// no group
if (!($subwiki = wiki_get_subwiki($page->subwikiid))) {
print_error('incorrectsubwikiid', 'wiki');
}
// Checking wiki instance of that subwiki
if (!($wiki = wiki_get_wiki($subwiki->wikiid))) {
print_error('incorrectwikiid', 'wiki');
}
}
// Checking course module instance
示例4: create_page
function create_page($pagetitle) {
global $USER, $PAGE;
$data = $this->mform->get_data();
if (isset($data->groupinfo)) {
$groupid = $data->groupinfo;
} else if (!empty($this->gid)) {
$groupid = $this->gid;
} else {
$groupid = '0';
}
if (empty($this->subwiki)) {
// If subwiki is not set then try find one and set else create one.
if (!$this->subwiki = wiki_get_subwiki_by_group($this->wid, $groupid, $this->uid)) {
$swid = wiki_add_subwiki($PAGE->activityrecord->id, $groupid, $this->uid);
$this->subwiki = wiki_get_subwiki($swid);
}
}
if ($data) {
$this->set_title($data->pagetitle);
$id = wiki_create_page($this->subwiki->id, $data->pagetitle, $data->pageformat, $USER->id);
} else {
$this->set_title($pagetitle);
$id = wiki_create_page($this->subwiki->id, $pagetitle, $PAGE->activityrecord->defaultformat, $USER->id);
}
$this->page = $id;
return $id;
}
示例5: optional_param
$group = optional_param('group', 0, PARAM_INT);
$uid = optional_param('uid', 0, PARAM_INT);
// 'create' action must be submitted by moodle form
// so sesskey must be checked
if ($action == 'create') {
if (!confirm_sesskey()) {
print_error('invalidsesskey');
}
}
if (!empty($swid)) {
$subwiki = wiki_get_subwiki($swid);
if (!($wiki = wiki_get_wiki($subwiki->wikiid))) {
print_error('incorrectwikiid', 'wiki');
}
} else {
$subwiki = wiki_get_subwiki_by_group($wid, $group, $uid);
if (!($wiki = wiki_get_wiki($wid))) {
print_error('incorrectwikiid', 'wiki');
}
}
if (!($cm = get_coursemodule_from_instance('wiki', $wiki->id))) {
print_error('invalidcoursemodule');
}
$groups = new stdClass();
if (groups_get_activity_groupmode($cm)) {
$modulecontext = context_module::instance($cm->id);
$canaccessgroups = has_capability('moodle/site:accessallgroups', $modulecontext);
if ($canaccessgroups) {
$groups->availablegroups = groups_get_all_groups($cm->course);
$allpart = new stdClass();
$allpart->id = '0';
示例6: list
if ($wiki->wikimode == 'individual' && ($groupmode == SEPARATEGROUPS || $groupmode == VISIBLEGROUPS)) {
list($gid, $uid) = explode('-', $groupanduser);
} else if ($wiki->wikimode == 'individual') {
$gid = 0;
$uid = $userid;
} else if ($groupmode == NOGROUPS) {
$gid = 0;
$uid = 0;
} else {
$gid = $currentgroup;
$uid = 0;
}
// Getting subwiki instance. If it does not exists, redirect to create page
if (!$subwiki = wiki_get_subwiki_by_group($wiki->id, $gid, $uid)) {
$context = context_module::instance($cm->id);
$modeanduser = $wiki->wikimode == 'individual' && $uid != $USER->id;
$modeandgroupmember = $wiki->wikimode == 'collaborative' && !groups_is_member($gid);
$manage = has_capability('mod/wiki:managewiki', $context);
$edit = has_capability('mod/wiki:editpage', $context);
$manageandedit = $manage && $edit;
if ($groupmode == VISIBLEGROUPS and ($modeanduser || $modeandgroupmember) and !$manageandedit) {
print_error('nocontent','wiki');
}
$params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $uid, 'title' => $title);
$url = new moodle_url('/mod/wiki/create.php', $params);
示例7: wiki_get_subwiki
if ($subwikiid) {
// Subwiki id is specified.
$subwiki = wiki_get_subwiki($subwikiid);
if (!$subwiki || $subwiki->wikiid != $wiki->id) {
print_error('incorrectsubwikiid', 'wiki');
}
} else {
// Getting current group id
$gid = groups_get_activity_group($cm);
// Getting current user id
if ($wiki->wikimode == 'individual') {
$userid = $userid ? $userid : $USER->id;
} else {
$userid = 0;
}
if (!($subwiki = wiki_get_subwiki_by_group($cm->instance, $gid, $userid))) {
// Subwiki does not exist yet, redirect to the view page (which will redirect to create page if allowed).
$params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $userid, 'title' => $wiki->firstpagetitle);
$url = new moodle_url('/mod/wiki/view.php', $params);
redirect($url);
}
}
if ($subwiki && !wiki_user_can_view($subwiki, $wiki)) {
print_error('cannotviewpage', 'wiki');
}
$wikipage = new page_wiki_search($wiki, $subwiki, $cm);
$wikipage->set_search_string($search, $searchcontent);
$wikipage->set_title(get_string('search'));
$wikipage->print_header();
$wikipage->print_content();
$wikipage->print_footer();
示例8: create_page
function create_page($pagetitle)
{
global $USER, $PAGE;
$data = $this->mform->get_data();
if (isset($data->groupinfo)) {
$groupid = $data->groupinfo;
} else {
$groupid = '0';
}
if (!($this->subwiki = wiki_get_subwiki_by_group($this->wid, $groupid))) {
$swid = wiki_add_subwiki($PAGE->activityrecord->id, $groupid, $this->uid);
$this->subwiki = wiki_get_subwiki($swid);
}
if ($data) {
$this->set_title($data->pagetitle);
$id = wiki_create_page($this->subwiki->id, $data->pagetitle, $data->pageformat, $USER->id);
} else {
$this->set_title($pagetitle);
$id = wiki_create_page($this->subwiki->id, $pagetitle, $PAGE->activityrecord->defaultformat, $USER->id);
}
$this->page = $id;
return $id;
}
示例9: wiki_get_subwiki_by_group_and_user_with_validation
/**
* Utility function for getting a subwiki by group and user, validating that the user can view it.
* If the subwiki doesn't exists in DB yet it'll have id -1.
*
* @param stdClass $wiki The wiki.
* @param int $groupid Group ID. 0 means the subwiki doesn't use groups.
* @param int $userid User ID. 0 means the subwiki doesn't use users.
* @return stdClass Subwiki. If it doesn't exists in DB yet it'll have id -1. If the user can't view the
* subwiki this function will return false.
* @since Moodle 3.1
* @throws moodle_exception
*/
function wiki_get_subwiki_by_group_and_user_with_validation($wiki, $groupid, $userid)
{
global $USER, $DB;
// Get subwiki based on group and user.
if (!($subwiki = wiki_get_subwiki_by_group($wiki->id, $groupid, $userid))) {
// The subwiki doesn't exist.
// Validate if user is valid.
if ($userid != 0) {
$user = core_user::get_user($userid, '*', MUST_EXIST);
core_user::require_active_user($user);
}
// Validate that groupid is valid.
if ($groupid != 0 && !groups_group_exists($groupid)) {
throw new moodle_exception('cannotfindgroup', 'error');
}
// Valid data but subwiki not found. We'll simulate a subwiki object to check if the user would be able to see it
// if it existed. If he's able to see it then we'll return an empty array because the subwiki has no pages.
$subwiki = new stdClass();
$subwiki->id = -1;
$subwiki->wikiid = $wiki->id;
$subwiki->userid = $userid;
$subwiki->groupid = $groupid;
}
// Check that the user can view the subwiki. This function checks capabilities.
if (!wiki_user_can_view($subwiki, $wiki)) {
return false;
}
return $subwiki;
}
示例10: wiki_get_possible_subwiki_by_group
/**
* Get a sub wiki instance by wiki id, group id and user id.
* If the wiki doesn't exist in DB it will return an isntance with id -1.
*
* @param int $wikiid Wiki ID.
* @param int $groupid Group ID.
* @param int $userid User ID.
* @return object Subwiki instance.
* @since Moodle 3.1
*/
function wiki_get_possible_subwiki_by_group($wikiid, $groupid, $userid = 0)
{
if (!($subwiki = wiki_get_subwiki_by_group($wikiid, $groupid, $userid))) {
$subwiki = new stdClass();
$subwiki->id = -1;
$subwiki->wikiid = $wikiid;
$subwiki->groupid = $groupid;
$subwiki->userid = $userid;
}
return $subwiki;
}
示例11: create_page
/**
* Generates a page in wiki.
*
* @param stdClass wiki object returned from create_instance (if known)
* @param stdClass|array $record data to insert as wiki entry.
* @return stdClass
* @throws coding_exception if neither $record->wikiid nor $wiki->id is specified
*/
public function create_page($wiki, $record = array())
{
global $CFG, $USER;
require_once $CFG->dirroot . '/mod/wiki/locallib.php';
$this->pagecount++;
$record = (array) $record + array('title' => 'wiki page ' . $this->pagecount, 'wikiid' => $wiki->id, 'subwikiid' => 0, 'group' => 0, 'content' => 'Wiki page content ' . $this->pagecount, 'format' => $wiki->defaultformat);
if (empty($record['wikiid']) && empty($record['subwikiid'])) {
throw new coding_exception('wiki page generator requires either wikiid or subwikiid');
}
if (!$record['subwikiid']) {
if (!isset($record['userid'])) {
$record['userid'] = $wiki->wikimode == 'individual' ? $USER->id : 0;
}
if ($subwiki = wiki_get_subwiki_by_group($record['wikiid'], $record['group'], $record['userid'])) {
$record['subwikiid'] = $subwiki->id;
} else {
$record['subwikiid'] = wiki_add_subwiki($record['wikiid'], $record['group'], $record['userid']);
}
}
if ($wikipage = wiki_get_page_by_title($record['subwikiid'], $record['title'])) {
$rv = wiki_save_page($wikipage, $record['content'], $USER->id);
return $rv['page'];
}
$pageid = wiki_create_page($record['subwikiid'], $record['title'], $record['format'], $USER->id);
$wikipage = wiki_get_page($pageid);
$rv = wiki_save_page($wikipage, $record['content'], $USER->id);
return $rv['page'];
}
示例12: create_page
/**
* Generates a page in wiki.
*
* @param stdClass wiki object returned from create_instance (if known)
* @param stdClass|array $record data to insert as wiki entry.
* @return stdClass
* @throws coding_exception if neither $record->wikiid nor $wiki->id is specified
*/
public function create_page($wiki, $record = array())
{
global $CFG, $USER;
require_once $CFG->dirroot . '/mod/wiki/locallib.php';
$this->pagecount++;
$record = (array) $record + array('title' => 'wiki page ' . $this->pagecount, 'wikiid' => $wiki->id, 'subwikiid' => 0, 'group' => 0, 'content' => 'Wiki page content ' . $this->pagecount, 'format' => $wiki->defaultformat);
if (empty($record['wikiid']) && empty($record['subwikiid'])) {
throw new coding_exception('wiki page generator requires either wikiid or subwikiid');
}
if (!$record['subwikiid']) {
if (!isset($record['userid'])) {
$record['userid'] = $wiki->wikimode == 'individual' ? $USER->id : 0;
}
if ($subwiki = wiki_get_subwiki_by_group($record['wikiid'], $record['group'], $record['userid'])) {
$record['subwikiid'] = $subwiki->id;
} else {
$record['subwikiid'] = wiki_add_subwiki($record['wikiid'], $record['group'], $record['userid']);
}
}
$wikipage = wiki_get_page_by_title($record['subwikiid'], $record['title']);
if (!$wikipage) {
$pageid = wiki_create_page($record['subwikiid'], $record['title'], $record['format'], $USER->id);
$wikipage = wiki_get_page($pageid);
}
$rv = wiki_save_page($wikipage, $record['content'], $USER->id);
if (array_key_exists('tags', $record)) {
$tags = is_array($record['tags']) ? $record['tags'] : preg_split('/,/', $record['tags']);
if (empty($wiki->cmid)) {
$cm = get_coursemodule_from_instance('wiki', $wiki->id, isset($wiki->course) ? $wiki->course : 0);
$wiki->cmid = $cm->id;
}
core_tag_tag::set_item_tags('mod_wiki', 'wiki_pages', $wikipage->id, context_module::instance($wiki->cmid), $tags);
}
return $rv['page'];
}
示例13: get_subwiki_pages
/**
* Returns the list of pages from a specific subwiki.
*
* @param int $wikiid The wiki instance ID.
* @param int $groupid The group ID. If not defined, use current group.
* @param int $userid The user ID. If not defined, use current user.
* @param array $options Several options like sort by, sort direction, ...
* @return array Containing a list of warnings and a list of pages.
* @since Moodle 3.1
*/
public static function get_subwiki_pages($wikiid, $groupid = -1, $userid = 0, $options = array())
{
global $USER, $DB;
$returnedpages = array();
$warnings = array();
$params = self::validate_parameters(self::get_subwiki_pages_parameters(), array('wikiid' => $wikiid, 'groupid' => $groupid, 'userid' => $userid, 'options' => $options));
// Get wiki instance.
if (!($wiki = wiki_get_wiki($params['wikiid']))) {
throw new moodle_exception('incorrectwikiid', 'wiki');
}
list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki');
$context = context_module::instance($cm->id);
self::validate_context($context);
// Determine group.
$groupmode = groups_get_activity_groupmode($cm);
if ($groupmode == NOGROUPS) {
$groupid = 0;
} else {
if ($params['groupid'] == -1) {
// Use current group.
$groupid = groups_get_activity_group($cm);
$groupid = !empty($groupid) ? $groupid : 0;
} else {
$groupid = $params['groupid'];
}
}
// Determine user.
if ($wiki->wikimode == 'collaborative') {
// Collaborative wikis don't use userid in subwikis.
$userid = 0;
} else {
if (empty($params['userid'])) {
// Use current user.
$userid = $USER->id;
} else {
$userid = $params['userid'];
}
}
// Get subwiki based on group and user.
if (!($subwiki = wiki_get_subwiki_by_group($cm->instance, $groupid, $userid))) {
// The subwiki doesn't exist.
// Validate if user is valid.
if ($userid != 0 && $userid != $USER->id && !($user = $DB->get_record('user', array('id' => $userid)))) {
throw new moodle_exception('invaliduserid', 'error');
}
// Validate that groupid is valid.
if ($groupid != 0 && !groups_group_exists($groupid)) {
throw new moodle_exception('cannotfindgroup', 'error');
}
// Valid data but subwiki not found. We'll simulate a subwiki object to check if the user would be able to see it
// if it existed. If he's able to see it then we'll return an empty array because the subwiki has no pages.
$subwiki = new stdClass();
$subwiki->wikiid = $wiki->id;
$subwiki->userid = $userid;
$subwiki->groupid = $groupid;
// Check that the user can view the subwiki. This function checks capabilities.
if (!wiki_user_can_view($subwiki, $wiki)) {
throw new moodle_exception('cannotviewpage', 'wiki');
}
} else {
// Check that the user can view the subwiki. This function checks capabilities.
if (!wiki_user_can_view($subwiki, $wiki)) {
throw new moodle_exception('cannotviewpage', 'wiki');
}
// Set sort param.
$options = $params['options'];
if (!empty($options['sortby'])) {
if ($options['sortdirection'] != 'ASC' && $options['sortdirection'] != 'DESC') {
// Invalid sort direction. Use default.
$options['sortdirection'] = 'ASC';
}
$sort = $options['sortby'] . ' ' . $options['sortdirection'];
}
$pages = wiki_get_page_list($subwiki->id, $sort);
$caneditpages = wiki_user_can_edit($subwiki);
$firstpage = wiki_get_first_page($subwiki->id);
foreach ($pages as $page) {
$retpage = array('id' => $page->id, 'subwikiid' => $page->subwikiid, 'title' => external_format_string($page->title, $context->id), 'timecreated' => $page->timecreated, 'timemodified' => $page->timemodified, 'timerendered' => $page->timerendered, 'userid' => $page->userid, 'pageviews' => $page->pageviews, 'readonly' => $page->readonly, 'caneditpage' => $caneditpages, 'firstpage' => $page->id == $firstpage->id);
if ($options['includecontent']) {
// Refresh page cached content if needed.
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
if ($content = wiki_refresh_cachedcontent($page)) {
$page = $content['page'];
}
}
list($retpage['cachedcontent'], $retpage['contentformat']) = external_format_text($page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id);
}
$returnedpages[] = $retpage;
}
}
//.........这里部分代码省略.........