1
deka87
Notifications based on criteria
  • 2008/12/17 21:05

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


Hi,

I use Catads 1.4 module and I've noticed that you can set up notification options e.g. receive notifications when there is a new ad posted. I was just wondering if it is possible for a users to receive notifications about new ads posted by users from their $coutry only i.e when $country defined by the user in the registration form = $location defined in the "submit new ad" form in the catads module. I am not talking about the catads module only but other modules too where you've got to define your coutry.

Hope I made this clear, so waiting for your suggestions.
Mind anchors

2
Anonymous
Re: Notifications based on criteria
  • 2008/12/17 21:38

  • Anonymous

  • Posts: 0

  • Since:


I understand what you mean and find it a usefull idea. But I should prefer keyword driven notifications. In that way you could receive notifications based on location but also other keywords for objects you want to buy, articles you like to read, autors you like to read from etc. I guess this would be an exciting new feature for xoops!

3
deka87
Re: Notifications based on criteria
  • 2008/12/18 5:43

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


Yea that's a great idea to have a keyword targeted notifications. Module developers, any suggestions?
Mind anchors

4
deka87
Re: Notifications based on criteria
  • 2008/12/18 17:04

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


C'mon moderators pay a little bit of your precious attention to this thread. This could really be helpful cos if a user gets notifications about all the ads posted he gets kinda spammed.
Mind anchors

5
trabis
Re: Notifications based on criteria
  • 2008/12/18 19:42

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Using notifications on tag module could be another idea.

About the use of criteria, in your ads module, on the submit file, there should be a line that calls this function:

function triggerEvent ($category, $item_id, $event, $extra_tags=array(), $user_list=array(), $module_id=null, $omit_user_id=null)

As you can see there is a $user_list parameter. You can pass into it an array of members that belong to a certain country. This will be used by notifications module as filter criteria

About keywords, we could use a field in profile module so users can enter tags they want to subscribe. Then, we could use the same method above so when a new item is submitted with a certain tag, we could fetch users that have those tags in profile and pass them into the notification->triggerevent()

I believe this can be done without core hacking

6
deka87
Re: Notifications based on criteria
  • 2008/12/18 20:54

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


thanks trabis. it's alwasy awesome when you and ghia join the topic.

as in regard to the line you provided, i dont have it. although i have this:

// Notification
        
$ads_id $xoopsDB->getInsertId();
        
$notification_handler =& xoops_gethandler('notification');
        
$tags = array();
        
$tags['ADS_TITLE'] = $ads_type.' '.$ads_title;
        
$tags['ADS_LANG'] = $ads->getVar('ads_lang1').' to '.$ads->getVar('ads_lang2');
        
$tags['ADS_DESC'] = $ads->getVar('ads_desc');
        if ( 
$xoopsModuleConfig['moderated'] == 1) {
            
$tags['ADS_URL'] = XOOPS_URL '/modules/' $xoopsModule->getVar('dirname') . '/admin/index.php?sel_status=2';
            
$notification_handler->triggerEvent('global'0'ads_submit'$tags);
            
$notification_handler->triggerEvent('category'$cat_id'ads_submit'$tags);
            
// If notify checkbox is set, add subscription for approve
            
if ($notifypub) {
                include_once 
XOOPS_ROOT_PATH '/include/notification_constants.php';
                
$notification_handler->subscribe('ads'$ads_id'approve'XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
            }
            
$messagesent ="<br />"._MD_CATADS_AFTER_MODERATE;
        } else {
            
$tags['ADS_URL'] = XOOPS_URL '/modules/' $xoopsModule->getVar('dirname') . '/adslist.php?cat_id=' $cat_id;
            
$notification_handler->triggerEvent('global'0'new_ads'$tags);
            
$notification_handler->triggerEvent('category'$cat_id'new_ads'$tags);
            
$messagesent ="<br />"._MD_CATADS_NO_MODERATE;
        }
        
redirect_header("index.php",2,$messagesent);
    break;


can you see those "$ads_lang1" and '$ads_lang2" variables (i've added them by myself)? I have also added two custom lines in the registration form: "$source_language" and "$target_language". So I want a user to be notified if $ads_lang1==$source_language and $ads_lang2==$target_language.

anyways, if this were too complicated, please just comment the code I've attached
Mind anchors

7
ghia
Re: Notifications based on criteria
  • 2008/12/18 22:15

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
This will be used by notifications module as filter criteria
So, from all users that subscribed, only the users that match languages should receive the notification?

8
trabis
Re: Notifications based on criteria
  • 2008/12/18 23:48

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

ghia wrote:
Quote:
This will be used by notifications module as filter criteria
So, from all users that subscribed, only the users that match languages should receive the notification?


The code is:
if (!empty($user_list)) {
            
$user_criteria = new CriteriaCompo();
            foreach (
$user_list as $user) {
                
$user_criteria->add (new Criteria('not_uid'$user), 'OR');
            }
            
$criteria->add($user_criteria);
        }


So if $user_list is array('1','12','145')
it push to the query something like this:

AND (not_uid = '1' OR not_uid = '12' OR not_uid = '145')

Remember that the users that are on the table are just the ones who selected to be notified so this will force a filter.
If you pass other users that did not choosed to be notified it will not be a problem because they are not in the table and they wont return in a row.

Deka:
This is a good line for changes:
$notification_handler->triggerEvent('global'0'ads_submit'$tags);


First you must get your user list(as an array) based on the ad language. Then you need to pass your user list as follows
$user_list = array('1','23','134');//do this your way
$notification_handler->triggerEvent('global'0'ads_submit'$tags$user_list);


Do this for the events you like (in this case we are dealing with the category 'global' event 'ads_submit')

9
Anonymous
Re: Notifications based on criteria
  • 2008/12/19 0:28

  • Anonymous

  • Posts: 0

  • Since:


I have another idea but I don't know if it is useful or no

- add new field "country" in xoops_catads_ads table
- add option to notify by country
- play with this code to send email if the ad releated to your country:

if ($country_notify == 1) {
                    
$ads_handler =& xoops_getmodulehandler('ads');
                    
$ads $ads_handler->get($item_id);
                    
$xoopsMailer =& getMailer();
                    
$xoopsMailer->useMail();
                    
$xoopsMailer->setToEmails($xoopsuser->email());
                    
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
                    
$xoopsMailer->setFromName($xoopsConfig['sitename']);
                    
$xoopsMailer->setSubject($ads->getVar('ads_title'));
                    
$xoopsMailer->setBody($ads->getVar('ads_desc'));
                    
$xoopsMailer->send();
                }





10
ghia
Re: Notifications based on criteria
  • 2008/12/19 2:47

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


The $user_list can come from the resultset of the following query:
$sql '
SELECT * FROM '
.$this->db->prefix('xoopsnotifications').
LEFT JOIN '
.$this->db->prefix('user_profile').
 ON not_uid = profileid 
WHERE
 not_modid = '
.$mod_id.' AND
 not_itemid = '
.0.' AND
 not_category = '
."'global'".' AND
 not_event = '
."'ads_submit'".' AND
 ((source_language <> '
.$ads->getVar('ads_lang1').') OR
  (target_language <> '
.$ads->getVar('ads_lang2').'))';

The first four where clauses can differ depending on the targeted notification.

Login

Who's Online

201 user(s) are online (141 user(s) are browsing Support Forums)


Members: 0


Guests: 201


more...

Donat-O-Meter

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

Latest GitHub Commits