## Preparation

1. Install TAO (3.0) with the development tools (https://github.com/oat-sa/extension-tao-devtools)
2. Make sure the extension taoDevTools has been installed.

## Create the extension

2. Go to “Settings”(upper right corner) -> “Extensions Manager”
3. Click on “create new” to create your new extension
4. Fill out the form and call your new extension “taoDocs” ( you can select some Samples to generate extra structure, according to your choice )

## Hello World

• Create the TestController.php in the controller folder

• Create the sayHello() method
<?php

namespace oat\taoDocs\controller;

class TestController extends \tao_actions_CommonModule
{
public function sayHello()
{
echo 'Hello World';
}
}
• To run the action visit ROOT_URL/taoDocs/TestController/sayHello (if your TAO Home is http://localhost/myinstall/tao/Main/index this would translate to http://localhost/myinstall/taoDocs/TestController/sayHello). If you get an “Access Denied” instead of the expected Hello world message, make sure you properly set up the extension in TAO as described in the preparation step of this tutorial here above. Make sure, www-data may fully access the files on the file system of your extension.

### Hello Template

• Create the hello.tpl file in views/templates
Hello <?=get_data('name')?>
• Update the sayHello() method to define the template and the parameter
public function sayHello()
{
$this->setData('name', 'bertrand');$this->setView('hello.tpl');
}
• To test this action visit URL:/taoDocs/TestController/sayHello

### Hello Parameter

• Update the sayHello() method to use the GET parameter “name”
public function sayHello()
{
if ($this->hasRequestParameter('name')) {$name = $this->getRequestParameter('name'); } else {$name = 'everybody';
}
$this->setData('name',$name);
$this->setView('hello.tpl'); } • Pass the parameter “name” in the url to test it URL:/taoDocs/TestController/sayHello?name=bertrand ## Integration with TAO ## Adding a structure • Open the controller/structures.xml ( see more at Tao_30_structuresxml_format| guide about structures.xml ) • Add a new structure with a section • In the structures.xml add the tag • Since TAO 2.6 the structures are cached, so you will need to empty your cache (by default situated in data/generis/cache. Also you can use taoDevTools scripts) • When refreshing the TAO home screen, the new extension should be visible ### Adding a tree • Add the tag into trees in the structures.xml file ( How_to_add_a_new_items_type|How to add a new items type ) NOTE: You should clear cache after each change of structures.xml. ### Adding a Controller • Now you can reload page and see error. It’s because you should create controller for our tree of documents. Example of Browser controller is attached ( Browser.php ). Download and place this file to controller folder. • Browser controller need two dependent classes: DocsService ( DocsService.php ) and FileUtils ( FileUtils.php ). This files should be downloaded and placed to model and helpers folders respectively. You need create this folders if it not exists. • Now we see error about undefined DOCS_PATH constant. Constants in extension usually stored in includes/constants.php. Create folder and file and insert into code from section below. $todefine = [
'DOCS_PATH' => ROOT_PATH . 'taoDocs/views/docs/'
];

Our documents will be placed on taoDocs/views/docs/ folder. Also you need create this folder and place to there or create some files.

• If you placed some files to created folder, the extension taoDocs now should shows a list of the files in it.

Add the tag into actions in the structures.xml file

Attribute id link this actions with tree. So for Delete button we need define id as “delete”, as in tree.

Attribute name define text on button.

Attribute url define path to controller action.

Attribute group tell where action (button) should be placed. In our case it will be places in tree, below list of files.

Attribute binding define handler for this action in front-side application (javascript). How should be organised frontend application see here: Front js

• Add the following code to the controller Browser.php
public function delete()
{
$filepath = DOCS_PATH .$this->getRequestParameter('uri');
$deleted = FileUtils::deleteFile($filepath);
if ($deleted) { //remove the current selection from the session$this->removeSessionAttribute('uri');

echo json_encode(['deleted' => 1]);
}
}
• After refreshing the page, when you select file in tree, you will see a delete button at the bottom of the Tree. Now you can delete selected file.

• If you wish you can now try to add your own actions, like duplicating a file, or creating an form to upload new files
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.1677531599998474, "perplexity": 8605.30466822981}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-40/segments/1600400220495.39/warc/CC-MAIN-20200924194925-20200924224925-00692.warc.gz"}