Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
Tz Tools
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
4cd50c72
authored
2010-11-10 14:16:18 +0000
by
Kevin Burton
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
update to notification
1 parent
33f056a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
5 deletions
com/Notifications/Notifications.php
com/Notifications/Notifications.php
View file @
4cd50c7
...
...
@@ -8,6 +8,7 @@ use Tz\Common;
const
OPTION_NAME
=
"notif_options"
;
call_user_func
(
function
()
{
Tools\add_actions
(
__NAMESPACE__
.
'\Actions'
);
Vars
::
$options
=
new
Tools\WP_Option
(
OPTION_NAME
);
if
(
is_admin
())
{
require_once
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'Validation.php'
);
...
...
@@ -38,6 +39,39 @@ function get_notification_by_trigger($trigger) {
}
/**
* GET NUMBER OF NEW NOTICES
@returns (Int)
*/
function
get_num_notices
()
{
// get number of notices for this user that are new...
$notices
=
get_user_meta
(
Tools\getCurrentUser
()
->
ID
,
'notices'
,
true
);
$notifications
=
array
();
// return $num;
if
(
empty
(
$notices
))
{
return
0
;
}
else
{
foreach
(
$notices
as
$notice
)
{
if
(
$notice
[
'status'
]
==
"show"
)
{
$notifications
[]
=
$notice
;
}
}
}
return
count
(
$notifications
);
}
function
remove_notice
(
$notification_id
=
-
1
)
{
$notices
=
get_user_meta
(
Tools\getCurrentUser
()
->
ID
,
'notices'
,
true
);
if
(
!
empty
(
$notices
))
{
foreach
(
$notices
as
$id
=>
$notice
)
{
if
(
$id
==
$notification_id
)
{
$notices
[
$id
][
'status'
]
=
"hide"
;
break
;
}
}
}
update_user_meta
(
Tools\getCurrentUser
()
->
ID
,
'notices'
,
$notices
);
}
/**
Send Notifications
...
...
@@ -79,17 +113,20 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array())
// if is_system ==========================================
if
(
$notification
->
is_system
)
{
$notices
=
get_user_meta
(
$user
->
ID
,
'notices'
,
false
);
if
(
!
is_array
(
$notices
))
{
$notices
=
array
();
}
$notices
=
get_user_meta
(
$user
->
ID
,
'notices'
,
true
);
$insert
=
array
(
'notification_id'
=>
$nid
,
'status'
=>
'show'
,
'sent_date'
=>
time
()
,
'args'
=>
$args
);
$notices
[]
=
$insert
;
if
(
empty
(
$notices
))
{
$notices
=
array
();
}
$notices
[]
=
$insert
;
update_user_meta
(
$user
->
ID
,
'notices'
,
$notices
);
}
...
...
@@ -141,6 +178,13 @@ function current_url() {
return
$pageURL
;
}
class
Actions
{
public
static
function
wp_ajax_update_notification_count
()
{
$count
=
get_num_notices
();
$return
=
array
(
'count'
=>
$count
);
die
(
json_encode
(
$return
));
}
}
class
Vars
{
public
static
$options
;
...
...
Please
register
or
sign in
to post a comment