Quote:
What’s the best way to retrieve data from other modules in XOOPS? Should I be using the existing APIs, or is there another recommended method?
Is there a specific XOOPS function or best practice for interacting with the database across multiple modules? I want to ensure that my approach is clean and efficient.
The best way would be probably to use XMF (see the
XMF Cookbook), and specifically the
Module HelpersMaybe something like this (
please note: none of this code is tested!):
use Xmf\Module\Helper;
// Get the helper for the 'news' module
$helper = Helper::getHelper('news');
// Get the handler for the 'story' object in the 'news' module
$storyHandler = $helper->getHandler('story');
// Define criteria for data retrieval
$criteria = new CriteriaCompo();
$criteria->setLimit(10); // Limit to 10 items
// Retrieve data objects
$newsItems = $storyHandler->getObjects($criteria);
// Loop through and display data
foreach ($newsItems as $newsItem) {
echo $newsItem->getVar('title');
}
Quote:
How should I structure the permissions for users accessing this dashboard, especially considering the different access levels required for the different modules?
I would work with the XMF
Permission HelperMaybe something like this:
Initialize the Permission Helper: use Xmf\Module\Helper\Permission;
$permHelper = new Permission();
Check User Permissions: // Assuming you're in your custom module context
$moduleDirName = basename(dirname(__DIR__));
$helper = Helper::getHelper($moduleDirName);
$permHelper = new Permission($helper);
$permissionName = 'view_dashboard'; // Define your custom permission
$itemId = null; // Use null if not item-specific
$userGroups = $xoopsUser ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS];
if ($permHelper->checkPermission($permissionName, $itemId, $userGroups)) {
// User has permission, display dashboard
} else {
// User doesn't have permission, show an error or redirect
redirect_header('index.php', 3, _NOPERM);
}
Define Permissions in Your Module: In your xoops_version.php, define the permissions your module will use.
Example in xoops_version.php:
$modversion['config'][] = [
'name' => 'permissions',
'title' => '_MI_YOURMODULE_PERMISSIONS',
'description' => '_MI_YOURMODULE_PERMISSIONS_DESC',
'formtype' => 'group_multi',
'valuetype' => 'array',
'default' => [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS],
];
Set Up Permission Items: Use the Permission Helper to set up permission items in your module's administration interface.
Example in Your Module's Admin Code:
$permHelper->savePermissionForItem('view_dashboard', $itemId, $groupIds);
Consider Module Permissions: When accessing other modules' data, check if the user has permissions in those modules.
Example:
// For the 'news' module
$newsHelper = Helper::getHelper('news');
$newsPermHelper = new Permission($newsHelper);
if ($newsPermHelper->checkPermission('view', $newsItemId, $userGroups)) {
// User has permission to view the news item
} else {
// Handle lack of permission
}
Quote:
Are there any examples or tutorials for similar use cases (integrating data from multiple modules) that you could point me to?
You might look at the
modules from Mage:
xmArticlexmstockxmdocRegarding
blockchain, this would be a completely custom implementation - you would need to use use PHP libraries to interact with blockchain APIs (like Ethereum, Bitcoin, or Hyperledger), but this would be quite complex.