Related.txt
Use the Related Module
by Matthew McNaney
The Related module allows administrators to link information. Once one
or more items are linked, they will reference one another when either
is viewed.
Making your module work with the Related module is simple and
straightforward.
You should access the Related module when an individual item (an
article, an image, an event, etc.) is being viewed.
For example, we will access Related in a function named 'View';
if ($_REQUEST['action'] == 'view' && isset($_REQUEST['id']))
view($_REQUEST['id']);
function view($id){
$content = MyModule::viewItem($id);
Layout::add($content);
}
First we create our related object:
$related = & new Related;
Next we need to plug-in imformation about our module:
/*-------------------------------------------------------------*/
$id = 5;
$title = "My module rules all!";
$url = "index.php?module=MyModule&action=view&id=$id";
$related->setMainId($id); // This is the id of our module's item
$related->setModule("MyModule"); // The name of your module
/**
* You may have more than one item type in your module. If so, you can
* name them separately. If you only have one item type, you don't need
* to call this function.
*/
$related->setItemName("MyModule");
$related->setTitle($title); // This is the title to your item
$related->setUrl($url); // The relative address to the view function
/*-------------------------------------------------------------*/
After setting everything up, you can then call:
$related->show();
The Related module will take care of the rest.
There is one parameter you can add to the show function.
This paramter lets you restrict edit access. For example:
$allow = Current_User::allow("MyModule");
$related->show($allow);
If the user had permission to administrate your module, a TRUE value
would get passed to the show function and they would be able to create
related links. If it was FALSE, then they would be stuck with the
default view.