Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+6 votes
835 views
in Q2A Core by
Hello,

 

I need new page for Admin section which is list all Answers and comments. How can add new page for Admin section any idea?
by
I also have similar need. Did you have any idea?
by
I will be grateful, If i know about this?

1 Answer

+4 votes
by
edited by

You can create admin page with your plugin.

For example ... (This is similar to "example page" plugin)

1. Create folder (e.g. example-admin-page) under qa-plugin

2. Create metadata.json under qa-plugin/example-admin-page/

{
    "name": "Example admin page",
    "description": "Example of a admin page plugin",
    "version": "1.0",
    "date": "2017-03-22",
    "author": "PowerQA",
    "author_uri": "http://www.powerqa.org",
    "license": "GPLv2",
    "min_q2a": "1.5"
}

3. Create qa-plugin.php under qa-plugin/example-admin-page/

<?php
if (!defined('QA_VERSION')) {
    header('Location: ../../');
    exit;
}
qa_register_plugin_overrides('qa-example-admin-page-overrides.php');
qa_register_plugin_module('page', 'qa-example-admin-page.php', 'qa_example_admin_page', 'Example Admin Page');

4. Create qa-example-admin-page-overrides.php under qa-plugin/example-admin-page/

<?php
if (!defined('QA_VERSION')) {
    header('Location: ../../');
    exit;
}
function qa_admin_sub_navigation() {
    $navigation = qa_admin_sub_navigation_base();
    if(qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
        $navigation['example-admin-page'] = array(
            'label' => 'Example of admin page',
            'url' => qa_path('admin/example-admin-page'),
            'selected' => (qa_request_part(1) == 'example-admin-page')? true : null,
        );
    }
    return $navigation;
}

5. Create qa-example-admin-page.php under qa-plugin/example-admin-page/

<?php
if (!defined('QA_VERSION')) {
    header('Location: ../../');
    exit;
}
require_once QA_INCLUDE_DIR.'app/admin.php';
class qa_example_admin_page {
    private $directory;
    private $urltoroot;

    public function load_module($directory, $urltoroot) {
        $this->directory=$directory;
        $this->urltoroot=$urltoroot;
    }
    public function match_request($request) {
        if(qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN)
            return $request == 'admin/example-admin-page';
        else
            return false;
    }
    public function process_request($request) {
        $qa_content=qa_content_prepare();
        $qa_content['title']='Amin page title';
        $qa_content['error']='An example error';
        $qa_content['custom']='Some <b>custom html</b>';
        $qa_content['form']=array(
            'tags' => 'method="post" action="'.qa_self_html().'"',
            'style' => 'wide',
            'ok' => qa_post_text('okthen') ? 'You clicked OK then!' : null,
            'title' => 'Form title',
            'fields' => array(
                'request' => array(
                    'label' => 'The request',
                    'tags' => 'name="request"',
                    'value' => qa_html($request),
                    'error' => qa_html('Another error'),
                ),
            ),
            'buttons' => array(
                'ok' => array(
                    'tags' => 'name="okthen"',
                    'label' => 'OK then',
                    'value' => '1',
                ),
            ),
            'hidden' => array(
                'hiddenfield' => '1',
            ),
        );
        $qa_content['custom_2']='<p><br>More <i>custom html</i></p>';
        $qa_content['navigation']['sub']=qa_admin_sub_navigation();
        return $qa_content;
    }
}

...