Jump to content

Example module.inc file: Difference between revisions

From NusaATK
Mjs (talk | contribs)
No edit summary
Mjs (talk | contribs)
Line 30: Line 30:
== registerNode() ==
== registerNode() ==


???
The <code>registerNode()</code> function call lets the access control components of ATK know what nodes exist, and what actions can be performed on those nodes.  Without explicitly adding nodes and actions, there is no way for any user (other than the administrator) to perform actions on nodes or even--in many cases--to see that an action (link) is even available.  Node that <code>registerNode()</code> does not determine who gets to do what; it only defines which actions are available.  (Who gets to do what is controlled by ATK's group management interface, and stored in the <code>access</code> table in the database.)
 
<code>registerNode()</code> has two arguments: a node name (string) and an array of actions:
 
<syntaxhighlight lang="php">
registerNode("user.student", array("admin", "add", "edit", "delete"));
</syntaxhighlight>
 
This tells ATK that the "admin", "add", "edit" and "delete" actions are valid operations to perform on a "user.student" node.


== menuitem() ==
== menuitem() ==

Revision as of 17:23, 29 August 2008

Every module you add to an ATK application follows some basic principles.

Create a directory, where the name is equal to the module name. For example, if you're going to create a module 'users', name the directory 'users'. It's best to place it in the modules/ subdir of your application.

In the directory, you place your node files. A module does not necessarily have to have any nodes, but most modules will consist of one or more nodes.

The module file is the most important part of the directory, as it will define the module. This file should be called 'module.inc' and should contain the following code:

<?php

  class mod_users extends atkModule
  {

     function getNodes()
     {
        registerNode("users.group", array("admin", "add", "edit", "delete"));
     }

     function getMenuItems()
     {
        $this->menuitem("groupadmin", dispatch_url("users.group", "admin"));
     }

  }

?>

registerNode()

The registerNode() function call lets the access control components of ATK know what nodes exist, and what actions can be performed on those nodes. Without explicitly adding nodes and actions, there is no way for any user (other than the administrator) to perform actions on nodes or even--in many cases--to see that an action (link) is even available. Node that registerNode() does not determine who gets to do what; it only defines which actions are available. (Who gets to do what is controlled by ATK's group management interface, and stored in the access table in the database.)

registerNode() has two arguments: a node name (string) and an array of actions:

registerNode("user.student", array("admin", "add", "edit", "delete"));

This tells ATK that the "admin", "add", "edit" and "delete" actions are valid operations to perform on a "user.student" node.

This function takes two parameters:

  • The name of the menuitem (‘groupadmin’ in this case)
  • The url that should displayed when the user clicks the menu item. This can be any valid url.

A third and a fourth parameter can be added as well.

function getMenuItems()
{
  $this->menuitem("groupadmin", dispatch_url("users.group", "admin"), "main", array("users.group", "admin"));
}

The third parameter, $parent, determines whether the menu item is a first- or second-level menu item. If $parent is absent or equal to the string"main", the menu item appears at the top level. If $parent is a string, then the menu item appears as a sub-menu of the named menu item.

The fourth parameter controls menu item visibility. (i.e. who has access to the menu item.) If true, then the menu item is always displayed; if false it's never displayed. If it's an array, the first element of the array must be a node (identified by modulename.nodename notation), the second element is an action. The third can be a node again, the fourth an action, and so on. If the user has the right to perform one of these actions, he will see the menu-item. In this case, the menu is displayed if the user has the ‘admin’ right on the 'users.group' node.