Edit a page contents.

@param int $pageid The page ID.
@param string $content Page contents.
@param int $section Section to be edited.
@return array of warnings and page data.
@since Moodle 3.1
173252
public static function edit_page($pageid, $content, $section = null) {
        global $USER;

        $params = self::validate_parameters(self::edit_page_parameters(),
                                            array(
                                                'pageid' => $pageid,
                                                'content' => $content,
                                                'section' => $section
                                            )
            );
        $warnings = array();

        // Get wiki page.
        if (!$page = wiki_get_page($params['pageid'])) {
            throw new moodle_exception('incorrectpageid', 'wiki');
        }

        // Get wiki instance.
        if (!$wiki = wiki_get_wiki_from_pageid($params['pageid'])) {
            throw new moodle_exception('incorrectwikiid', 'wiki');
        }

        // Get subwiki instance.
        if (!$subwiki = wiki_get_subwiki($page->subwikiid)) {
            throw new moodle_exception('incorrectsubwikiid', 'wiki');
        }

        // Permission validation.
        $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course);
        $context = context_module::instance($cm->id);
        self::validate_context($context);

        if (!wiki_user_can_edit($subwiki)) {
            throw new moodle_exception('cannoteditpage', 'wiki');
        }

        if (wiki_is_page_section_locked($page->id, $USER->id, $params['section'])) {
            throw new moodle_exception('pageislocked', 'wiki');
        }

        // Save content.
        if (!is_null($params['section'])) {
            $version = wiki_get_current_version($page->id);
            $content = wiki_parser_proxy::get_section($version->content, $version->contentformat, $params['section'], false);
            if (!$content) {
                throw new moodle_exception('invalidsection', 'wiki');
            }

            $save = wiki_save_section($page, $params['section'], $params['content'], $USER->id);
        } else {
            $save = wiki_save_page($page, $params['content'], $USER->id);
        }

        wiki_delete_locks($page->id, $USER->id, $params['section']);

        if (!$save) {
            throw new moodle_exception('savingerror', 'wiki');
        }

        $result = array();
        $result['pageid'] = $page->id;
        $result['warnings'] = $warnings;
        return $result;
    }
426968
public function updateTemplateSections($id, $sections)
    {
        /** @var $entity \PageBuilder\Entity\Template */
        if ($entity = $this->findObject($id)) {

            /** @var $ts \PageBuilder\Entity\Join\TemplateSection */
            foreach ($entity->getTemplateSections() as $ts) {
                $ts->setIsActive(0);
            }
            if ($ts = $entity->getTemplateSections()) {
                $entity->getTemplateSections()->clear();
            } else {
                $entity->setTemplateSections(new ArrayCollection());
            }
        }

        foreach ($sections as $key => $v) {
            $order = $key;
            if ($entry = $this->getEntityManager()->getRepository('PageBuilder\Entity\Join\TemplateSection')
                ->findOneBy(['templateId' => $id, 'sectionId' => $v])
            ) {
                $entry->setSortOrder($order);
                $entry->setIsActive(1);
            } elseif ($section = $this->getEntityManager()->getRepository('PageBuilder\Entity\Section')->find($v)
            ) {
                $entry = new TemplateSection();
                $entry->setSectionId($section);
                $entry->setTemplateId($entity);
                $entry->setSortOrder($order);
                $entry->setIsActive(1);
            }
            $entity->getTemplateSections()->add($entry);
        }

        return $this->save($entity);
    }
215769
public function findPageUidsWithContentsFromPid(int $pageId) : array
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder->getRestrictions()->removeAll();
        $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));

        $queryBuilder
            ->select('uid')
            ->from($this->table)
            ->add('where',
                $queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT))
            );

        $this->addDefaultLanguageUidConstraint($queryBuilder);

        return $queryBuilder->execute()->fetchAll();
    }
1348846
public function update(Page $page, PageContent $content)
    {
        if (is_null(request()->file('media'))) {
            $attributes = request()->validate(array_except(PageContent::$rules, 'media'),
                PageContent::$messages);
        }
        else {
            $attributes = request()->validate(PageContent::$rules, PageContent::$messages);

            $media = $this->moveAndCreatePhoto($attributes['media']);
            if ($media) {
                $attributes['media'] = $media;
            }
        }

        unset($attributes['page_id']);
        $item = $this->updateEntry($content, $attributes);

        return redirect_to_resource();
    }
666743
public function updateContent($content)
    {
        $sections = Eresus_CMS::getLegacyKernel()->sections;
        $item = $sections->get(Eresus_Kernel::app()->getPage()->id);
        $section = new Html_SiteSection($item);
        $section->setContent($content);
        $section->setOption('disallowGET', !arg('allowGET', 'int'));
        $section->setOption('disallowPOST', !arg('allowPOST', 'int'));
        $section->setOption('html.rel_canonical', arg('canonical', 'int'));

        if ($this->settings['notes'])
        {
            $notes = arg('notes');
            if (!is_null($notes))
            {
                $section->setNotes($notes);
            }
        }

        $sections->update($section->toArray());
    }
