In order to create a ressource type, you need to specify three functions that will be used to access the ressources.
When users create an attachment, they are offered a dropdown list to choose both contents (the attachment, and that to which it is attached) from. This function retrieves the options that will be available in the dropdown list.
The options should be stored in the variable $options, in the form of $options = array($id=>$label) The available variables are $gCms, $db and $type (see below for this object\'s attributes).
Here is, for example, the retrievecombo code for the "News article" ressource type:
$query = "SELECT news_id, news_title FROM ".cms_db_prefix()."module_news"; $dbresult =& $db->Execute($query); while ($dbresult && $row = $dbresult->FetchRow()){ $options[$row["news_id"]] = $row["news_title"]; }
When the module displays the elements attached to the content we are currently seeing, it needs for each attachment to retrieve some of the ressource\'s information to build the link that will be displayed, namely the url and the name to display. You are given the attachment object ($item), and should fill the values $item->ressource_url and $item->ressource_name. (Other available variables are $gCms, $db, $type, $id and $returnid).
Here is, for example, the retrieveitem code for the "Content Page" ressource type:
$manager =& $gCms->GetHierarchyManager(); $node =& $manager->sureGetNodeById($item->destid); if(!isset($node)) return false; $content =& $node->GetContent(); $item->ressource_name = $content->Name(); $item->ressource_url = $content->getURL();
This code is executed before the ressource type is made active. If you need to check for any necessary module, here\'s the place to do it. At the end of the execution, $result should hold true if the ressource type can be activated, and false if it can\'t.
Here is, for example, the activecheck code for the "News article" ressource type:
if(!isset($gCms->modules["News"]) || !$gCms->modules["News"]["active"]){ $result = false; }else{ $result = true; }
Make sure the "Attach: use" permission has been given to the users!
First, go in the Attachments section of the content menu and create some attachments... You will be asked what kind of ressource you wish to attach to what kind of ressource, so if I want to link a Content page to a file, I would choose: Attach a "File" to a "Content Page"...
Then, to display the elements attached to the current Content Page, simply add this to the template : {cms_module module="Attach"}
To display the elements attached to any other ressource, you must specify some additional parameters (from_type and from_id). For example, to display the elements attached to a news article, you could add this to the news detail template: {cms_module module="Attach" from_type="News-article" from_id=$entry->id}
In order to create or edit ressource types, you will need the "Attach: admin" permission. Be careful with this permission! Editing ressource types means editing php code and possible danger to your website.
If you would like to add a CTLModuleMaker module to the ressource types, use the following functions (make sure to replace NAMEOFMODULE by the name of your module, and NAMEOFLEVEL by the name of the level you wish to use).
$themodule = $this->GetModuleInstance("NAMEOFMODULE"); if(!$themodule) return false; $itemlist = $themodule->get_level_NAMEOFLEVEL(); foreach($itemlist as $item) $options[$item->id] = $item->name;
$themodule = $this->GetModuleInstance("NAMEOFMODULE"); if(!$themodule) return false; $result = $themodule->get_level_NAMEOFLEVEL(array("id"=>$item->destid,"active"=>1)); if(!isset($result[0])) return false; $item->ressource_name = $result[0]->name; $linkparams = array("alias"=>$result[0]->alias, "parent"=>$result[0]->parent_alias); $item->ressource_url = $themodule->CreateLink($id,"default",$returnid,"",$linkparams,"",true, false, "", true, $themodule->BuildPrettyUrls($linkparams, $returnid));
if(!isset($gCms->modules["NAMEOFMODULE"]) || !$gCms->modules["NAMEOFMODULE"]["active"]){ $result = false; }else{ $result = true; }