Hi
I need a custom function where every time a user receive a Thank for their post, they will automatically get 1 point inserted to their custom point table here
Please review this code for the latest Joomla 5 and Kunena 6.2.3 version, do i need the event trigger or something to make this feature enabled?
Code:
<?php
// Your Joomla configuration file
define('_JEXEC', 1);
define('JPATH_BASE', __DIR__); // Adjust this path based on your Joomla installation
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
// Initialize the Joomla application
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
// Assuming #__shop_users_points is your table name
$db = JFactory::getDbo();
// Assuming 'kunena_thanks' is the table where thanks are recorded
// Replace 'kunena_messages', 'thanks_field', and 'user_field' with your actual Kunena table and field names
$query = $db->getQuery(true);
$query->select('userid')
->from('#__kunena_messages')
->where('thanks_field = 1');
$db->setQuery($query);
$usersToReward = $db->loadColumn();
// Insert 1 point for each user receiving thanks
foreach ($usersToReward as $userID) {
$insertQuery = $db->getQuery(true);
$insertQuery->insert('#__shop_users_points')
->columns(array('user_id', 'points_column'))
->values((int)$userID . ', 1');
$db->setQuery($insertQuery);
$db->execute();
}
?>
p/s how can i preview the message before it get posted? its very useful feature