Problem displaying alert.

Jake B.

Well-known member
I'm currently working on an addon, and I'm having a problem getting it to display the alerts after a certain action happens. I have created the appropriate rows in xf_content_type, and xf_content_type_field and pointed it towards my AlertHandler, which is being called. But for some reason it will not display the alert. It shows that I have a new alert, but doesn't display it.

Here is my alert handler:
Code:
<?php
class XenStop_Casino_AlertHandler_Casino extends XenForo_AlertHandler_Abstract
{
    protected $_postModel = null;
    public function getContentByIds(array $contentIds, $model, $userId, array $viewingUser)
    {
        $betModel = $model->getModelFromCache('XenStop_Casino_Model_Casino');
        return $betModel->getBetsByIds($contentIds);
    }
   
    protected function _prepareAlertBeforeAction(array $item, $content, array $viewingUser)
    {
        if($item['content_type']=='casino_bet'){
            if ($item['extra_data']) {
                $item['extra'] = unserialize($item['extra_data']);
                $item['winlose'] = $item['extra']['win_lose'];
                if($item['winlose'] == 1) {
                    $item['amount'] = intval($item['extra']['bet_amount']) * 2;
                } else {
                    $item['amount'] = $item['extra']['bet_amount'];
                }
            }
        }
        unset($item['extra_data']);
        return $item;
    }
    protected function _getDefaultTemplateTitle($contentType, $action) {
        return 'xenstop_casino_alert';
    }
}

It is selecting all of the rows from in the getContentByIds function, but the _prepareAlertBeforeAction function isn't even running.
 
Hi,
1). Did you rebuild the content type cache after you inserted them? Can be done via function rebuildContentTypeCache()
2). In your _prepareAlertBeforeAction() you are unsetting extra_data which function prepareAlert() looks for. Personally I would run you code via the _prepareAction() function (where Action is the action of your alert - such as 'win', 'lose').
 
1) Yes I did.
2) That isn't the problem, the '_prepareAlertBeforeAction' isn't even running

EDIT: I fixed the issue by removing the unset($item['extra_data']);

Thanks for the assistance @Syndol
 
Last edited:
Top Bottom