1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Empty Alert

Discussion in 'XenForo Development Discussions' started by Robust, Nov 21, 2015.

  1. Robust

    Robust Well-Known Member

    So I use the following code:

    Code:
                        XenForo_Model_Alert::alert(
                            $user['user_id'],
                            $user['user_id'],
                            $user['username'],
                            'task_completion',
                            $user['user_id'],
                            'completed'
                        );
    The user gets the alerts, but they are always empty. When I hover over alerts, it just disappears and shows none, and when I go to show all alerts they're not there, but when it's initially processed (before marking them as 'read') it shows the number beside the "Alert" text.

    What's up? Never had this problem with alerts before. It's a custom alert handler, which does this:

    (canViewAlert -> true)
    Code:
        public function getContentByIds(array $contentIds, $model, $userId, array $viewingUser)
        {
            return $model->getModelFromCache('Model_Class')->getTasksByTaskIds($contentIds);
        }
    That method returns:
    Code:
        public function getTasksByTaskIds(array $taskIds)
        {
            return $this->fetchAllKeyed('
                SELECT *
                FROM aupp_task AS task
                WHERE task_id IN ('. $this->_getDb()->quote($taskIds) .')
            ', 'task_id');
        }
    A little urgent, so thanks for any help I can get :)
     
  2. Jake B.

    Jake B. Well-Known Member

    Does your template have the correct name? It's getting the data if the alert is at least showing up
     
  3. Robust

    Robust Well-Known Member

    Template name is:
    alert_task_completion_completed

    With content:
    Code:
    {xen:phrase aupp_you_have_just_completed_a_task,
        'taskname={$content.title}',
        'taskpoints={$content.added_points}'}
     
  4. Robust

    Robust Well-Known Member

    The alert doesn't exact show, btw. It's shown like 1 alert or something, but when I hover over it says "There are no new alerts". It's also not shown on "Show all alerts" - so I don't even see the empty alert box without any data. I just see the number there, which goes away after hover.
     
  5. Robust

    Robust Well-Known Member

    Here's xf_user_alert table data:
    [​IMG]
     
  6. Robust

    Robust Well-Known Member

    Actually, doh moment, I might just have it.
     
  7. dmurphy

    dmurphy Member

    I am having the same issue right now. Mind sharing how you got around it?
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    I would guess a content type and content type field hasn't been added and/or no Alert handler code.
     
  9. Robust

    Robust Well-Known Member

    I wish I wrote down what solved it for me. I remember it was something obvious but the last thing I'd think of at the same time. I really just can't remember what I did.

    Ensure you have the content type setup and all, that's critical. First thing you need to do. You also need an AlertHandler class for it.
     
  10. dmurphy

    dmurphy Member

    I have both content type field and content type setup. (using https://xenforo.com/community/resources/content-type-management.2513/) and have my handler code.

    Maybe you guys can spot something I cannot.

    Call an alert:
    Code:
    XenForo_Model_Alert::alert($var['user_id'], 0, "", 'tickets', $var['user_id'], 'new');
    AlertHandler:
    Code:
    class ServUO_shardwatch_AlertHandler_Ticket extends XenForo_AlertHandler_Abstract
    {
        public function getContentByIds(array $contentIds, $model, $userId, array $viewingUser)
        {
            return $model->getModelFromCache('ServUO_shardwatch_Model_ticket')->getTicketsByIds($contentIds);
        }
    }
    Model method:
    Code:
      public function getTicketsByIds(array $ticketIds)
      {
          return $this->fetchAllKeyed('
       SELECT *
       FROM xf_servuo_shardwatch_tickets
       WHERE ticket_id IN (' . $this->_getDb()->quote($ticketIds) . ')
    ', 'ticket_id');
      }
    alert_tickets_new template:
    Code:
    {xen:phrase ServUO_shardwatch_ticketAlert}
    phrase:
    Code:
    You have a new support ticket. 
     
  11. Daniel Hood

    Daniel Hood Well-Known Member

    When you added the content type and content type field for the alert handler did you delete the contenttypes entry in the data registry?
     
  12. Xon

    Xon Well-Known Member

    You also need to manually rebuild the content type cache if you modify the content type tables outside of the installer/uninstaller.
     
  13. Chris D

    Chris D XenForo Developer Staff Member

    It seems he created he content types through my management add on so it does these things automatically.

    Probably worth doing them manually just to be sure though.
     
    Xon likes this.
  14. RichardKYA

    RichardKYA Well-Known Member

    I just had this problem, so I thought I would put the solution for own experience here in case it helps someone else at some point.

    Anyway, after a few hours of banging my head against a wall, I realised that........I was stupid, I had previously discovered this many times before in my life, and while it wasn't the complete answer to my problem, I knew it must have something do with my current situation, so I decided to start from the very beginning of creating an add on and under the drop down menu of my add-on, I selected "edit", it was here that took note of my add on id, which was "My_Addon_Id", remember this, because this part is imperative to my solution. So with the id noted freshly in my mind, I then went and checked the xf_content_type table and it was here that my stupidity had flourished, because it was here that I had put "my_addon_id", instead of "My_Addon_Id".

    So, if you get stuck, at least make sure your addon id is correct ;)
     

Share This Page