public function definition()
 {
     $mform = $this->_form;
     // Don't forget the underscore!
     if (isset($this->_customdata['catalog_id']) && is_object($this->_customdata['catalog_id'])) {
         $catalog_id = $this->_customdata['catalog_id'];
     }
     $mform->addElement('select', 'page_id', get_string('page'), local_catalog_get_pages(false), array('style' => 'width: 100%'));
     $mform->addRule('page_id', get_string('required'), 'required', null, 'client');
     $this->add_action_buttons();
 }
    $data->url = new moodle_url($returnurl);
    $data->sesskey = sesskey();
    $data->deleteicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall'));
    $data->editicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall'));
    $metaform = new local_catalog_metadata(new moodle_url($returnurl, array('action' => $addmeta)));
    $data->metadata = local_catalog_get_metadata_categories();
    if (count($data->metadata) > 0) {
        $data->has_metadata = true;
    }
    foreach ($data->metadata as $key => $elem) {
        if ($elem['count'] == "0") {
            $data->metadata[$key]['candelete'] = "true";
        }
    }
    $data->metaform = $metaform->render();
    $data->pages = local_catalog_get_pages();
    if (count($data->pages) > 0) {
        $data->has_pages = true;
    }
    foreach ($data->pages as $key => $elem) {
        if ($elem['count'] == "0") {
            $data->pages[$key]['candelete'] = "true";
        }
    }
    $template_form = new local_catalog_pages(new moodle_url($returnurl, array('action' => $addpages)));
    $data->template_form = $template_form->render();
    $data->header = $OUTPUT->header();
    $data->heading = $OUTPUT->heading(get_string('catalogsetup', 'local_catalog'));
    $data->footer = $OUTPUT->footer();
    echo $OUTPUT->render_from_template('local_catalog/setup', $data);
}
function local_catalog_get_course_pages($catalog_id)
{
    global $DB;
    $list = local_catalog_get_pages(true, "id");
    $records = $DB->get_records('local_catalog_course_pages', array('catalog_id' => $catalog_id), 'sequence');
    $pages = array();
    $i = 0;
    foreach ($records as $r) {
        $pages[$i]['id'] = $r->id;
        $pages[$i]['page_id'] = $r->page_id;
        $pages[$i]['name'] = $list[$r->page_id]['name'];
        $pages[$i]['fa_icon'] = $list[$r->page_id]['fa_icon'];
        if ($r->use_template == 1) {
            $pages[$i]['use_template'] = true;
            $pages[$i]['content'] = $list[$r->page_id]['template'];
        } else {
            $pages[$i]['use_template'] = false;
            $pages[$i]['content'] = $r->content;
        }
        $i++;
    }
    return $pages;
}