// Get first undeleted (current) page version (there must be one) $pageversions = ouwiki_get_page_history($pageversion->pageid, false, 0, 1); $currentpageversion = reset($pageversions); if (!$currentpageversion) { throw new Exception('Error deleting/undeleting ouwiki page version'); } // Check if version that has been undeleted should be the new current version if ($pageversion->currentversionid != $currentpageversion->versionid) { // Set new current version id $DB->set_field('ouwiki_pages', 'currentversionid', $currentpageversion->versionid, array('id' => $pageversion->pageid)); } // Update completion status for user $completion = new completion_info($course); if ($completion->is_enabled($cm) && ($ouwiki->completionedits || $ouwiki->completionpages)) { $completion->update_state($cm, COMPLETION_COMPLETE, $pageversion->userid); } } } catch (Exception $e) { // Unlock page ouwiki_release_lock($pageversion->pageid); ouwiki_dberror('Error deleting/undeleting ouwiki page version ' . $e); } // Unlock page ouwiki_release_lock($pageversion->pageid); // Log delete or undelete action $ouwikiparamsurl = ouwiki_display_wiki_parameters($pagename, $subwiki, $cm, OUWIKI_PARAMS_URL); add_to_log($course->id, 'ouwiki', 'version' . $action, 'delete.php?' . $ouwikiparamsurl . '&version=' . $versionid, '', $cm->id); $redirecturl = new moodle_url('/mod/ouwiki/history.php'); // Redirect to view what is now the current version redirect($redirecturl . '?' . $ouwikiparamsurl); exit;
/** * Sets the page editing lock according to $lock * * @param integer $pageid Wiki page id * @param bool $lock * @return nothing */ function ouwiki_lock_editing($pageid, $lock) { global $DB; $locked = ouwiki_is_page_editing_locked($pageid); if ($lock != $locked) { $dataobject->id = $pageid; $dataobject->locked = $lock ? 1 : 0; try { $DB->update_record('ouwiki_pages', $dataobject); } catch (Exception $e) { ouwiki_dberror($e, 'Could not change the lock status for this wiki page'); } } }
/** * This function prints the recent activity (since current user's last login) * for specified courses. * @param array $courses Array of courses to print activity for. * @param string by reference $htmlarray Array of html snippets for display some * -where, which this function adds its new html to. */ function ouwiki_print_overview($courses, &$htmlarray) { global $USER, $CFG, $DB; if (empty($courses) || !is_array($courses) || count($courses) == 0) { return array(); } if (!($wikis = get_all_instances_in_courses('ouwiki', $courses))) { return; } // get all ouwiki logs in ONE query (much better!) $params = array(); $sql = 'SELECT instance, cmid, l.course, COUNT(l.id) as count FROM {log} l JOIN {course_modules} cm ON cm.id = cmid WHERE ('; foreach ($courses as $course) { $params[] = $course->id; $params[] = $course->lastaccess; $sql .= '(l.course = ? AND l.time > ?) OR '; } $sql = substr($sql, 0, -3); // take off the last OR $sql .= ") AND l.module = 'ouwiki' AND action = 'edit' " . " AND userid != ? GROUP BY cmid, l.course, instance"; $params[] = $USER->id; try { $new = $DB->get_records_sql($sql, $params); } catch (Exception $e) { ouwiki_dberror($e); } $strwikis = get_string('modulename', 'ouwiki'); $strnumrespsince1 = get_string('overviewnumentrysince1', 'ouwiki'); $strnumrespsince = get_string('overviewnumentrysince', 'ouwiki'); // Go through the list of all wikis build previously, and check whether // they have had any activity. foreach ($wikis as $wiki) { if (array_key_exists($wiki->id, $new) && !empty($new[$wiki->id])) { $count = $new[$wiki->id]->count; if ($count > 0) { if ($count == 1) { $strresp = $strnumrespsince1; } else { $strresp = $strnumrespsince; } $viewurl = new moodle_url('/mod/ouwiki/view.php', array('id' => $wiki->coursemodule)); $str = '<div class="overview wiki"><div class="name">' . $strwikis . ': <a title="' . $strwikis . '" href="' . $viewurl . '">' . $wiki->name . '</a></div>'; $str .= '<div class="info">'; $str .= $count . ' ' . $strresp; $str .= '</div></div>'; if (!array_key_exists($wiki->course, $htmlarray)) { $htmlarray[$wiki->course] = array(); } if (!array_key_exists('wiki', $htmlarray[$wiki->course])) { $htmlarray[$wiki->course]['wiki'] = ''; // initialize, avoid warnings } $htmlarray[$wiki->course]['wiki'] .= $str; } } } }
// we need to work backwords through this lot in order to maintain charactor position krsort($new_annotations, SORT_NUMERIC); $prevkey = ''; $spanlength = 0; foreach ($new_annotations as $key => $value) { if ($value != '') { $dataobject->pageid = $pageversion->pageid; $dataobject->userid = $userid; $dataobject->timemodified = time(); $dataobject->content = addslashes($value); try { $newannoid = insert_record('ouwiki_annotations', $dataobject); $updated[$newannoid] = ''; } catch (Exception $e) { $tw->rollback(); ouwiki_dberror('annotations'); } // we're still going so insert the new annotation into the xhtml $replace = '<span id="annotation' . $newannoid . '"></span>'; $position = $key; if ($key == $prevkey) { $position = $key + $spanlength; } else { $position = $key; } $pageversion->xhtml = substr_replace($pageversion->xhtml, $replace, $position, 0); $neednewversion = true; $spanlength = strlen($replace); $prevkey = $key; } }