1
remel24354
Help Needed with Custom Module Development in XOOPS

Hey guys......

I have been working with XOOPS for a little while now, and I am currently trying to develop a custom module to fit some specific requirements for a project I'm working on. Although, I am running into some challenges and could really use your advice.

The module I am building involves creating a user dashboard that pulls data from multiple existing XOOPS modules (like News, Comments, and Private Messaging) and displays it in one place for easier management. I’ve gone through the basic module creation tutorial, but I’m a bit stuck on how to fetch and display data from other modules within my custom module.

Here are a few specific questions I have:

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.
How should I structure the permissions for users accessing this dashboard, especially considering the different access levels required for the different modules?
Are there any examples or tutorials for similar use cases (integrating data from multiple modules) that you could point me to?
I also check this: how can i use php development in xoops modules? and blockchain I’m really looking forward to any advice or tips you can provide! I feel like I’m close, but just need some pointers to get over this hurdle.

Thanks in advance for your help!

2
Mamba
Re: Help Needed with Custom Module Development in XOOPS

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 Helpers

Maybe 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 Helper

Maybe 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_ADMINXOOPS_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:
xmArticle
xmstock
xmdoc

Regarding 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.
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

Login

Who's Online

118 user(s) are online (24 user(s) are browsing Support Forums)


Members: 0


Guests: 118


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Oct 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits