.

Notifications Class Reference

Facade class for notifications model. More...

List of all members.

Static Public Member Functions

static  create (DAOUsers $user, $params, &$created)
  Create a notification for given user.
static  create_unread_user_adapter ($id_user)
  Finds all unread notifications for given user.
static  create_user_adapter ($id_user)
  Finds all notifications for given user.
static  existing ($params)
  Returns Notiifcation, if a notification with given params already exists.
static  get ($id)
  return given Notification
static  get_all_sources ($id_user)
  Returns all sources available (for user).
static  get_delivery_methods ()
  Returns all possible status.
static  get_latest ($user_id, $num)
  Returns $num latest notifications for user.
static  get_read_sources ()
  Returns all possible status.
static  get_status ()
  Returns all possible status.
static  mark_as_read_by_source_id ($id_user, $source, $source_id, $read_through=self::READ_CONTENT, $read_action= '')
  Mark matching notifications as read.
static  notify_all_users ($message, $title= '', $source= 'app', $params=array())
  Notify all users by sending a message.
static  notify_single_user (DAOUsers $user, $message, $title= '', $source= 'app', $params=array())
  Notify a user by sending a message.
static  notify_some_users ($arr_users, $message, $title= '', $source= 'app', $params=array())
  Notify a couple of user by sending a message.
static  translate_source ($src)
  Translates source.

Public Attributes

const  DELIVER_DIGEST = 'DIGEST'
const  DELIVER_FEED = 'FEED'
const  DELIVER_MAIL = 'MAIL'
const  READ_CONTENT = 'CONTENT'
const  READ_DIGEST = 'DIGEST'
const  READ_FEED = 'FEED'
const  READ_MAIL = 'MAIL'
const  READ_MARK_ALL = 'ALL'
const  READ_MARK_AUTO = 'AUTO'
const  READ_MARK_MANUALLY = 'MANUALLY'
const  READ_UNKNOWN = 'UNKNOWN'
const  SOURCE_ALL = 'all'
const  SOURCE_APP = 'app'
const  STATUS_NEW = 'NEW'
const  STATUS_READ = 'READ'

Detailed Description

Facade class for notifications model.

Definition at line 5 of file notifications.facade.php.


Member Function Documentation

static Notifications::create ( DAOUsers user,
params,
&$  created  
) [static]

Create a notification for given user.

Parameters:
DAOUsers  $user
array  $params
mixed  $created
Returns:
Status

Definition at line 119 of file notifications.facade.php.

00119                                                                           {
00120                 $ret = new Status();
00121                 $params['id_user'] = $user->id;
00122                 $params['title'] = self::compute_title(Arr::get_item($params, 'message', ''), Arr::get_item($params, 'title', ''));
00123                 $cmd = CommandsFactory::create_command('notifications', 'create', $params);
00124                 $ret->merge($cmd->execute());
00125                 $created = $cmd->get_result();
00126                 return $ret;
00127         }
static Notifications::create_unread_user_adapter ( id_user  )  [static]

Finds all unread notifications for given user.

Returns:
DAONotifications

Definition at line 94 of file notifications.facade.php.

00094                                                                     {
00095                 $ret = self::create_user_adapter($id_user);
00096                 $ret->status = self::STATUS_NEW;
00097                 return $ret;
00098         }
static Notifications::create_user_adapter ( id_user  )  [static]

Finds all notifications for given user.

Returns:
DAONotifications

Definition at line 82 of file notifications.facade.php.

00082                                                              {
00083                 $ret = new DAONotifications();
00084                 $ret->id_user = $id_user;
00085                 $ret->sort('creationdate', DataObjectBase::DESC);
00086                 return $ret;
00087         }
static Notifications::existing ( params  )  [static]

Returns Notiifcation, if a notification with given params already exists.

Checked are id_user, source and source_id (which must be non-empty!)

Returns:
DAONotifications Existing instance or false if none

Definition at line 244 of file notifications.facade.php.