242953
public static function getChildPageIds($pageId)
    {
        if (empty(self::$preloaded_page_children)) {
            foreach (static::preloadArray() as $key => $page) {
                if (!isset(self::$preloaded_page_children[$page->parent])) {
                    self::$preloaded_page_children[$page->parent] = [];
                }
                self::$preloaded_page_children[$page->parent][] = $page->id;
            }
        }
        return !empty(self::$preloaded_page_children[$pageId]) ? self::$preloaded_page_children[$pageId] : [];
    }
1370572
private function getSectionId($locationId)
    {
        $location = $this->load($locationId);
        $locationContentInfo = $this->contentHandler->loadContentInfo($location->contentId);

        return $locationContentInfo->sectionId;
    }
735529
public function getPageContent($pageId)
    {
        // Retrieve cache version if front mode to avoid multiple calls
        $melisEngineCacheSystem = $this->getServiceLocator()->get('MelisEngineCacheSystem');
        $pageContent = $melisEngineCacheSystem->getCacheByKey($this->cachekey.$pageId, $this->cacheConfig, true);
        
        return $pageContent;
    }
1090852
private function updatePageLevel($sectionUid, $level)
    {
        $page_repo = $this->getEntityManager()
                ->getRepository('BackBee\NestedNode\Page');

        $page_repo->createQueryBuilder('p')
                ->update()
                ->set('p._level', $level)
                ->where('p._uid = :uid')
                ->setParameter('uid', $sectionUid)
                ->getQuery()
                ->execute();

        $page_repo->createQueryBuilder('p')
                ->update()
                ->set('p._level', $level + 1)
                ->where('p._section = :uid')
                ->andWhere('p._uid <> :uid')
                ->setParameter('uid', $sectionUid)
                ->getQuery()
                ->execute();

        return $this;
    }
1082886
public function updateContent($content)
    {
        $db = Eresus_CMS::getLegacyKernel()->db;
        $item = $db->selectItem('pages', "`id`='".Eresus_Kernel::app()->getPage()->id."'");
        $item['content'] = $content;
        $db->updateItem('pages', $item, "`id`='".Eresus_Kernel::app()->getPage()->id."'");
    }
166534
public static function edit_section($action, $id, $sectionreturn) {
        global $DB;
        // Validate and normalize parameters.
        $params = self::validate_parameters(self::edit_section_parameters(),
            array('action' => $action, 'id' => $id, 'sectionreturn' => $sectionreturn));
        $action = $params['action'];
        $id = $params['id'];
        $sr = $params['sectionreturn'];

        $section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
        $coursecontext = context_course::instance($section->course);
        self::validate_context($coursecontext);

        $rv = course_get_format($section->course)->section_action($section, $action, $sectionreturn);
        if ($rv) {
            return json_encode($rv);
        } else {
            return null;
        }
    }
944341
private function updateContentSetElements(ContentSet $content, array $elementsData, Page $page = null)
    {
        $content->clear();
        foreach ($elementsData as $data) {
            if ($data instanceof AbstractClassContent) {
                if (null !== $page && null === $data->getMainNode()) {
                    $data->setMainNode($page);
                }
                $content->push($data);
            }
        }

        return $this;
    }
716109
public function setItem($cacheId, $content)
    {
        $cacheId = $this->normalizeKey($cacheId);

        return $this->cache->save($cacheId, serialize($content));
    }
1129360
protected function _replaceSection( $content, $section, $marker )
	{
		$marker = '<!-- ' . $marker . ' -->';
		$start = strpos( $content, $marker );

		if( $start !== false && ( $end = $end = strpos( $content, $marker, $start+1 ) ) !== false ) {
			return substr_replace( $content, $section, $start, $end - $start + strlen( $marker) );
		}

		return $content;
	}
121863
public function startSection($section, $content = '')
    {
        if (! empty($content)) {
            $this->extendSection($section, $content);
        } else if (ob_start()) {
            $this->sectionStack[] = $section;
        }
    }
650669
static function ContentTreeUrl(Content $content)
    {
        $args = array();
        $pageContent = $content->GetPageContent();
        if ($pageContent)
        {
            $args['page'] = $pageContent->GetPage()->GetID();
            $args['area'] = $pageContent->GetArea()->GetID();
            return self::ModuleUrl(new \Phine\Bundles\Core\Modules\Backend\PageContentTree, $args);
        }
        $layoutContent = $content->GetLayoutContent();
        if ($layoutContent)
        {
            $args['area'] = $layoutContent->GetArea()->GetID();
            return self::ModuleUrl(new \Phine\Bundles\Core\Modules\Backend\LayoutContentTree, $args);
        }
        $containerContent = $content->GetContainerContent();
        if($containerContent)
        {
            $args['container'] = $containerContent->GetContainer()->GetID();
            return self::ModuleUrl(new \Phine\Bundles\Core\Modules\Backend\ContainerContentTree, $args);
        }
    }
372749
public function openSection($id = null)
    {
        $current = end($this->activeSections);

        if (null !== $id && null === $current->get($id)) {
            throw new \LogicException(sprintf('The section "%s" has been started at an other level and can not be opened.', $id));
        }

        $this->start('__section__.child', 'section');
        $this->activeSections[] = $current->open($id);
        $this->start('__section__');
    }