31
trabis
Re: Notifications based on criteria
  • 2008/12/21 13:07

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Ok, for XOOPS 2.2 it is a little more simple:
$user_handler =& xoops_gethandler('user');
$criteria = new CriteriaCompo(new Criteria('source_language'$ads->getVar('ads_lang1')));
$criteria->add(new Criteria('target_language'$ads->getVar('ads_lang2')));
$users $user_handler->getList($criteria);
unset(
$criteria);
$user_list array_keys($users);

32
deka87
Re: Notifications based on criteria
  • 2008/12/21 16:23

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


YAHOOO! It works now! Thanks guys, this is really awesome. Two more questions:

1. Does it send notifications when source and target languages are absolutely equal to ads_lang1 and ads_lang2, or source and target languages may just contain words from ads_lang1 and ads_lang2. Is it case sensitive?

2. Is it possible to set catads notifications checked by default for newly registered users? but still make it possible to unsubscribe whenever they want.
Mind anchors

33
trabis
Re: Notifications based on criteria
  • 2008/12/21 17:00

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Match is case sensitive, that is why I recommended using a select box the first place.

Anyway, this may help with case differences I think:

$user_handler =& xoops_gethandler('user');
$criteria = new CriteriaCompo(new Criteria('source_language'$ads->getVar('ads_lang1'),'LIKE'));
$criteria->add(new Criteria('target_language'$ads->getVar('ads_lang2'),'LIKE'));
$users $user_handler->getList($criteria);
unset(
$criteria);
$user_list array_keys($users);


Glad to see it works!

Adding notifications while registering is possible.
You have to do something like this:

$not_handler =& xoops_gethandler('notification');
$not_handler->subscribe($category$item_id$events$mode$module_id$user_id);


You must fill the data to suit your needs,

$mode could be 'NULL' because it will get the user selected notification method.

$uid is for the new registered user so you must get it after the insert statement(something like $user_handler->insert($user);)

using something like
$uid = $user->getVar('uid');

$module_id is the ads module id
If you don´t want to hard code it then you must use this:
$module_handler =& xoops_gethandler('module');
$module $module_handler->getByDirname('ads');//change ads to the name of the module
$module_id $module->getVar('mid');


The rest of the parameters are up to you.






34
deka87
Re: Notifications based on criteria
  • 2008/12/21 17:08

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


$module_handler =& xoops_gethandler('module');
$module $module_handler->getByDirname('ads');//change ads to the name of the module
$module_id $module->getVar('mid');

$not_handler =& xoops_gethandler('notification');
$not_handler->subscribe($category$item_id$events$mode$module_id$user_id);


am i supposed to include this in profile/register.php? if yes then where exactly?
Mind anchors

35
trabis
Re: Notifications based on criteria
  • 2008/12/21 17:26

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Yes, around line 156.
Add your code bellow $newid = $newuser->getVar('uid');

You can use $user_id=$newid;

This code happens before user gets activated but it should not make a diference.

If you want you can edit activate.php around line 58 and paste your code above this line:
$config_handler =& xoops_gethandler('config');

In that case $user_id=$thisuser->getVar('uid');

36
deka87
Re: Notifications based on criteria
  • 2008/12/21 19:34

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


I've added the code in the registration form and registered a new user. but he didnt get notifications. i checked "notifications" tab and saw that he's got "Module: Jobs" event instead of "New job" and the category line was empty.

and i've got one more question about notifications based on criteria. is it done only for global or for every category too? i mean if a user decides to be notified about a new ad in some category (not global) will he still get proper notifications based on his languages?
Mind anchors

37
trabis
Re: Notifications based on criteria
  • 2008/12/21 19:42

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

deka87 wrote:
I've added the code in the registration form and registered a new user. but he didnt get notifications. i checked "notifications" tab and saw that he's got "Module: Jobs" event instead of "New job" and the category line was empty.

and i've got one more question about notifications based on criteria. is it done only for global or for every category too? i mean if a user decides to be notified about a new ad in some category (not global) will he still get proper notifications based on his languages?


You have to fill the other options($category, $item_id, $events) to suit your needs.
If you want user to subscribe several items then you have to enter more $notification_handler->subscribe() lines.

38
deka87
Re: Notifications based on criteria
  • 2008/12/21 19:53

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


ok thank you. now i think the thread may be marked as solved
Mind anchors

39
deka87
Re: Notifications based on criteria
  • 2008/12/22 4:23

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


Trabis, in case I'd want to make it dropdown instead of a text box, what would the final code:

global $xoopsDB;
$sql "
SELECT * FROM "
.$xoopsDB->prefix('xoopsnotifications')."
LEFT JOIN "
.$xoopsDB->prefix('user_profile')."
 ON not_uid = profileid
WHERE
 not_modid = '"
.intVal($mod_id)."' AND
 not_itemid = '0' AND
 not_category = 'global' AND
 not_event = 'new_ads' AND
 source_language = "
.$xoopsDB->quoteString($ads->getVar('ads_lang1'))." AND
 target_language = "
.$xoopsDB->quoteString($ads->getVar('ads_lang2'));

$result $xoopsDB->query($sql);

$user_handler =& xoops_gethandler('user');
$criteria = new CriteriaCompo(new Criteria('source_language'$ads->getVar('ads_lang1')));
$criteria->add(new Criteria('target_language'$ads->getVar('ads_lang2')));
$users $user_handler->getList($criteria);
unset(
$criteria);
$user_list array_keys($users);


look like?
Mind anchors

40
ghia
Re: Notifications based on criteria
  • 2008/12/22 10:10

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


This part is no longer needed:
$sql "
SELECT * FROM "
.$xoopsDB->prefix('xoopsnotifications')."
LEFT JOIN "
.$xoopsDB->prefix('user_profile')."
 ON not_uid = profileid
WHERE
 not_modid = '"
.intVal($mod_id)."' AND
 not_itemid = '0' AND
 not_category = 'global' AND
 not_event = 'new_ads' AND
 source_language = "
.$xoopsDB->quoteString($ads->getVar('ads_lang1'))." AND
 target_language = "
.$xoopsDB->quoteString($ads->getVar('ads_lang2'));

$result $xoopsDB->query($sql);
and may be deleted.
Quote:
in case I'd want to make it dropdown instead of a text box

You mean for the source and target language select in the profile?
Isn't that a question of another definition for the field?

Login

Who's Online

501 user(s) are online (108 user(s) are browsing Support Forums)


Members: 0


Guests: 501


more...

Donat-O-Meter

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

Latest GitHub Commits