Kunena 7.0.4 Released
The Kunena team has announce the arrival of Kunena 7.0.4 [K 7.0.4] in stable which is now available for download as a native Joomla extension for J! 5.4.x/6.0.x. This version addresses most of the issues that were discovered in K 6.2 / K 6.3 / K 6.4 and issues discovered during the last development stages of K 7.0
Question Category Subscriptions - Default Subscribed?
15 years 6 months ago #63553
by DesoWV
Replied by DesoWV on topic Re: Category Subscriptions - Default Subscribed?
ok, so I have been able to get it to insert the data for whichever user is logged in by:
now, obviously we dont want this to run every single time a user changes pages on the website (which is what its doing right now with the above code). So I have tried to implement a check on the user's last login seeing as I dont know any other way to check for the user being new.
what I have to attempt this is:
Now, this is stopping it from setting the logged in user subscribed to the category whenever they change pages on the website, in fact its not subscribing at all right now because it is not finding a match for the if statement.... That is where something is wrong, its not catching when the user has a lastvisitDate of 0000-00-00 00:00:00 to which my theory is that this is set to the current time/date the instant you log in, before the "system - kunena plugin" even runs the php file with the above code....
any thoughts?
Code:
$user = &JFactory::getUser ();
$query = "INSERT INTO jos_kunena_subscriptions_categories (catid, userid) VALUES ('234987','$user->id')";
mysql_query($query);
now, obviously we dont want this to run every single time a user changes pages on the website (which is what its doing right now with the above code). So I have tried to implement a check on the user's last login seeing as I dont know any other way to check for the user being new.
what I have to attempt this is:
Code:
$user = &JFactory::getUser ();
$visitq = "SELECT lastvisitDate FROM jos_users WHEN (id==$user->id)";
$visit = mysql_query($visitq);
if ($visit=="0000-00-00 00:00:00") {
$query = "INSERT INTO jos_kunena_subscriptions_categories (catid, userid) VALUES ('234987','$user->id')";
mysql_query($query);
}
Now, this is stopping it from setting the logged in user subscribed to the category whenever they change pages on the website, in fact its not subscribing at all right now because it is not finding a match for the if statement.... That is where something is wrong, its not catching when the user has a lastvisitDate of 0000-00-00 00:00:00 to which my theory is that this is set to the current time/date the instant you log in, before the "system - kunena plugin" even runs the php file with the above code....
any thoughts?
Please Log in or Create an account to join the conversation.
15 years 6 months ago - 15 years 6 months ago #63554
by Matias
Replied by Matias on topic Re: Category Subscriptions - Default Subscribed?
You need to play with phpMyAdmin a bit:
So you will need to do something like this when user gets created:
That will subscribe user to all selected categories, including those he cannot see. Well, that should be OK as they are not counted if user doesn't have permissions..
Code:
-- Find all categories where user can subscribe (not a section and published):
SELECT c.id FROM jos_kunena_categories AS c WHERE c.parent>0 AND c.published=1
-- Find all categories where user is already subscribed:
SELECT * FROM jos_kunena_subscriptions_categories AS s WHERE s.userid=62
-- Find all categories where user is NOT subscribed:
SELECT c.id, s.userid FROM jos_kunena_categories AS c
LEFT JOIN jos_kunena_subscriptions_categories AS s ON c.id=s.catid AND s.userid=62
WHERE parent>0 AND s.userid IS NULL
-- Insert user into category:
INSERT INTO jos_kunena_subscriptions_categories (catid, userid) VALUES ('123','62')
-- Do it for all categories (use static value for userid):
INSERT INTO jos_kunena_subscriptions_categories (catid, userid)
SELECT c.id, 62 AS userid FROM jos_kunena_categories AS c
LEFT JOIN jos_kunena_subscriptions_categories AS s ON c.id=s.catid AND s.userid=62
WHERE parent>0 AND s.userid IS NULL
So you will need to do something like this when user gets created:
Code:
if ($isNew) {
// Subscribe user to selected categories:
$selectedCategories = '1,2,3,4,5,6,7,8,9,10';
$db = Jfactory::getDBO();
$query = "INSERT INTO #__kunena_subscriptions_categories (catid, userid)
SELECT c.id, {$user->id} AS userid
FROM #__kunena_categories AS c
LEFT JOIN #__kunena_subscriptions_categories AS s ON c.id=s.catid AND s.userid={$user->id}
WHERE c.parent>0 AND c.id IN ({$selectedCategories}) AND s.userid IS NULL";
$db->setQuery ( $query );
$db->query ();
KunenaError::checkDatabaseError();
}
That will subscribe user to all selected categories, including those he cannot see. Well, that should be OK as they are not counted if user doesn't have permissions..
Last edit: 15 years 6 months ago by Matias.
Please Log in or Create an account to join the conversation.
15 years 6 months ago - 15 years 6 months ago #63557
by Matias
Replied by Matias on topic Re: Category Subscriptions - Default Subscribed?
Here's query to add subscriptions to all users to selected categories: c.id IN (ADD YOUR LIST INTO HERE):
WARNING: Never use this for large sites with many users. Sending email is pretty slow and even if you use this for one category, it may make posting messages into it REALLY SLOW.
So this feature may be useful for small sites having maybe up to 50-100 users. Well, maybe we will have better emailing system for the next version.
Code:
INSERT INTO jos_kunena_subscriptions_categories (catid, userid)
SELECT c.id, u.id AS userid
FROM jos_users AS u JOIN jos_kunena_categories AS c
LEFT JOIN jos_kunena_subscriptions_categories AS s ON u.id=s.userid
WHERE c.id IN (1,2,3,4,5) AND s.userid IS NULL
WARNING: Never use this for large sites with many users. Sending email is pretty slow and even if you use this for one category, it may make posting messages into it REALLY SLOW.
So this feature may be useful for small sites having maybe up to 50-100 users. Well, maybe we will have better emailing system for the next version.
Last edit: 15 years 6 months ago by Matias.
Please Log in or Create an account to join the conversation.
15 years 6 months ago #63562
by Matias
Replied by Matias on topic Re: Category Subscriptions - Default Subscribed?
If you have really small site with only few friends using it, you may remove c.id IN (...) to subscribe users to every category.
PS. this subject belongs into hacks category..
PS. this subject belongs into hacks category..
Please Log in or Create an account to join the conversation.
15 years 6 months ago #63563
by DesoWV
Replied by DesoWV on topic Re: Category Subscriptions - Default Subscribed?
Thank You for your replies, I have read through them and tried to understand what all is going on there, but it is a little over my head. I am going to bed now (12:18AM here) and maybe in the morning I will be able to decipher it 
I replaced my code with yours but it doesnt seem to be working, my guess is that its a result of the $isNew as this is not defined in the **/plugins/system/kunena.php ??
Sorry about the wrong category, originally I posted asking a question with no intention of going into code editing, my hope was that this was going to be implemented into the final 1.6 version, please move if needed
Oh ya, the site is for a Volunteer Organization and its members, at current the user total should not exceed 100 for the next year or two, so good news there.
I replaced my code with yours but it doesnt seem to be working, my guess is that its a result of the $isNew as this is not defined in the **/plugins/system/kunena.php ??
Sorry about the wrong category, originally I posted asking a question with no intention of going into code editing, my hope was that this was going to be implemented into the final 1.6 version, please move if needed
Oh ya, the site is for a Volunteer Organization and its members, at current the user total should not exceed 100 for the next year or two, so good news there.
Please Log in or Create an account to join the conversation.
15 years 6 months ago #63568
by Matias
Replied by Matias on topic Re: Category Subscriptions - Default Subscribed?
Variable is $isnew
Didn't look at the function, so i remembered it wrong.
I also haven't tested the code, but I just added it (commented out for now) into Kunena 1.7. With configuration option and better email system, this could be pretty cool feature.
I also haven't tested the code, but I just added it (commented out for now) into Kunena 1.7. With configuration option and better email system, this could be pretty cool feature.
Please Log in or Create an account to join the conversation.
Time to create page: 0.278 seconds