コード例 #1
0
ファイル: locallib.php プロジェクト: esyacelga/sisadmaca
/**
 * Delete pages and all related data
 *
 * @param mixed $context context in which page needs to be deleted.
 * @param mixed $pageids id's of pages to be deleted
 * @param int $subwikiid id of the subwiki for which all pages should be deleted
 */
function wiki_delete_pages($context, $pageids = null, $subwikiid = null)
{
    global $DB;
    if (!empty($pageids) && is_int($pageids)) {
        $pageids = array($pageids);
    } else {
        if (!empty($subwikiid)) {
            $pageids = wiki_get_page_list($subwikiid);
        }
    }
    //If there is no pageid then return as we can't delete anything.
    if (empty($pageids)) {
        return;
    }
    /// Delete page and all it's relevent data
    foreach ($pageids as $pageid) {
        if (is_object($pageid)) {
            $pageid = $pageid->id;
        }
        //Delete page comments
        $comments = wiki_get_comments($context->id, $pageid);
        foreach ($comments as $commentid => $commentvalue) {
            wiki_delete_comment($commentid, $context, $pageid);
        }
        //Delete page tags
        $tags = tag_get_tags_array('wiki_pages', $pageid);
        foreach ($tags as $tagid => $tagvalue) {
            tag_delete_instance('wiki_pages', $pageid, $tagid);
        }
        //Delete Synonym
        wiki_delete_synonym($subwikiid, $pageid);
        //Delete all page versions
        wiki_delete_page_versions(array($pageid => array(0)));
        //Delete all page locks
        wiki_delete_locks($pageid);
        //Delete all page links
        wiki_delete_links(null, $pageid);
        //Delete page
        $params = array('id' => $pageid);
        $DB->delete_records('wiki_pages', $params);
    }
}
コード例 #2
0
ファイル: pagelib.php プロジェクト: Burick/moodle
    private function delete_comment($commentid) {
        global $CFG, $PAGE;

        $pageid = $this->page->id;

        wiki_delete_comment($commentid, $this->modcontext, $pageid);
    }
コード例 #3
0
ファイル: events_test.php プロジェクト: evltuma/moodle
 /**
  * Test comment_deleted event.
  */
 public function test_comment_deleted()
 {
     $this->setUp();
     $page = $this->wikigenerator->create_first_page($this->wiki);
     $context = context_module::instance($this->wiki->cmid);
     // Add comment so we can delete it later.
     wiki_add_comment($context, $page->id, 'Test comment', 'html');
     $comment = wiki_get_comments($context->id, $page->id);
     $this->assertCount(1, $comment);
     $comment = array_shift($comment);
     // Triggering and capturing the event.
     $sink = $this->redirectEvents();
     wiki_delete_comment($comment->id, $context, $page->id);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_wiki\\event\\comment_deleted', $event);
     $this->assertEquals($context, $event->get_context());
     $this->assertEquals($page->id, $event->other['itemid']);
     $this->assertEventContextNotUsed($event);
 }
コード例 #4
0
ファイル: locallib.php プロジェクト: isuruAb/moodle
/**
 * Delete pages and all related data
 *
 * @param mixed $context context in which page needs to be deleted.
 * @param mixed $pageids id's of pages to be deleted
 * @param int $subwikiid id of the subwiki for which all pages should be deleted
 */
function wiki_delete_pages($context, $pageids = null, $subwikiid = null)
{
    global $DB, $CFG;
    if (!empty($pageids) && is_int($pageids)) {
        $pageids = array($pageids);
    } else {
        if (!empty($subwikiid)) {
            $pageids = wiki_get_page_list($subwikiid);
        }
    }
    //If there is no pageid then return as we can't delete anything.
    if (empty($pageids)) {
        return;
    }
    /// Delete page and all it's relevent data
    foreach ($pageids as $pageid) {
        if (is_object($pageid)) {
            $pageid = $pageid->id;
        }
        //Delete page comments
        $comments = wiki_get_comments($context->id, $pageid);
        foreach ($comments as $commentid => $commentvalue) {
            wiki_delete_comment($commentid, $context, $pageid);
        }
        //Delete page tags
        core_tag_tag::remove_all_item_tags('mod_wiki', 'wiki_pages', $pageid);
        //Delete Synonym
        wiki_delete_synonym($subwikiid, $pageid);
        //Delete all page versions
        wiki_delete_page_versions(array($pageid => array(0)), $context);
        //Delete all page locks
        wiki_delete_locks($pageid);
        //Delete all page links
        wiki_delete_links(null, $pageid);
        $params = array('id' => $pageid);
        // Get page before deleting.
        $page = $DB->get_record('wiki_pages', $params);
        //Delete page
        $DB->delete_records('wiki_pages', $params);
        // Trigger page_deleted event.
        $event = \mod_wiki\event\page_deleted::create(array('context' => $context, 'objectid' => $pageid, 'other' => array('subwikiid' => $subwikiid)));
        $event->add_record_snapshot('wiki_pages', $page);
        $event->trigger();
    }
}
コード例 #5
0
ファイル: pagelib.php プロジェクト: nuckey/moodle
    private function delete_comment($commentid) {
        global $CFG, $PAGE;

        $cm = $PAGE->cm;
        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
        $pageid = $this->page->id;

        wiki_delete_comment($commentid, $context, $pageid);
    }