How to add welcome ticket in helpdesk when user signup

From aMember Pro Documentation
Revision as of 07:17, 19 May 2016 by Caesar (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Add this code to site.php file:

Am_Di::getInstance()->hook->add(Am_Event::USER_AFTER_INSERT,  function (Am_Event $event){
    $user = $event->getUser();
    $di = $event->getDi();
 
    $ticket = $di->helpdeskTicketRecord;
    $ticket->created = $ticket->updated = sqlTime('now');
    $ticket->user_id = $user->user_id;
    $ticket->status = HelpdeskTicket::STATUS_AWAITING_USER_RESPONSE;
 
    // TICKET SUBJECT
    $ticket->subject = 'Welcome user '.$user->name_f.' '.$user->name_l;
    $ticket->has_new = 1;
    $ticket->insert();
 
    $message = $di->helpdeskMessageRecord;
    $message->dattm = sqlTime('now');
    $message->admin_id = 1; // ADMIN ID
 
    // TICKET BODY
    $message->content =  'Welcome to helpdesk. Simple content';
    $message->ticket_id = $ticket->ticket_id;
    $message->insert();
});