TS3AudioBot Control Panel Modules Developer Guide

TS3AudioBot Panel


Introduction

This product need a certain level of technical expertise. If you don't know what you are doing, you might break the System and cause bad things to happen.

Example

If you have a certain level of PHP knowledge, you can checkout this Example Module that is always up to date to fit the module system. It gives you a small module to show off all features and provides a solid base for module development.

GitHub Base Module Example

Routes


Routes are an essential part of your module if you want to add one or more new pages.

They are defined in your baseclass (ExampleModule.php) inside the routes() function. The first parameter in the array is the route that you want to use for that site. The second is the class and function that will take care of the rendering itself. This is most likely bound to your functionality, so if you want to create a module to add a page that shows you imprint this may be something like ExampleModule\Controllers\Imprint::renderImprint. The third paramtere gives you the abillity to transfer variables to the function without using them in a static context as function parameters. This is helpfull if you want to implement, for example an invoicing system, and you want to display the user an invoice with an ID that you have to load from the database. Then you may have some route like /invoice/:id and you parameter array would be something like ["id" => "\d+"] which matches all integers provided in the URL at that position. The last parameter is for the request type. Since you most of the time will use GET to display pages, this parameter defaults to GET. A complex route for registering a user might look like this: array("/register/:id", "ExampleModule\Controllers\Register::newUser", ["id" => "\d+"], "POST"). This will allow post-requests to /register/:id where id is any integer.

Now that we have our route setup correctly, we can have a look inside of the function that we call when someone visits our defined URL.

This also is on GitHub.

Here we have our function with the parameter which is transfered by the Engine itself. It contains our Engine-class which we need to render anything to the user.
In order to allow Interceptors to catch the render-process and possibly add content to the Page, we need to call the Panel::render($engine->compile(...)) method. This will render the page to the user after checking if there are any interceptors on that route that need to be executed. We only use compile from the engine because it returns a string which is then renders by the Panel class.

                                        Panel::render($engine->compile("_views/" . THEME . "/examplefile.html", array(
                                            "parameters" => "test parameter to render into the template"
                                        )));
                                    

The first parameter of the compile function is the file which gets opened and compiled by the engine. THEME is a constanct which contains the name of the theme currently in use. If you want to render the page, make sure it exists in the folder.

The second parameter is an array of arguments which may contain data you want to display on your page. Maybe some data from the invoice you want to display if we stick with the example from above. This will be further documented in the Templating Engine section.

Interceptors


coming soon

Database


We have a util class which can be used for easy database access.

you can import it with $db = Panel::getDatabase(); and use the following functions to get or update data.

See all function in the class which is used: GitHub

Template Engine


The templating engine is used by the Panel to render contents from the backend into the frontend and then displaying it to the user.

The basic functionality will be extended in the documentation, but for now you can have a look at the class that the panel uses.

Syntax.php on GitHub.