Skip to main content
Topic: If ( there is an alert) (Read 7012 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

If ( there is an alert)

How do I know if there is an alert to initiate an action ?

Re: If ( there is an alert)

Reply #1

I guess I have got a wrong code here

Code: [Select]
/* Growl Notifications Angular */

if (!empty($txt['notify']))
echo '

<growl-notification class="fading">
    You have active notifications
</growl-notification>';

Re: If ( there is an alert)

Reply #2

Or, should I have to replace $txt with $context['notification_set'] ?


Re: If ( there is an alert)

Reply #3

Txt only contains strings, so I wouldn't check if it's empty.

Re: If ( there is an alert)

Reply #4

What should I check to see whether there is  a notification or not ?

Re: If ( there is an alert)

Reply #5

Do you mean the mentions? This holds the number of mentions (if you compare it > 0, and true, then there is a mention):
Code: [Select]
$context['user']['mentions']

Re: If ( there is an alert)

Reply #6

So, I would need to check 2. If there is like , if there is mention. Then I can display notification.

Re: If ( there is an alert)

Reply #7

You check is there is a "mention" (i.e. notification, yeah, same name for two things), a mention includes likes, @ mentions, and some other stuff.
Bugs creator.
Features destroyer.
Template killer.

Re: If ( there is an alert)

Reply #8

Yes. Is it possible that I can have the code to check both ? I am not good in php.

Some other stuff includes what all ? At the moment, I am concentrating on presence of like and @ mention

PS: I mean, compare if > 0 inclusive

Re: If ( there is an alert)

Reply #9

Use what CrimeS suggested. It is for both.
Bugs creator.
Features destroyer.
Template killer.

Re: If ( there is an alert)

Reply #10

php doubt. Something wrong with this code ?

Code: [Select]
/* Popup alert notification using Growl Notifications */

function growl_based_notification()
{
global $context;

if (!empty($context['user']['mentions']))

// Say they have unread alerts.

 
    $html = '<body ng-app="af_notify" ng-controller="growlCtrl">
   
    <growl-notifications></growl-notifications>
    <growl-notification>
      Psst ! You have unread notifications
    </growl-notification>
  </body>';
    return $html;


}
Last Edit: October 19, 2015, 04:06:15 pm by Wizard

Re: If ( there is an alert)

Reply #11

Yes and no.

If you mean "is the ElkArte way?" then the answer is: yes there is something wrong.
If you mean "is the code syntactically correct?" Then the answer is: no, nothing wrong.
Bugs creator.
Features destroyer.
Template killer.

Re: If ( there is an alert)

Reply #12

Sorry ?

Re: If ( there is an alert)

Reply #13

I asked because I did everything as per this Plunker code but getting no alert despite having an active mention

http://plnkr.co/edit/ZZHW0JKumXfdFgjTjVJz?p=preview

Re: If ( there is an alert)

Reply #14

Another way to say what I wrote it: the snippet of code you posted as is doesn't work in ElkArte, but is valid PHP code.
So, depending on what you are doing it may or may not work.
Guessing from your posts your question is: does that code work in ElkArte?
And then the answer is: no, because "return" is not "echo", and returning the HTML doesn't send it to the template, for that you need "echo", because that's the way ElkArte works.
Then there is the second problem: when $context['user']['mentions'] is 0, $html is not initialized, so ElkArte will throw an error.
Bugs creator.
Features destroyer.
Template killer.