[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * Library of functions and constants for module wiki 20 * 21 * It contains the great majority of functions defined by Moodle 22 * that are mandatory to develop a module. 23 * 24 * @package mod_wiki 25 * @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu 26 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu 27 * 28 * @author Jordi Piguillem 29 * @author Marc Alier 30 * @author David Jimenez 31 * @author Josep Arus 32 * @author Kenneth Riba 33 * 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 37 /** 38 * Given an object containing all the necessary data, 39 * (defined by the form in mod.html) this function 40 * will create a new instance and return the id number 41 * of the new instance. 42 * 43 * @param object $instance An object from the form in mod.html 44 * @return int The id of the newly inserted wiki record 45 **/ 46 function wiki_add_instance($wiki) { 47 global $DB; 48 49 $wiki->timemodified = time(); 50 # May have to add extra stuff in here # 51 if (empty($wiki->forceformat)) { 52 $wiki->forceformat = 0; 53 } 54 return $DB->insert_record('wiki', $wiki); 55 } 56 57 /** 58 * Given an object containing all the necessary data, 59 * (defined by the form in mod.html) this function 60 * will update an existing instance with new data. 61 * 62 * @param object $instance An object from the form in mod.html 63 * @return boolean Success/Fail 64 **/ 65 function wiki_update_instance($wiki) { 66 global $DB; 67 68 $wiki->timemodified = time(); 69 $wiki->id = $wiki->instance; 70 if (empty($wiki->forceformat)) { 71 $wiki->forceformat = 0; 72 } 73 74 # May have to add extra stuff in here # 75 76 return $DB->update_record('wiki', $wiki); 77 } 78 79 /** 80 * Given an ID of an instance of this module, 81 * this function will permanently delete the instance 82 * and any data that depends on it. 83 * 84 * @param int $id Id of the module instance 85 * @return boolean Success/Failure 86 **/ 87 function wiki_delete_instance($id) { 88 global $DB; 89 90 if (!$wiki = $DB->get_record('wiki', array('id' => $id))) { 91 return false; 92 } 93 94 $result = true; 95 96 # Get subwiki information # 97 $subwikis = $DB->get_records('wiki_subwikis', array('wikiid' => $wiki->id)); 98 99 foreach ($subwikis as $subwiki) { 100 # Get existing links, and delete them # 101 if (!$DB->delete_records('wiki_links', array('subwikiid' => $subwiki->id), IGNORE_MISSING)) { 102 $result = false; 103 } 104 105 # Get existing pages # 106 if ($pages = $DB->get_records('wiki_pages', array('subwikiid' => $subwiki->id))) { 107 foreach ($pages as $page) { 108 # Get locks, and delete them # 109 if (!$DB->delete_records('wiki_locks', array('pageid' => $page->id), IGNORE_MISSING)) { 110 $result = false; 111 } 112 113 # Get versions, and delete them # 114 if (!$DB->delete_records('wiki_versions', array('pageid' => $page->id), IGNORE_MISSING)) { 115 $result = false; 116 } 117 } 118 119 # Delete pages # 120 if (!$DB->delete_records('wiki_pages', array('subwikiid' => $subwiki->id), IGNORE_MISSING)) { 121 $result = false; 122 } 123 } 124 125 # Get existing synonyms, and delete them # 126 if (!$DB->delete_records('wiki_synonyms', array('subwikiid' => $subwiki->id), IGNORE_MISSING)) { 127 $result = false; 128 } 129 130 # Delete any subwikis # 131 if (!$DB->delete_records('wiki_subwikis', array('id' => $subwiki->id), IGNORE_MISSING)) { 132 $result = false; 133 } 134 } 135 136 # Delete any dependent records here # 137 if (!$DB->delete_records('wiki', array('id' => $wiki->id))) { 138 $result = false; 139 } 140 141 return $result; 142 } 143 144 /** 145 * Implements callback to reset course 146 * 147 * @param stdClass $data 148 * @return boolean|array 149 */ 150 function wiki_reset_userdata($data) { 151 global $CFG,$DB; 152 require_once($CFG->dirroot . '/mod/wiki/pagelib.php'); 153 require_once($CFG->dirroot . "/mod/wiki/locallib.php"); 154 155 $componentstr = get_string('modulenameplural', 'wiki'); 156 $status = array(); 157 158 //get the wiki(s) in this course. 159 if (!$wikis = $DB->get_records('wiki', array('course' => $data->courseid))) { 160 return false; 161 } 162 if (empty($data->reset_wiki_comments) && empty($data->reset_wiki_tags) && empty($data->reset_wiki_pages)) { 163 return $status; 164 } 165 166 foreach ($wikis as $wiki) { 167 if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id, $data->courseid)) { 168 continue; 169 } 170 $context = context_module::instance($cm->id); 171 172 // Remove tags or all pages. 173 if (!empty($data->reset_wiki_pages) || !empty($data->reset_wiki_tags)) { 174 175 // Get subwiki information. 176 $subwikis = wiki_get_subwikis($wiki->id); 177 178 foreach ($subwikis as $subwiki) { 179 // Get existing pages. 180 if ($pages = wiki_get_page_list($subwiki->id)) { 181 // If the wiki page isn't selected then we are only removing tags. 182 if (empty($data->reset_wiki_pages)) { 183 // Go through each page and delete the tags. 184 foreach ($pages as $page) { 185 core_tag_tag::remove_all_item_tags('mod_wiki', 'wiki_pages', $page->id); 186 } 187 } else { 188 // Otherwise we are removing pages and tags. 189 wiki_delete_pages($context, $pages, $subwiki->id); 190 } 191 } 192 if (!empty($data->reset_wiki_pages)) { 193 // Delete any subwikis. 194 $DB->delete_records('wiki_subwikis', array('id' => $subwiki->id), IGNORE_MISSING); 195 196 // Delete any attached files. 197 $fs = get_file_storage(); 198 $fs->delete_area_files($context->id, 'mod_wiki', 'attachments'); 199 } 200 } 201 202 if (!empty($data->reset_wiki_pages)) { 203 $status[] = array('component' => $componentstr, 'item' => get_string('deleteallpages', 'wiki'), 204 'error' => false); 205 } 206 if (!empty($data->reset_wiki_tags)) { 207 $status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'wiki'), 'error' => false); 208 } 209 } 210 211 // Remove all comments. 212 if (!empty($data->reset_wiki_comments) || !empty($data->reset_wiki_pages)) { 213 $DB->delete_records_select('comments', "contextid = ? AND commentarea='wiki_page'", array($context->id)); 214 if (!empty($data->reset_wiki_comments)) { 215 $status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false); 216 } 217 } 218 } 219 return $status; 220 } 221 222 223 function wiki_reset_course_form_definition(&$mform) { 224 $mform->addElement('header', 'wikiheader', get_string('modulenameplural', 'wiki')); 225 $mform->addElement('advcheckbox', 'reset_wiki_pages', get_string('deleteallpages', 'wiki')); 226 $mform->addElement('advcheckbox', 'reset_wiki_tags', get_string('removeallwikitags', 'wiki')); 227 $mform->addElement('advcheckbox', 'reset_wiki_comments', get_string('deleteallcomments')); 228 } 229 230 /** 231 * Indicates API features that the wiki supports. 232 * 233 * @uses FEATURE_GROUPS 234 * @uses FEATURE_GROUPINGS 235 * @uses FEATURE_MOD_INTRO 236 * @uses FEATURE_COMPLETION_TRACKS_VIEWS 237 * @uses FEATURE_COMPLETION_HAS_RULES 238 * @uses FEATURE_GRADE_HAS_GRADE 239 * @uses FEATURE_GRADE_OUTCOMES 240 * @param string $feature 241 * @return mixed True if yes (some features may use other values) 242 */ 243 function wiki_supports($feature) { 244 switch ($feature) { 245 case FEATURE_GROUPS: 246 return true; 247 case FEATURE_GROUPINGS: 248 return true; 249 case FEATURE_MOD_INTRO: 250 return true; 251 case FEATURE_COMPLETION_TRACKS_VIEWS: 252 return true; 253 case FEATURE_GRADE_HAS_GRADE: 254 return false; 255 case FEATURE_GRADE_OUTCOMES: 256 return false; 257 case FEATURE_RATE: 258 return false; 259 case FEATURE_BACKUP_MOODLE2: 260 return true; 261 case FEATURE_SHOW_DESCRIPTION: 262 return true; 263 264 default: 265 return null; 266 } 267 } 268 269 /** 270 * Given a course and a time, this module should find recent activity 271 * that has occurred in wiki activities and print it out. 272 * Return true if there was output, or false is there was none. 273 * 274 * @global $CFG 275 * @global $DB 276 * @uses CONTEXT_MODULE 277 * @uses VISIBLEGROUPS 278 * @param object $course 279 * @param bool $viewfullnames capability 280 * @param int $timestart 281 * @return boolean 282 **/ 283 function wiki_print_recent_activity($course, $viewfullnames, $timestart) { 284 global $CFG, $DB, $OUTPUT; 285 286 $sql = "SELECT p.id, p.timemodified, p.subwikiid, sw.wikiid, w.wikimode, sw.userid, sw.groupid 287 FROM {wiki_pages} p 288 JOIN {wiki_subwikis} sw ON sw.id = p.subwikiid 289 JOIN {wiki} w ON w.id = sw.wikiid 290 WHERE p.timemodified > ? AND w.course = ? 291 ORDER BY p.timemodified ASC"; 292 if (!$pages = $DB->get_records_sql($sql, array($timestart, $course->id))) { 293 return false; 294 } 295 require_once($CFG->dirroot . "/mod/wiki/locallib.php"); 296 297 $wikis = array(); 298 299 $modinfo = get_fast_modinfo($course); 300 301 $subwikivisible = array(); 302 foreach ($pages as $page) { 303 if (!isset($subwikivisible[$page->subwikiid])) { 304 $subwiki = (object)array('id' => $page->subwikiid, 'wikiid' => $page->wikiid, 305 'groupid' => $page->groupid, 'userid' => $page->userid); 306 $wiki = (object)array('id' => $page->wikiid, 'course' => $course->id, 'wikimode' => $page->wikimode); 307 $subwikivisible[$page->subwikiid] = wiki_user_can_view($subwiki, $wiki); 308 } 309 if ($subwikivisible[$page->subwikiid]) { 310 $wikis[] = $page; 311 } 312 } 313 unset($subwikivisible); 314 unset($pages); 315 316 if (!$wikis) { 317 return false; 318 } 319 echo $OUTPUT->heading(get_string("updatedwikipages", 'wiki') . ':', 3); 320 foreach ($wikis as $wiki) { 321 $cm = $modinfo->instances['wiki'][$wiki->wikiid]; 322 $link = $CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $wiki->id; 323 print_recent_activity_note($wiki->timemodified, $wiki, $cm->name, $link, false, $viewfullnames); 324 } 325 326 return true; // True if anything was printed, otherwise false 327 } 328 /** 329 * Function to be run periodically according to the moodle cron 330 * This function searches for things that need to be done, such 331 * as sending out mail, toggling flags etc ... 332 * 333 * @uses $CFG 334 * @return boolean 335 * @todo Finish documenting this function 336 **/ 337 function wiki_cron() { 338 global $CFG; 339 340 return true; 341 } 342 343 /** 344 * Must return an array of grades for a given instance of this module, 345 * indexed by user. It also returns a maximum allowed grade. 346 * 347 * Example: 348 * $return->grades = array of grades; 349 * $return->maxgrade = maximum allowed grade; 350 * 351 * return $return; 352 * 353 * @param int $wikiid ID of an instance of this module 354 * @return mixed Null or object with an array of grades and with the maximum grade 355 **/ 356 function wiki_grades($wikiid) { 357 return null; 358 } 359 360 /** 361 * This function returns if a scale is being used by one wiki 362 * it it has support for grading and scales. Commented code should be 363 * modified if necessary. See forum, glossary or journal modules 364 * as reference. 365 * 366 * @param int $wikiid ID of an instance of this module 367 * @return mixed 368 * @todo Finish documenting this function 369 **/ 370 function wiki_scale_used($wikiid, $scaleid) { 371 $return = false; 372 373 //$rec = get_record("wiki","id","$wikiid","scale","-$scaleid"); 374 // 375 //if (!empty($rec) && !empty($scaleid)) { 376 // $return = true; 377 //} 378 379 return $return; 380 } 381 382 /** 383 * Checks if scale is being used by any instance of wiki. 384 * This function was added in 1.9 385 * 386 * This is used to find out if scale used anywhere 387 * @param $scaleid int 388 * @return boolean True if the scale is used by any wiki 389 */ 390 function wiki_scale_used_anywhere($scaleid) { 391 global $DB; 392 393 //if ($scaleid and $DB->record_exists('wiki', array('grade' => -$scaleid))) { 394 // return true; 395 //} else { 396 // return false; 397 //} 398 399 return false; 400 } 401 402 /** 403 * file serving callback 404 * 405 * @copyright Josep Arus 406 * @package mod_wiki 407 * @category files 408 * @param stdClass $course course object 409 * @param stdClass $cm course module object 410 * @param stdClass $context context object 411 * @param string $filearea file area 412 * @param array $args extra arguments 413 * @param bool $forcedownload whether or not force download 414 * @param array $options additional options affecting the file serving 415 * @return bool false if the file was not found, just send the file otherwise and do not return anything 416 */ 417 function wiki_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { 418 global $CFG; 419 420 if ($context->contextlevel != CONTEXT_MODULE) { 421 return false; 422 } 423 424 require_login($course, true, $cm); 425 426 require_once($CFG->dirroot . "/mod/wiki/locallib.php"); 427 428 if ($filearea == 'attachments') { 429 $swid = (int) array_shift($args); 430 431 if (!$subwiki = wiki_get_subwiki($swid)) { 432 return false; 433 } 434 435 require_capability('mod/wiki:viewpage', $context); 436 437 $relativepath = implode('/', $args); 438 439 $fullpath = "/$context->id/mod_wiki/attachments/$swid/$relativepath"; 440 441 $fs = get_file_storage(); 442 if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { 443 return false; 444 } 445 446 send_stored_file($file, null, 0, $options); 447 } 448 } 449 450 function wiki_search_form($cm, $search = '', $subwiki = null) { 451 global $CFG, $OUTPUT; 452 453 $output = '<div class="wikisearch">'; 454 $output .= '<form method="post" action="' . $CFG->wwwroot . '/mod/wiki/search.php" style="display:inline">'; 455 $output .= '<fieldset class="invisiblefieldset">'; 456 $output .= '<legend class="accesshide">'. get_string('searchwikis', 'wiki') .'</legend>'; 457 $output .= '<label class="accesshide" for="searchwiki">' . get_string("searchterms", "wiki") . '</label>'; 458 $output .= '<input id="searchwiki" name="searchstring" type="text" size="18" value="' . s($search, true) . '" alt="search" />'; 459 $output .= '<input name="courseid" type="hidden" value="' . $cm->course . '" />'; 460 $output .= '<input name="cmid" type="hidden" value="' . $cm->id . '" />'; 461 if (!empty($subwiki->id)) { 462 $output .= '<input name="subwikiid" type="hidden" value="' . $subwiki->id . '" />'; 463 } 464 $output .= '<input name="searchwikicontent" type="hidden" value="1" />'; 465 $output .= '<input value="' . get_string('searchwikis', 'wiki') . '" type="submit" />'; 466 $output .= '</fieldset>'; 467 $output .= '</form>'; 468 $output .= '</div>'; 469 470 return $output; 471 } 472 function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm) { 473 global $CFG, $PAGE, $USER; 474 475 require_once($CFG->dirroot . '/mod/wiki/locallib.php'); 476 477 $context = context_module::instance($cm->id); 478 $url = $PAGE->url; 479 $userid = 0; 480 if ($module->wikimode == 'individual') { 481 $userid = $USER->id; 482 } 483 484 if (!$wiki = wiki_get_wiki($cm->instance)) { 485 return false; 486 } 487 488 if (!$gid = groups_get_activity_group($cm)) { 489 $gid = 0; 490 } 491 if (!$subwiki = wiki_get_subwiki_by_group($cm->instance, $gid, $userid)) { 492 return null; 493 } else { 494 $swid = $subwiki->id; 495 } 496 497 $pageid = $url->param('pageid'); 498 $cmid = $url->param('id'); 499 if (empty($pageid) && !empty($cmid)) { 500 // wiki main page 501 $page = wiki_get_page_by_title($swid, $wiki->firstpagetitle); 502 $pageid = $page->id; 503 } 504 505 if (wiki_can_create_pages($context)) { 506 $link = new moodle_url('/mod/wiki/create.php', array('action' => 'new', 'swid' => $swid)); 507 $node = $navref->add(get_string('newpage', 'wiki'), $link, navigation_node::TYPE_SETTING); 508 } 509 510 if (is_numeric($pageid)) { 511 512 if (has_capability('mod/wiki:viewpage', $context)) { 513 $link = new moodle_url('/mod/wiki/view.php', array('pageid' => $pageid)); 514 $node = $navref->add(get_string('view', 'wiki'), $link, navigation_node::TYPE_SETTING); 515 } 516 517 if (wiki_user_can_edit($subwiki)) { 518 $link = new moodle_url('/mod/wiki/edit.php', array('pageid' => $pageid)); 519 $node = $navref->add(get_string('edit', 'wiki'), $link, navigation_node::TYPE_SETTING); 520 } 521 522 if (has_capability('mod/wiki:viewcomment', $context)) { 523 $link = new moodle_url('/mod/wiki/comments.php', array('pageid' => $pageid)); 524 $node = $navref->add(get_string('comments', 'wiki'), $link, navigation_node::TYPE_SETTING); 525 } 526 527 if (has_capability('mod/wiki:viewpage', $context)) { 528 $link = new moodle_url('/mod/wiki/history.php', array('pageid' => $pageid)); 529 $node = $navref->add(get_string('history', 'wiki'), $link, navigation_node::TYPE_SETTING); 530 } 531 532 if (has_capability('mod/wiki:viewpage', $context)) { 533 $link = new moodle_url('/mod/wiki/map.php', array('pageid' => $pageid)); 534 $node = $navref->add(get_string('map', 'wiki'), $link, navigation_node::TYPE_SETTING); 535 } 536 537 if (has_capability('mod/wiki:viewpage', $context)) { 538 $link = new moodle_url('/mod/wiki/files.php', array('pageid' => $pageid)); 539 $node = $navref->add(get_string('files', 'wiki'), $link, navigation_node::TYPE_SETTING); 540 } 541 542 if (has_capability('mod/wiki:managewiki', $context)) { 543 $link = new moodle_url('/mod/wiki/admin.php', array('pageid' => $pageid)); 544 $node = $navref->add(get_string('admin', 'wiki'), $link, navigation_node::TYPE_SETTING); 545 } 546 } 547 } 548 /** 549 * Returns all other caps used in wiki module 550 * 551 * @return array 552 */ 553 function wiki_get_extra_capabilities() { 554 return array('moodle/comment:view', 'moodle/comment:post', 'moodle/comment:delete'); 555 } 556 557 /** 558 * Running addtional permission check on plugin, for example, plugins 559 * may have switch to turn on/off comments option, this callback will 560 * affect UI display, not like pluginname_comment_validate only throw 561 * exceptions. 562 * Capability check has been done in comment->check_permissions(), we 563 * don't need to do it again here. 564 * 565 * @package mod_wiki 566 * @category comment 567 * 568 * @param stdClass $comment_param { 569 * context => context the context object 570 * courseid => int course id 571 * cm => stdClass course module object 572 * commentarea => string comment area 573 * itemid => int itemid 574 * } 575 * @return array 576 */ 577 function wiki_comment_permissions($comment_param) { 578 return array('post'=>true, 'view'=>true); 579 } 580 581 /** 582 * Validate comment parameter before perform other comments actions 583 * 584 * @param stdClass $comment_param { 585 * context => context the context object 586 * courseid => int course id 587 * cm => stdClass course module object 588 * commentarea => string comment area 589 * itemid => int itemid 590 * } 591 * 592 * @package mod_wiki 593 * @category comment 594 * 595 * @return boolean 596 */ 597 function wiki_comment_validate($comment_param) { 598 global $DB, $CFG; 599 require_once($CFG->dirroot . '/mod/wiki/locallib.php'); 600 // validate comment area 601 if ($comment_param->commentarea != 'wiki_page') { 602 throw new comment_exception('invalidcommentarea'); 603 } 604 // validate itemid 605 if (!$record = $DB->get_record('wiki_pages', array('id'=>$comment_param->itemid))) { 606 throw new comment_exception('invalidcommentitemid'); 607 } 608 if (!$subwiki = wiki_get_subwiki($record->subwikiid)) { 609 throw new comment_exception('invalidsubwikiid'); 610 } 611 if (!$wiki = wiki_get_wiki_from_pageid($comment_param->itemid)) { 612 throw new comment_exception('invalidid', 'data'); 613 } 614 if (!$course = $DB->get_record('course', array('id'=>$wiki->course))) { 615 throw new comment_exception('coursemisconf'); 616 } 617 if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id, $course->id)) { 618 throw new comment_exception('invalidcoursemodule'); 619 } 620 $context = context_module::instance($cm->id); 621 // group access 622 if ($subwiki->groupid) { 623 $groupmode = groups_get_activity_groupmode($cm, $course); 624 if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { 625 if (!groups_is_member($subwiki->groupid)) { 626 throw new comment_exception('notmemberofgroup'); 627 } 628 } 629 } 630 // validate context id 631 if ($context->id != $comment_param->context->id) { 632 throw new comment_exception('invalidcontext'); 633 } 634 // validation for comment deletion 635 if (!empty($comment_param->commentid)) { 636 if ($comment = $DB->get_record('comments', array('id'=>$comment_param->commentid))) { 637 if ($comment->commentarea != 'wiki_page') { 638 throw new comment_exception('invalidcommentarea'); 639 } 640 if ($comment->contextid != $context->id) { 641 throw new comment_exception('invalidcontext'); 642 } 643 if ($comment->itemid != $comment_param->itemid) { 644 throw new comment_exception('invalidcommentitemid'); 645 } 646 } else { 647 throw new comment_exception('invalidcommentid'); 648 } 649 } 650 return true; 651 } 652 653 /** 654 * Return a list of page types 655 * @param string $pagetype current page type 656 * @param stdClass $parentcontext Block's parent context 657 * @param stdClass $currentcontext Current context of block 658 */ 659 function wiki_page_type_list($pagetype, $parentcontext, $currentcontext) { 660 $module_pagetype = array( 661 'mod-wiki-*'=>get_string('page-mod-wiki-x', 'wiki'), 662 'mod-wiki-view'=>get_string('page-mod-wiki-view', 'wiki'), 663 'mod-wiki-comments'=>get_string('page-mod-wiki-comments', 'wiki'), 664 'mod-wiki-history'=>get_string('page-mod-wiki-history', 'wiki'), 665 'mod-wiki-map'=>get_string('page-mod-wiki-map', 'wiki') 666 ); 667 return $module_pagetype; 668 } 669 670 /** 671 * Mark the activity completed (if required) and trigger the course_module_viewed event. 672 * 673 * @param stdClass $wiki Wiki object. 674 * @param stdClass $course Course object. 675 * @param stdClass $cm Course module object. 676 * @param stdClass $context Context object. 677 * @since Moodle 3.1 678 */ 679 function wiki_view($wiki, $course, $cm, $context) { 680 // Trigger course_module_viewed event. 681 $params = array( 682 'context' => $context, 683 'objectid' => $wiki->id 684 ); 685 $event = \mod_wiki\event\course_module_viewed::create($params); 686 $event->add_record_snapshot('course_modules', $cm); 687 $event->add_record_snapshot('course', $course); 688 $event->add_record_snapshot('wiki', $wiki); 689 $event->trigger(); 690 691 // Completion. 692 $completion = new completion_info($course); 693 $completion->set_module_viewed($cm); 694 } 695 696 /** 697 * Mark the activity completed (if required) and trigger the page_viewed event. 698 * 699 * @param stdClass $wiki Wiki object. 700 * @param stdClass $page Page object. 701 * @param stdClass $course Course object. 702 * @param stdClass $cm Course module object. 703 * @param stdClass $context Context object. 704 * @param int $uid Optional User ID. 705 * @param array $other Optional Other params: title, wiki ID, group ID, groupanduser, prettyview. 706 * @param stdClass $subwiki Optional Subwiki. 707 * @since Moodle 3.1 708 */ 709 function wiki_page_view($wiki, $page, $course, $cm, $context, $uid = null, $other = null, $subwiki = null) { 710 711 // Trigger course_module_viewed event. 712 $params = array( 713 'context' => $context, 714 'objectid' => $page->id 715 ); 716 if ($uid != null) { 717 $params['relateduserid'] = $uid; 718 } 719 if ($other != null) { 720 $params['other'] = $other; 721 } 722 723 $event = \mod_wiki\event\page_viewed::create($params); 724 725 $event->add_record_snapshot('wiki_pages', $page); 726 $event->add_record_snapshot('course_modules', $cm); 727 $event->add_record_snapshot('course', $course); 728 $event->add_record_snapshot('wiki', $wiki); 729 if ($subwiki != null) { 730 $event->add_record_snapshot('wiki_subwikis', $subwiki); 731 } 732 $event->trigger(); 733 734 // Completion. 735 $completion = new completion_info($course); 736 $completion->set_module_viewed($cm); 737 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |