Create instance of event.

@param \lesson_page $lessonpage
@param \context_module $context
@return page_updated
334947
public static function create_from_lesson_page(\lesson_page $lessonpage, \context_module $context) {
        $data = array(
            'context' => $context,
            'objectid' => $lessonpage->properties()->id,
            'other' => array(
                'pagetype' => $lessonpage->get_typestring()
            )
        );
        return self::create($data);
    }
1023214
public function setPagination($currentPage, $perPage = null)
    {

        $this->currentPageNumber = $this->isValidPageNumber($currentPage) ? $currentPage : 1;
        $defaultPerPage = $this->perPage ? $this->perPage : static::$perPageDefault;
        $this->perPage = $perPage ?: $defaultPerPage;
        $this->pages = null;
        return $this;
    }
731552
public static function create(
        string $queryText,
        int $page = self::DEFAULT_PAGE,
        int $size = self::DEFAULT_SIZE
    ): self {
        $page = (int) (max(1, $page));
        $query = new self($queryText);
        $query->from = ($page - 1) * $size;
        $query->size = $size;
        $query->page = $page;

        return $query;
    }
119616
public static function create_from_chapter(\stdClass $book, \context_module $context, \stdClass $chapter) {
        $data = array(
            'context' => $context,
            'objectid' => $chapter->id,
        );
        /** @var chapter_printed $event */
        $event = self::create($data);
        $event->add_record_snapshot('book', $book);
        $event->add_record_snapshot('book_chapters', $chapter);
        return $event;
    }
661941
private static function getInstanceForPage(TdbCmsTplPage $page, $baseQuery)
    {
        /** @var CacheInterface $cache */
        $cache = \ChameleonSystem\CoreBundle\ServiceLocator::get('chameleon_system_core.cache');

        $cacheKey = $cache->getKey(array(
            'class' => __CLASS__,
            'method' => 'getInstanceForPage',
            'pageId' => $page->id,
        ));
        $instance = $cache->get($cacheKey);
        if (null === $instance) {
            $instance = false;

            $query = "SELECT pkg_shop_listfilter_module_config.*
                    FROM cms_tpl_module_instance
              INNER JOIN cms_tpl_module ON cms_tpl_module_instance.cms_tpl_module_id = cms_tpl_module.id
              INNER JOIN cms_tpl_page_cms_master_pagedef_spot ON cms_tpl_module_instance.id = cms_tpl_page_cms_master_pagedef_spot.cms_tpl_module_instance_id
              INNER JOIN pkg_shop_listfilter_module_config ON cms_tpl_module_instance.id = pkg_shop_listfilter_module_config.cms_tpl_module_instance_id
                   WHERE cms_tpl_page_cms_master_pagedef_spot.cms_tpl_page_id = '{$page->id}'
                     AND pkg_shop_listfilter_module_config.pkg_shop_listfilter_id != ''

        ";

            // we are looking for a module that has a listfilter set. in the future we might change this to a more robust way of identifying the right module. (eg. via generic meta data)
            $filterConfig = MySqlLegacySupport::getInstance()->fetch_assoc(MySqlLegacySupport::getInstance()->query($query));
            if ($filterConfig) {
                $instance = TdbPkgShopListfilter::GetNewInstance($filterConfig['pkg_shop_listfilter_id']);
                if ('' !== $filterConfig['filter_parameter']) {
                    $instance->setStaticFilter($filterConfig['filter_parameter']);
                }
            }

            $cache->set($cacheKey, $instance, array(array('table' => 'shop', 'id' => null), array('table' => 'cms_tpl_page', 'id' => $page->id), array('table' => 'pkg_shop_listfilter', 'id' => null)));
        }

        if (false === $instance) { // check if the category sets a filter
            $instance = null;
            /** @var $shopService \ChameleonSystem\ShopBundle\Interfaces\ShopServiceInterface */
            $shopService = \ChameleonSystem\CoreBundle\ServiceLocator::get('chameleon_system_shop.shop_service');
            $activeCategory = $shopService->getActiveCategory();
            if (null !== $activeCategory) {
                $instance = self::getInstanceForCategory($activeCategory, $shopService->getActiveShop());
            }
        }

        if (null === $instance) {
            $instance = TdbPkgShopListfilter::GetNewInstance(TdbShop::GetInstance()->fieldPkgShopListfilterPostsearchId);
        }

        $instance->pushStaticFilterToRequest();

        $instance->setArticleListQuery($baseQuery);

        return $instance;
    }
1293893
public function render_preview(moodle_page $page) {

        if (!$this->is_form_defined()) {
            throw new coding_exception('It is the caller\'s responsibility to make sure that the form is actually defined');
        }

        $criteria = $this->definition->rubric_criteria;
        $options = $this->get_options();
        $rubric = '';
        if (has_capability('moodle/grade:managegradingforms', $page->context)) {
            $showdescription = true;
        } else {
            if (empty($options['alwaysshowdefinition']))  {
                // ensure we don't display unless show rubric option enabled
                return '';
            }
            $showdescription = $options['showdescriptionstudent'];
        }
        $output = $this->get_renderer($page);
        if ($showdescription) {
            $rubric .= $output->box($this->get_formatted_description(), 'gradingform_rubric-description');
        }
        if (has_capability('moodle/grade:managegradingforms', $page->context)) {
            if (!$options['lockzeropoints']) {
                // Warn about using grade calculation method where minimum number of points is flexible.
                $rubric .= $output->display_rubric_mapping_explained($this->get_min_max_score());
            }
            $rubric .= $output->display_rubric($criteria, $options, self::DISPLAY_PREVIEW, 'rubric');
        } else {
            $rubric .= $output->display_rubric($criteria, $options, self::DISPLAY_PREVIEW_GRADED, 'rubric');
        }

        return $rubric;
    }
632081
public function display_edit_full(lesson $lesson, $pageid, $prevpageid, $single=false) {
        global $DB, $CFG;

        $manager = lesson_page_type_manager::get($lesson);
        $qtypes = $manager->get_page_type_strings();
        $npages = count($lesson->load_all_pages());
        $canedit = has_capability('mod/lesson:edit', context_module::instance($this->page->cm->id));

        $content = '';
        if ($canedit) {
            $content = $this->add_page_links($lesson, $prevpageid);
        }

        $options = new stdClass;
        $options->noclean = true;

        while ($pageid != 0 && $single!=='stop') {
            $page = $lesson->load_page($pageid);

            $pagetable = new html_table();
            $pagetable->align = array('right','left');
            $pagetable->width = '100%';
            $pagetable->tablealign = 'center';
            $pagetable->cellspacing = 0;
            $pagetable->cellpadding = '5px';
            $pagetable->data = array();

            $pageheading = new html_table_cell();

            $pageheading->text = html_writer::tag('a', '', array('id' => 'lesson-' . $pageid)) . format_string($page->title);
            if ($canedit) {
                $pageheading->text .= ' '.$this->page_action_links($page, $npages);
            }
            $pageheading->style = 'text-align:center';
            $pageheading->colspan = 2;
            $pageheading->scope = 'col';
            $pagetable->head = array($pageheading);

            $cell = new html_table_cell();
            $cell->colspan = 2;
            $cell->style = 'text-align:left';
            $cell->text = $page->contents;
            $pagetable->data[] = new html_table_row(array($cell));

            $cell = new html_table_cell();
            $cell->colspan = 2;
            $cell->style = 'text-align:center';
            $cell->text = '<strong>'.$qtypes[$page->qtype] . $page->option_description_string().'</strong>';
            $pagetable->data[] = new html_table_row(array($cell));

            $pagetable = $page->display_answers($pagetable);

            $content .= html_writer::start_tag('div');
            $content .= html_writer::table($pagetable);
            $content .= html_writer::end_tag('div');

            if ($canedit) {
                $content .= $this->add_page_links($lesson, $pageid);
            }

            // check the prev links - fix (silently) if necessary - there was a bug in
            // versions 1 and 2 when add new pages. Not serious then as the backwards
            // links were not used in those versions
            if ($page->prevpageid != $prevpageid) {
                // fix it
                $DB->set_field("lesson_pages", "prevpageid", $prevpageid, array("id" => $page->id));
                debugging("<p>***prevpageid of page $page->id set to $prevpageid***");
            }

            $prevpageid = $page->id;
            $pageid = $page->nextpageid;

            if ($single === true) {
                $single = 'stop';
            }

        }

        return $this->output->box($content, 'edit_pages_box');
    }
116949
public function setModelPage(\Haven\CmsBundle\Entity\TemplatePage $modelPage = null) {
        $this->model_page = $modelPage;

        return $this;
    }
233824
public function showAction(ErrorPage $page)
    {
        //add the view to twig
        $this->container->get('twig')->addGlobal('view', $page);
        $page->setReference(new ViewReference($page->getId()));
        $parameters = [
            'view'   => $page,
            'id'     => $page->getId(),
            'locale' => $page->getCurrentLocale(),
        ];

        $this->get('victoire_widget_map.builder')->build($page);
        $this->get('victoire_widget_map.widget_data_warmer')->warm(
            $this->get('doctrine.orm.entity_manager'),
            $page
        );

        $this->container->get('victoire_core.current_view')->setCurrentView($page);

        //create the response
        $response = $this->container->get('templating')->renderResponse(
            'VictoireCoreBundle:Layout:'.$page->getTemplate()->getLayout().'.html.twig',
            $parameters
        );

        return $response;
    }
756716
protected function createCreateForm(Page $page)
    {
        $channel = $this->getSelectedChannel();

        $form = $this->createForm(
            PageType::class,
            $page,
            [
                'action' => $this->generateUrl('integrated_page_page_new', ['channel' => $channel->getId()]),
                'method' => 'POST',
                'theme'  => $this->getTheme($channel),
            ]
        );

        $form->add('actions', SaveCancelType::class, [
            'cancel_route' => 'integrated_page_page_index',
            'cancel_route_parameters' => ['channel' => $this->getSelectedChannel()->getId()],
            'label' => 'Create',
            'button_class' => '',
        ]);

        return $form;
    }
761959
public static function init(moodle_page $page = null) {
        global $PAGE;

        if (empty($page)) {
            $page = $PAGE;
        }
        // setup variables for non-js interface
        self::$nonjs = optional_param('nonjscomment', '', PARAM_ALPHANUM);
        self::$comment_itemid = optional_param('comment_itemid',  '', PARAM_INT);
        self::$comment_component = optional_param('comment_component', '', PARAM_COMPONENT);
        self::$comment_context = optional_param('comment_context', '', PARAM_INT);
        self::$comment_page = optional_param('comment_page',    '', PARAM_INT);
        self::$comment_area = optional_param('comment_area',    '', PARAM_AREA);

        $page->requires->strings_for_js(array(
                'addcomment',
                'comments',
                'commentscount',
                'commentsrequirelogin',
                'deletecommentbyon'
            ),
            'moodle'
        );
    }
1191837
protected static function get_page_fields(lesson_page $page, $returncontents = false) {
        $lesson = $page->lesson;
        $context = $lesson->context;

        $pagedata = new stdClass; // Contains the data that will be returned by the WS.

        // Return the visible data.
        $visibleproperties = array('id', 'lessonid', 'prevpageid', 'nextpageid', 'qtype', 'qoption', 'layout', 'display',
                                    'displayinmenublock', 'type', 'typeid', 'typestring', 'timecreated', 'timemodified');
        foreach ($visibleproperties as $prop) {
            $pagedata->{$prop} = $page->{$prop};
        }

        // Check if we can see title (contents required custom rendering, we won't returning it here @see get_page_data).
        $canmanage = $lesson->can_manage();
        // If we are managers or the menu block is enabled and is a content page visible always return contents.
        if ($returncontents || $canmanage || (lesson_displayleftif($lesson) && $page->displayinmenublock && $page->display)) {
            $pagedata->title = external_format_string($page->title, $context->id);

            $options = array('noclean' => true);
            list($pagedata->contents, $pagedata->contentsformat) =
                external_format_text($page->contents, $page->contentsformat, $context->id, 'mod_lesson', 'page_contents', $page->id,
                    $options);

        }
        return $pagedata;
    }
828933
public static function data_for_template_competencies_page($templateid, $pagecontext) {
        global $PAGE;
        $params = self::validate_parameters(self::data_for_template_competencies_page_parameters(), array(
            'templateid' => $templateid,
            'pagecontext' => $pagecontext
        ));

        $context = self::get_context_from_params($params['pagecontext']);
        self::validate_context($context);

        $template = api::read_template($params['templateid']);
        $renderable = new output\template_competencies_page($template, $context);
        $renderer = $PAGE->get_renderer('tool_lp');

        $data = $renderable->export_for_template($renderer);

        return $data;
    }
1113428
public function withPageAndPerPage($page, $perPage)
    {
        $new = clone $this;
        $new->offset = ($page - 1) * $perPage;
        $new->limit = $perPage;
        $new->paginationType = self::PAGED_PAGINATION;

        return $new;
    }
21430
public static function data_for_competency_frameworks_manage_page($pagecontext) {
        global $PAGE;

        $params = self::validate_parameters(
            self::data_for_competency_frameworks_manage_page_parameters(),
            array(
                'pagecontext' => $pagecontext
            )
        );
        $context = self::get_context_from_params($params['pagecontext']);
        self::validate_context($context);

        $renderable = new output\manage_competency_frameworks_page($context);
        $renderer = $PAGE->get_renderer('tool_lp');

        $data = $renderable->export_for_template($renderer);

        return $data;
    }
304308
public function update($properties, $context = null, $maxbytes = null) {
        global $DB, $PAGE;
        $answers  = $this->get_answers();
        $properties->id = $this->properties->id;
        $properties->lessonid = $this->lesson->id;
        $properties->timemodified = time();
        $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
        $DB->update_record("lesson_pages", $properties);

        // Trigger an event: page updated.
        \mod_lesson\event\page_updated::create_from_lesson_page($this, $context)->trigger();

        // need to reset offset for correct and wrong responses
        $this->lesson->maxanswers = 2;
        for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
            if (!array_key_exists($i, $this->answers)) {
                $this->answers[$i] = new stdClass;
                $this->answers[$i]->lessonid = $this->lesson->id;
                $this->answers[$i]->pageid = $this->id;
                $this->answers[$i]->timecreated = $this->timecreated;
            }

            if (!empty($properties->answer_editor[$i]) && is_array($properties->answer_editor[$i])) {
                $this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
                $this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
            }

            if (!empty($properties->response_editor[$i]) && is_array($properties->response_editor[$i])) {
                $this->answers[$i]->response = $properties->response_editor[$i]['text'];
                $this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
            }

            // we don't need to check for isset here because properties called it's own isset method.
            if ($this->answers[$i]->answer != '') {
                if (isset($properties->jumpto[$i])) {
                    $this->answers[$i]->jumpto = $properties->jumpto[$i];
                }
                if ($this->lesson->custom && isset($properties->score[$i])) {
                    $this->answers[$i]->score = $properties->score[$i];
                }
                if (!isset($this->answers[$i]->id)) {
                    $this->answers[$i]->id =  $DB->insert_record("lesson_answers", $this->answers[$i]);
                } else {
                    $DB->update_record("lesson_answers", $this->answers[$i]->properties());
                }
                // Save files in answers and responses.
                $this->save_answers_files($context, $maxbytes, $this->answers[$i],
                        $properties->answer_editor[$i], $properties->response_editor[$i]);
            } else if (isset($this->answers[$i]->id)) {
                $DB->delete_records('lesson_answers', array('id'=>$this->answers[$i]->id));
                unset($this->answers[$i]);
            }
        }
        return true;
    }
700471
public function getRendererTemplateForPage(ContentPage $contentPage)
    {
        if (null !== $contentPage->getContentTypeId())
        {
            return $contentPage->getContentType()->getTemplateName();
        }

        return $this->defaultRendererTemplate;
    }