How to make pm automatically?
tony Offline
Junior Member
**
Posts: 4
Joined: Nov 2012
Post: #1
How to make pm automatically?
How can I make it so when an user is a member of my forum for say one year it receives a pm automatically with some text like Hello username. You have been a member here for one year etc etc.

What hook should I use and what code? I would appreciate some help.
11-30-2012 06:20 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: How to make pm automatically?
It depends on how you want to approach the issue.
What do you exactly want to trigger the sending of the PM?  Perhaps a task?  When the user logs in?  That will determine where you should apply your modifications.

My Blog
12-01-2012 09:13 AM
Find all posts by this user Quote this message in a reply
Seabody Offline
Member
***
Posts: 54
Joined: Aug 2012
Post: #3
RE: How to make pm automatically?
Well, the basic code for a fuction would be along the lines of this, but I'm not 100% sure it works:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function happybday($to)
  {
      global $mybb
      require_once(MYBB_ROOT . "inc/datahandlers/pm.php");
      $pmhandler = new PMDataHandler();
      $pmhandler->admin_override = true;

      $pm = array(
          "subject" => "Hi",
          "message" => "You've been a member for a year. Have some pie.",
          "icon" => "-1",
          "toid" => array(),
          "fromid" => '1', //Change this to a uid
          "do" => "",
          "pmid" => ""
      );
      $pm["options"] = array(
          "signature" => "0",
          "disablesmilies" => "0",
          "savecopy" => "0",
          "readreceipt" => "0"
      );
      
      if(!is_array($to))
      {
          array_push($pm["toid"], $to);
      }
      else
      {
          foreach($to as $uid)
          {
              array_push($pm["toid"], $uid);
          }
      }

      $pmhandler->set_data($pm);

      if($pmhandler->validate_pm())
      {
          $pmhandler->insert_pm();
          return true;
      }
      else
      {
          return false;
      }
  }

12-01-2012 09:40 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: How to make pm automatically?
^ Does not contain a trigger.

My Blog
12-01-2012 10:20 PM
Find all posts by this user Quote this message in a reply
tony Offline
Junior Member
**
Posts: 4
Joined: Nov 2012
Post: #5
RE: How to make pm automatically?
(12-01-2012 09:13 AM)ZiNgA BuRgA Wrote:  It depends on how you want to approach the issue.
What do you exactly want to trigger the sending of the PM?  Perhaps a task?  When the user logs in?  That will determine where you should apply your modifications.

I would like for the pm to be sent automatically as soon as an user is a member at my forum for one year. No task or any other criteria such when they log in or anything. Thank you in advance Smile

What is trigger btw? That the code above does not have it? And what hook should I use?
12-02-2012 04:16 AM
Find all posts by this user Quote this message in a reply
tony Offline
Junior Member
**
Posts: 4
Joined: Nov 2012
Post: #6
RE: How to make pm automatically?
My previous post became moderate because it said that it triggered the spam filter but I was not spamming.
12-02-2012 04:17 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #7
RE: How to make pm automatically?
(12-02-2012 04:16 AM)tony Wrote:  I would like for the pm to be sent automatically as soon as an user is a member at my forum for one year. No task or any other criteria such when they log in or anything.
That isn't a trigger, that's a condition.  There is no such trigger as "user is a member for one year".

A triggered action requires three things:
- triggers
- conditions
- actions

You've given a condition (member registration date is at least one year in the past and PM has not previously been sent) and an action (send PM and indicate not to send the PM again), but you haven't given a trigger to cause this event to occur.
If you actually intend to code this, this is a basic concept you need to be very well aware of.

(12-02-2012 04:16 AM)tony Wrote:  That the code above does not have it? And what hook should I use?
If you don't understand the basic concepts of triggers, don't even bother trying to think about hooks because it's not going to make sense.
A trigger is an activation of an action in response to some external influence.  A user visiting a page is an example of an external influence.


Of course, if you're really just asking someone to make this modification for you, we won't help you.  Neither will we hand hold you with PHP etc - that's obviously a required knowledge for coding it in the first place.

My Blog
12-02-2012 09:19 AM
Find all posts by this user Quote this message in a reply
tony Offline
Junior Member
**
Posts: 4
Joined: Nov 2012
Post: #8
RE: How to make pm automatically?
Thank you for explaining it to me. Now I am not asking anyone to code it for me. I can code it for myself but I am stuck at which hook name to use. I have condition ready to get the anniversary of the user and I have the code to send the pm automatically. What I miss is the hook name. Can you help me with that please?
12-03-2012 06:27 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #9
RE: How to make pm automatically?
(12-02-2012 09:19 AM)ZiNgA BuRgA Wrote:  you haven't given a trigger to cause this event to occur.

My Blog
12-03-2012 07:54 AM
Find all posts by this user Quote this message in a reply
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #10
RE: How to make pm automatically?
You could maybe use a daily task that looks for users with a start date of one year ago and then send a pm which will be in the inbox next time they log in - you could even add a column in the user table for the PM sent so it would only query on those users who had not already had a PM.


[Image: leelink.gif]
MYBB1.6 & XThreads
12-03-2012 11:49 AM
Visit this user's website Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: