Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #118522 Feat: Document for TJ UCM #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<ul>
{% assign tutorials = posts | sort: "title" %}
{% for tutorial in tutorials | sort: "navigation_weight" %}
{% if tutorial.showSidebar %}
<li {% if tutorial.url == page.url %}class="active"{% endif %}><a href="{{ site.baseurl }}{{ tutorial.url }}">{{ tutorial.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
Expand Down
5 changes: 3 additions & 2 deletions _posts/2017-01-17-com-api-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ tags:
- REST API
type: Document
navigation_weight: 1
showSidebar: "true"
---

# REST API framework for Joomla

com_api is a quick and easy way to add REST APIs to Joomla. Extendible via plugins, you an easily add support for more Joomla extensions. To get started, download the component and install the API plugins you need. Enable the plugins and you are ready to fetch your content via APIs.
com_api is a quick and easy way to add REST APIs to Joomla. Extendible via plugins, you an easily add support for more Joomla extensions. To get started, download the component and install the API plugins you need. Enable the plugins and you are ready to fetch your content via APIs.

To add additional resources to the API, plugins need to be created. Each plugin can provide multiple API resources. Plugins are a convenient way to group several resources. Eg: A single plugin could be created for Quick2Cart with separate resources for products, cart, checkout, orders etc.

## Plugin Terms

### app
An app is essentially a Joomla plugin. However the plugin itself does nothing more than load the resources it contains. So the app is mainly used to package the API plugin and to enable adding any API specific parameters. Each app will have one or more resources.
An app is essentially a Joomla plugin. However the plugin itself does nothing more than load the resources it contains. So the app is mainly used to package the API plugin and to enable adding any API specific parameters. Each app will have one or more resources.

### resource
Resources are files that have code to accept input and set the API output. You will usually have multiple resources in an app. A common use case is for an extension like Easysocial or Jomsocial to have a single app. The app contains resources for various objects like groups, events, photos, newsfeed etc. The resource will contain the methods `get()` `post()` `delete()` to perform CRUD operations on that type of object.
Expand Down
35 changes: 18 additions & 17 deletions _posts/2017-01-17-com-api-plugin-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tags:
- REST API
type: Document
navigation_weight: 0
showSidebar: "true"
---

# Writing your own API Plugin
Expand All @@ -23,12 +24,12 @@ Each resource supports the GET, POST and DELETE operations. These are exposed by
- login.php - Resource file
- users.php - Resource file
* users.php - plugin file
* users.xml - xml file
* users.xml - xml file

You can add multiple resource in resource folder and use them for different purpose. Usually, each resource will map to an object type for your extension.

## Create plugin entry file users.php file
This is the entry file for the API plugin, the things that re deifned in the file are resource locations, and making certain resources public. Below is the code for the file -
This is the entry file for the API plugin, the things that re deifned in the file are resource locations, and making certain resources public. Below is the code for the file -

```php
jimport('joomla.plugin.plugin');
Expand All @@ -38,14 +39,14 @@ class plgAPIUsers extends ApiPlugin
public function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config = array());

// Set resource path
ApiResource::addIncludePath(dirname(__FILE__).'/users');

// Load language files
$lang = JFactory::getLanguage();
$lang = JFactory::getLanguage();
$lang->load('com_users', JPATH_ADMINISTRATOR, '', true);

// Set the login resource to be public
$this->setResourceAccess('login', 'public', 'post');
}
Expand All @@ -64,14 +65,14 @@ class UsersApiResourceLogin extends ApiResource
$result = new \stdClass;
$result->id = 45;
$result->name = "John Doe"

$this->plugin->setResponse( $result );
}

public function post()
{
// Add your code here

$this->plugin->setResponse( $result );
}
}
Expand All @@ -80,7 +81,7 @@ class UsersApiResourceLogin extends ApiResource
The array or object from the plugin should be set via `$this->plugin->setResponse()`.

## Error Handling
It is possible to send HTTP errors with the right HTTP codes using the `APIError::raiseError()` method. Depending on the type of error you can raise different Exceptions that set the appropriate HTTP code.
It is possible to send HTTP errors with the right HTTP codes using the `APIError::raiseError()` method. Depending on the type of error you can raise different Exceptions that set the appropriate HTTP code.

```php
<?php
Expand All @@ -103,14 +104,14 @@ It is possible to send HTTP errors with the right HTTP codes using the `APIError

You are free to specify your own error code and message. It is also possible to add more Exceptions in the `components/com_api/libraries/exceptions` folder. When using `APIError::raiseError()` there is no need to use `$this->plugin->setResponse()` since com_api handles the response and setting the http code.

Note : The exception classes extend PHP's `Exception` class. So you will need to use numeric only codes, since PHP does not support non-numeric Exception codes.
Note : The exception classes extend PHP's `Exception` class. So you will need to use numeric only codes, since PHP does not support non-numeric Exception codes.


## Private and public resources

Unless specified, all resources are private, which means an API token is needed to access. However, it is possible to make certain resource and methods public by using the setResourceAccess() access method as
```php
$this->setResourceAccess('login', 'public', 'post')
$this->setResourceAccess('login', 'public', 'post')
```

The first parameter is the resource name, second is status (should be public to make it public) and last is HTTP method to make public. Setting a resource public will mean that the API URL for that resource will not need any authentication.
Expand Down Expand Up @@ -139,21 +140,21 @@ Finally create a manifest XML so that your plugin can be installed. Set group as
<name>YourPlugin</name>
<version>1.0</version>
<creationDate>10/11/2016</creationDate>
<author></author>
<author></author>
<description></description>
<files>
<filename plugin="your_plugin_name">your_plugin_name.php</filename>
<folder>your_plugin_name</folder>
<folder>your_plugin_name</folder>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_api_plugin_name.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_api_plugin_name.sys.ini</language>
</languages>
</extension>

</extension>
```

## Tips for writing plugins
- Think of API plugins as a replacement of controllers. Any business logic that you won't put in a controller, leave it out of the plugin too. Load and use your models in the plugin code.
- It is not recommended to have API specific language files unless absolutely necessary. You will ususally make plugins for an existing component, so load the language files from that component.
- To create the list and details for an object type, you can either add a condition based on `id` query parameter in the `get()` method, or have a separate resource for the list.
- To create the list and details for an object type, you can either add a condition based on `id` query parameter in the `get()` method, or have a separate resource for the list.
3 changes: 2 additions & 1 deletion _posts/2017-09-15-com-api-making-api-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ tags:
- Joomla
- REST API
type: Document
showSidebar: "true"
---

# Calling API resources

## API URLs
The URL to access any route is of the format -
The URL to access any route is of the format -

`/api/{plugin}/{resource}`

Expand Down
7 changes: 4 additions & 3 deletions _posts/2017-09-15-tjreports-architecture-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ tags:
- tjreports
- architecture
type: Document
showSidebar: "true"
---

# TJ Reports : Architecture Overview
In terms of data structure, the TJ Reports framework is a Joomla MVC List view, with added features for saving queries, modifying columns and dynamic filters. Since reports are typically tabular data, reusing existing list view infrastructure was an obvious choice. So under the hood, it simply extends JModelList. The key difference is that instead of a single model, the framework allows plugins to extend the base reports model and provide a query or list for the report.

## Plugin Architecture
TJ Reports allows a plugin driven approach to creating "pluggable models" that can be rendered as a report.
TJ Reports allows a plugin driven approach to creating "pluggable models" that can be rendered as a report.
Each plugin is essentially a model class that can have Joomla's `getListQuery()` or `getItems()` method to either return a query object, or directly the array of items to display. So TJReports does not use plugins in their classic event/dispatcher pattern. Instead, TJ Reports uses plugins to simplify installation and set any defaults via parameters.

To implement filters, sorting and dynamic columns there are additional methods that allow setting column names, toggle sortable and filter columns and choose which columns may be hidden by the user.
Expand All @@ -23,6 +24,6 @@ Once a plugin is installed, an instance of the plugin needs to be created for th
Additionally, ACL can be applied to each instance so it becomes possible to create multiple lists from the same plugin, but with different filters that can be set such that users cannot change the filters.

## Component Architecture
As mentioned above, the component loads a single plugin instance using it's configuration. The component also applies the ACL based on the instance configuration.
As mentioned above, the component loads a single plugin instance using it's configuration. The component also applies the ACL based on the instance configuration.

The component allows users to create saved queries. Saved queries are stored similar to an instance, but they inherit the ACL and configuration superset of the instance they are created from.
The component allows users to create saved queries. Saved queries are stored similar to an instance, but they inherit the ACL and configuration superset of the instance they are created from.
53 changes: 27 additions & 26 deletions _posts/2017-09-15-tjreports-integration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tags:
- Joomla
- tjreports
type: Document
showSidebar: "true"
---

# TJ Reports Integration Guide
Expand Down Expand Up @@ -43,57 +44,57 @@ b) ```title``` - This is the title of your plugin visible to users.
## Linking to TJ reports
Just like other infrastructure extensions, you can pass the client context to show reports related to your extension. For instance Shika uses `index.php?option=com_tjreports&client=tjlms` for reports contextual to Shika LMS. The client is be specified when creating instances.

When user passes client parameter in the url at backend, framework also fetches the menus added in the `addSubmenu` of the component you passed in the client parameter.
When user passes client parameter in the url at backend, framework also fetches the menus added in the `addSubmenu` of the component you passed in the client parameter.

Below is the default URL for your extension
Below is the default URL for your extension

`index.php?option=com_tjreports&client=com_example&task=reports.defaultReport`

This will bring you to the first plugin of that client type.
This will bring you to the first plugin of that client type.


## Plugin configuration options -
One can limit number of columns to show in the Report using plugin configuration. When you edit a plugin in tjreport you can load default params using ```Load Default Params``` . This data depends on the details you have mentioned in your plugin __constract.
One can limit number of columns to show in the Report using plugin configuration. When you edit a plugin in tjreport you can load default params using ```Load Default Params``` . This data depends on the details you have mentioned in your plugin __constract.

Below is the example JSON Data -
Below is the example JSON Data -

```
{
"filter_order":"name",
"filter_order_Dir":"ASC",
"limit":"20",
"showHideColumns":[
"attempt",
"name",
"username",
"usergroup",
"time_spent",
"lesson_status",
"score",
"last_accessed_on"
],
"attempt",
"name",
"username",
"usergroup",
"time_spent",
"lesson_status",
"score",
"last_accessed_on"
],
"colToshow":{
"attempt": true,
"name":true,
"username":true,
"usergroup":false,
"time_spent":true,
"lesson_status":true,
"score":true,
"last_accessed_on":true
}
}
```
"name":true,
"username":true,
"usergroup":false,
"time_spent":true,
"lesson_status":true,
"score":true,
"last_accessed_on":true
}
}
```

filter_order - Default filter column, can be any key of your $this->columns array

filter_order_Dir - Default filter direction, can we ASC or DESC

limit - Default limit of the results

showHideColumns - Which columns to show in show/hide dropdown. It must be a subset of colToshow(next option)
showHideColumns - Which columns to show in show/hide dropdown. It must be a subset of colToshow(next option)

colToshow - By default what columns to display. Key of this data are column names(keys of $this->columns array) and value can be true or false which decides whether it will be displayed by default or not.
colToshow - By default what columns to display. Key of this data are column names(keys of $this->columns array) and value can be true or false which decides whether it will be displayed by default or not.



1 change: 1 addition & 0 deletions _posts/2017-09-15-tjreports-writing-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tags:
- Joomla
- tjreports
type: Document
showSidebar: "true"
---

# Example Report Plugin
Expand Down
3 changes: 2 additions & 1 deletion _posts/2017-09-16-hierarchy-manager-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ tags:
- Hierarchy
type: Document
navigation_weight: 1
showSidebar: "true"
---
# Hierarchy Management
# Hierarchy Management

Hierarchy Management is an horizontal (Infrastructure) extension by Techjoomla that allows setting up general or context specific hierarchical relations between users. This can be used by other extensions to allow special access control, generate reports and so on.
3 changes: 2 additions & 1 deletion _posts/2017-09-16-tc-manager-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ tags:
- Terms & Conditions Manager
type: Document
navigation_weight: 1
showSidebar: "true"
---

# Terms & Conditions Manager
Terms & Conditions Manager is used to force users to accept the T&C before they can start using the site, or a part of the site.
Terms & Conditions Manager is used to force users to accept the T&C before they can start using the site, or a part of the site.

It is also possible to define multiple T&C that block different contexts. For example, you may want users to accept terms before they start writing blogs on your site. On the same site, you may want users to accept different terms before they can participate in the community. The T&C Manager allows you to do this.

Expand Down
Loading