00244                                                  {
00245                 $ret = false;
00246                 $source_id = Arr::get_item($params, 'source_id', false);
00247                 $id_user = Arr::get_item($params, 'id_user', false);
00248                 $source =  Arr::get_item($params, 'source', false);
00249                 if ($source_id && $id_user && $source) {
00250                         $dao = new DAONotifications();
00251                         $dao->id_user = $id_user;
00252                         $dao->source = $source;
00253                         $dao->source_id = $source_id;
00254                         $dao->status = self::STATUS_NEW;
00255                         if ($dao->find(DataObjectBase::AUTOFETCH)) {
00256                                 $ret = $dao;
00257                         }
00258                 }
00259                 return $ret;
00260         }
static Notifications::get ( id  )  [static]

return given Notification

Returns:
DAONotifications

Definition at line 30 of file notifications.facade.php.

00030                                         {
00031                 return DB::get_item('notifications', 'id', $id);
00032         }
static Notifications::get_all_sources ( id_user  )  [static]

Returns all sources available (for user).

Returns:
array

Definition at line 205 of file notifications.facade.php.

00205                                                          {
00206                 $dao = new DAONotifications();
00207                 $dao->id_user = $id_user;
00208                 $query = $dao->create_select_query();
00209                 $query->set_fields('source');
00210                 $query->set_policy(DBQuerySelect::DISTINCT);
00211                 
00212                 $result = DB::query($query);
00213                 $ret = array();
00214                 while($row = $result->fetch()) {
00215                         $ret[$row['source']] = self::translate_source($row['source']);
00216                 }
00217                 return $ret;
00218         }
static Notifications::get_delivery_methods (  )  [static]

Returns all possible status.

Returns:
array

Definition at line 51 of file notifications.facade.php.

00051                                                       {
00052                 return array(
00053                         self::DELIVER_MAIL => tr(self::DELIVER_MAIL, 'notifications'),
00054                         self::DELIVER_FEED => tr(self::DELIVER_FEED, 'notifications'),
00055                         self::DELIVER_DIGEST => tr(self::DELIVER_DIGEST, 'notifications'),
00056                 );
00057         }
static Notifications::get_latest ( user_id,
num  
) [static]

Returns $num latest notifications for user.

Returns:
array

Definition at line 105 of file notifications.facade.php.

00105                                                           {
00106                 $dao = self::create_unread_user_adapter($user_id);
00107                 $dao->limit(0, $num);
00108                 return $dao->find_array();
00109         }
static Notifications::get_read_sources (  )  [static]

Returns all possible status.

Returns:
array

Definition at line 64 of file notifications.facade.php.

00064                                                   {
00065                 return array(
00066                         self::READ_UNKNOWN => tr(self::READ_UNKNOWN, 'notifications'),
00067                         self::READ_MARK_MANUALLY => tr(self::READ_MARK_MANUALLY, 'notifications'),
00068                         self::READ_MARK_AUTO => tr(self::READ_MARK_AUTO, 'notifications'),
00069                         self::READ_MARK_ALL => tr(self::READ_MARK_ALL, 'notifications'),
00070                         self::READ_MAIL => tr(self::READ_MAIL, 'notifications'),
00071                         self::READ_FEED => tr(self::READ_FEED, 'notifications'),
00072                         self::READ_DIGEST => tr(self::READ_DIGEST, 'notifications'),
00073                         self::READ_CONTENT => tr(self::READ_CONTENT, 'notifications'),                  
00074                 );
00075         }       
static Notifications::get_status (  )  [static]

Returns all possible status.

Returns:
array

Definition at line 39 of file notifications.facade.php.

00039                                             {
00040                 return array(
00041                         self::STATUS_NEW => tr(self::STATUS_NEW, 'notifications'),
00042                         self::STATUS_READ => tr(self::STATUS_READ, 'notifications')
00043                 );
00044         }
static Notifications::mark_as_read_by_source_id ( id_user,
source,
source_id,
read_through = self::READ_CONTENT,
read_action = ''  
) [static]

Mark matching notifications as read.

Returns:
void

Definition at line 267 of file notifications.facade.php.

