Example #1
0
File: lib.php Project: dg711/moodle
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);
        }
    }
}
Example #2
0
 /**
  * Returns a list of wikis in a provided list of courses,
  * if no list is provided all wikis that the user can view will be returned.
  *
  * @param array $courseids The courses IDs.
  * @return array Containing a list of warnings and a list of wikis.
  * @since Moodle 3.1
  */
 public static function get_wikis_by_courses($courseids = array())
 {
     $returnedwikis = array();
     $warnings = array();
     $params = self::validate_parameters(self::get_wikis_by_courses_parameters(), array('courseids' => $courseids));
     $mycourses = array();
     if (empty($params['courseids'])) {
         $mycourses = enrol_get_my_courses();
         $params['courseids'] = array_keys($mycourses);
     }
     // Ensure there are courseids to loop through.
     if (!empty($params['courseids'])) {
         list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
         // Get the wikis in this course, this function checks users visibility permissions.
         // We can avoid then additional validate_context calls.
         $wikis = get_all_instances_in_courses('wiki', $courses);
         foreach ($wikis as $wiki) {
             $context = context_module::instance($wiki->coursemodule);
             // Entry to return.
             $module = array();
             // First, we return information that any user can see in (or can deduce from) the web interface.
             $module['id'] = $wiki->id;
             $module['coursemodule'] = $wiki->coursemodule;
             $module['course'] = $wiki->course;
             $module['name'] = external_format_string($wiki->name, $context->id);
             $viewablefields = [];
             if (has_capability('mod/wiki:viewpage', $context)) {
                 list($module['intro'], $module['introformat']) = external_format_text($wiki->intro, $wiki->introformat, $context->id, 'mod_wiki', 'intro', $wiki->id);
                 $module['introfiles'] = external_util::get_area_files($context->id, 'mod_wiki', 'intro', false, false);
                 $viewablefields = array('firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend', 'section', 'visible', 'groupmode', 'groupingid');
             }
             // Check additional permissions for returning optional private settings.
             if (has_capability('moodle/course:manageactivities', $context)) {
                 $additionalfields = array('timecreated', 'timemodified');
                 $viewablefields = array_merge($viewablefields, $additionalfields);
             }
             foreach ($viewablefields as $field) {
                 $module[$field] = $wiki->{$field};
             }
             // Check if user can add new pages.
             $module['cancreatepages'] = wiki_can_create_pages($context);
             $returnedwikis[] = $module;
         }
     }
     $result = array();
     $result['wikis'] = $returnedwikis;
     $result['warnings'] = $warnings;
     return $result;
 }