00267                                                                                                                                              {
00268                 if ($source_id && $id_user && $source) {
00269                         $params = array(
00270                                 'read_through' => $read_through,
00271                                 'read_action' => $read_action 
00272                         );
00273                         $dao = new DAONotifications();
00274                         $dao->id_user = $id_user;
00275                         $dao->source = $source;
00276                         $dao->source_id = $source_id;
00277                         $dao->status = self::STATUS_NEW;
00278                         $dao->find();
00279                         while($dao->fetch()) {
00280                                 $cmd = CommandsFactory::create_command(clone($dao), 'markread', $params);
00281                                 $cmd->execute();
00282                         }
00283                 }
00284         }
static Notifications::notify_all_users ( message,
title = '',
source = 'app',
params = array()  
) [static]

Notify all users by sending a message.

Parameters:
string  $message
string  $title If title is empty a title will be computed from message
Returns:
Status

Definition at line 182 of file notifications.facade.php.

00182                                                                                                            {
00183                 $params['title'] = self::compute_title($message, $title);
00184                 $params['message'] = $message;
00185                 $params['source'] = $source;
00186                 $cmd = CommandsFactory::create_command('users', 'notifyall', $params);
00187                 return $cmd->execute();         
00188         }
static Notifications::notify_single_user ( DAOUsers user,
message,
title = '',
source = 'app',
params = array()  
) [static]

Notify a user by sending a message.

Parameters:
DAOUsers  $user
string  $message
string  $title If title is empty a title will be computed from message
Returns:
Status

Definition at line 137 of file notifications.facade.php.

00137                                                                                                                              {
00138                 $ret = new Status();
00139                 $params['title'] = self::compute_title($message, $title);
00140                 $params['message'] = $message;
00141                 $params['source'] = $source;
00142 
00143                 $cmd = CommandsFactory::create_command($user, 'notify', $params);
00144                 if ($cmd->can_execute($user)) {
00145                         $ret->merge($cmd->execute());
00146                 }
00147                 return $ret;
00148         }
static Notifications::notify_some_users ( arr_users,
message,
title = '',
source = 'app',
params = array()  
) [static]

Notify a couple of user by sending a message.

Parameters:
array  $arr_users Array of DAOUsers
string  $message
string  $title If title is empty a title will be computed from message
Returns:
Status

Definition at line 158 of file notifications.facade.php.

00158                                                                                                                         {
00159                 $ret = new Status();
00160                 $already_notified_ids = array();
00161                 $title = self::compute_title($message, $title);
00162                 foreach($arr_users as $user) {
00163                         $user_id = $user->id;
00164                         if (!in_array($user_id, $already_notified_ids)) {
00165                                 $ret->merge(self::notify_single_user($user, $message, $title, $source, $params));
00166                                 if ($ret->is_error()) {
00167                                         break;
00168                                 }       
00169                                 $already_notified_ids[] = $user_id;
00170                         }
00171                 }
00172                 return $ret;
00173         }
static Notifications::translate_source ( src  )  [static]

Translates source.

Definition at line 223 of file notifications.facade.php.

00223                                                       {
00224                 $ret = $src;
00225                 switch($src) {
00226                         case self::SOURCE_ALL:
00227                         case self::SOURCE_APP:
00228                                 $ret = tr($src, 'notifications');
00229                                 break;
00230                         default:
00231                                 EventSource::Instance()->invoke_event('notifications_translate', $src, $ret);
00232                                 break;
00233                 }
00234                 return $ret;
00235         }

Member Data Documentation

Definition at line 13 of file notifications.facade.php.

Definition at line 14 of file notifications.facade.php.

Definition at line 12 of file notifications.facade.php.

const Notifications::READ_CONTENT = 'CONTENT'

Definition at line 23 of file notifications.facade.php.

const Notifications::READ_DIGEST = 'DIGEST'

Definition at line 21 of file notifications.facade.php.

const Notifications::READ_FEED = 'FEED'

Definition at line 22 of file notifications.facade.php.

const Notifications::READ_MAIL = 'MAIL'

Definition at line 20 of file notifications.facade.php.

Definition at line 19 of file notifications.facade.php.

Definition at line 18 of file notifications.facade.php.

Definition at line 17 of file notifications.facade.php.

const Notifications::READ_UNKNOWN = 'UNKNOWN'

Definition at line 16 of file notifications.facade.php.

Definition at line 6 of file notifications.facade.php.

Definition at line 7 of file notifications.facade.php.

Definition at line 9 of file notifications.facade.php.

Definition at line 10 of file notifications.facade.php.


The documentation for this class was generated from the following file: