.

NotificationsController Class Reference

There are some routes to handle for notifications. More...

Inheritance diagram for NotificationsController:
ControllerBase IController IEventSink

List of all members.

Public Member Functions

  action_markallasread_cmd_handler (PageData $page_data)
  action_notifications_ajax_toggle (PageData $page_data)
  Toggle a message state.
  action_notifications_clicktrack (PageData $page_data, $id)
  Track links inside notifications messages.
  action_notifications_digest (PageData $page_data)
  Send a mail digest.
  action_notifications_exclude (PageData $page_data, $source, $source_id, $token)
  Exclude items.
  action_notifications_feed (PageData $page_data, $id_user, $feed_token)
  Notifications feed.
  action_notifications_settings (PageData $page_data)
  Change notifcation settings.
  action_notifications_view (PageData $page_data, $id)
  Show given notification.
  action_users_notifications (PageData $page_data)
  Show list of all notifications.
  get_routes ()
  Return array of Route instances which are handled by this controller.

Protected Member Functions

  do_notifications_settings (PageData $page_data, FormHandler $formhandler, $settings)
  Save settings.

Detailed Description

There are some routes to handle for notifications.

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


Member Function Documentation

NotificationsController::action_markallasread_cmd_handler ( PageData page_data  ) 

Definition at line 239 of file notifications.controller.php.

00239                                                                               {
00240                 $cmd = CommandsFactory::create_command('notifications', 'markallasread', false);
00241                 if (!$cmd->can_execute(false)) {
00242                         return CONTROLLER_ACCESS_DENIED;
00243                 }
00244                 $err = $cmd->execute();
00245                 if ($err->is_ok()) {
00246                         $err = new Message(tr('All notifications have been marked as read', 'notifications'));
00247                 }
00248                 History::go_to(0, $err);
00249                 exit; 
00250         }
NotificationsController::action_notifications_ajax_toggle ( PageData page_data  ) 

Toggle a message state.

Definition at line 209 of file notifications.controller.php.

00209                                                                               {
00210                 $page_data->in_history = false;
00211                 $page_data->page_template = 'emptypage';
00212                 $id = $page_data->get_post()->get_item('id', false);
00213                 $notification = DB::get_item('notifications', 'id', $id);
00214                 if (!AccessControl::is_allowed('status', $notification)) {
00215                         return self::ACCESS_DENIED;
00216                 }
00217                 
00218                 $new_status = ($notification->get_status() != Notifications::STATUS_NEW) ? Notifications::STATUS_NEW : Notifications::STATUS_READ;
00219                 $cmd = CommandsFactory::create_command($notification, 'status', $new_status);
00220                 $err = $cmd->execute();
00221                 if ($err->is_ok()) {
00222                         $view = ViewFactory::create_view(IViewFactory::MESSAGE, 'notifications/inc/item', $page_data);
00223                         $view->assign('notification', $notification);
00224                         $page_data->content = $view->render();
00225                 }
00226                 else {
00227                         return self::INTERNAL_ERROR;
00228                 }
00229         }
NotificationsController::action_notifications_clicktrack ( PageData page_data,
id  
)

Track links inside notifications messages.

Definition at line 87 of file notifications.controller.php.

00087                                                                                   {
00088                 Load::models('notifications');
00089                 $n = Notifications::get($id);
00090                 if ($n === false) {
00091                         return self::NOT_FOUND;
00092                 }
00093                 
00094                 $url = $page_data->get_get()->get_item('url', '');
00095                 $src = $page_data->get_get()->get_item('src', false);
00096                 $token = $page_data->get_get()->get_item('token', '');
00097                 if ($token != $n->click_track_fingerprint($src, $url)) {
00098                         return self::NOT_FOUND;
00099                 }
00100                 
00101                 $cmd = CommandsFactory::create_command($n, 'markread', array('read_through' => $src, 'read_action' => 'click'));
00102                 $cmd->execute(); 
00103                 
00104                 Url::create_with_fallback_host($url, Config::get_value(Config::URL_DOMAIN))->redirect(Url::TEMPORARY);
00105         }
NotificationsController::action_notifications_digest ( PageData page_data  ) 

Send a mail digest.

Definition at line 234 of file notifications.controller.php.

00234                                                                          {
00235                 $cmd = CommandsFactory::create_command('notifications', 'digest', false);
00236                 $page_data->status = $cmd->execute();
00237         }
NotificationsController::action_notifications_exclude ( PageData page_data,
source,
source_id,
token  
)

Exclude items.

Definition at line 190 of file notifications.controller.php.

00190                                                                                                        {
00191                 $data = array('source' => $source, 'source_id' => $source_id);
00192                 $user = Users::get_current_user();
00193                 if ($token != $user->create_token('exclude', $data)) {
00194                         return self::NOT_FOUND;
00195                 }
00196                 
00197                 $data['id_user'] = $user->id;
00198                 $cmd = CommandsFactory::create_command('notificationsexceptions', 'create', $data);
00199                 $err = $cmd->execute();
00200                 if ($err->is_ok()) {
00201                         $err = new Message(tr('Notifications have been disabled for the given item', 'notifications'));
00202                 }
00203                 History::go_to(0, $err, ActionMapper::get_url('users_notifications'));
00204         }
NotificationsController::action_notifications_feed ( PageData page_data,
id_user,
feed_token  
)

Notifications feed.

Definition at line 160 of file notifications.controller.php.

00160                                                                                               {
00161                 $page_data->in_history = false;
00162                 Load::models('notificationssettings');
00163                 $settings = NotificationsSettings::get_for_user($id_user);
00164                 if ($settings === false || !$settings->feed_enable || $settings->feed_token != $feed_token) {
00165                         return self::NOT_FOUND;
00166                 }
00167 
00168                 // Find notifications
00169                 $dao = NotificationsSettings::create_feed_adapter($settings);
00170                 $nots = array();
00171                 $dao->find();
00172                 while($dao->fetch()) {
00173                         if ($settings->should_notification_be_processed($dao, NotificationsSettings::TYPE_FEED)) {
00174                                 $n = clone($dao);
00175                                 $nots[] = $n;
00176                                 $n->add_sent_as(Notifications::DELIVER_FEED);
00177                                 $cmd = CommandsFactory::create_command($n, 'update', array());
00178                                 $cmd->execute();
00179                         }
00180                 }
00181                 
00182                 $view = ViewFactory::create_view(ViewFactoryMime::MIME, 'notifications/feed', $page_data);
00183                 $view->assign('notifications', $nots);
00184                 $view->render();
00185         }
NotificationsController::action_notifications_settings ( PageData page_data  ) 

Change notifcation settings.

Definition at line 110 of file notifications.controller.php.

00110                                                                            {
00111                 Load::models('notificationssettings');
00112                 Load::tools('formhandler');
00113                 $formhandler = new FormHandler('notificationssettings');
00114                 
00115                 $user = Users::get_current_user(); 
00116                 $settings = NotificationsSettings::get_for_user($user->id); // can be false
00117                 
00118                 if ($page_data->has_post_data()) {
00119                         $this->do_notifications_settings($page_data, $formhandler, $settings);
00120                 }
00121                 
00122                 $view = ViewFactory::create_view(IViewFactory::CONTENT, 'notifications/settings', $page_data);
00123                 $view->assign('sources', NotificationsSettings::collect_sources($user));
00124                 $view->assign('settings', $settings);
00125                 
00126                 if (empty($settings)) {
00127                         $settings = new DAONotificationssettings();
00128                         $settings->set_default_values();
00129                 }
00130                 $formhandler->prepare_view($view, $settings);
00131                 
00132                 $view->render(); 
00133         }
NotificationsController::action_notifications_view ( PageData page_data,
id  
)

Show given notification.

Definition at line 56 of file notifications.controller.php.

00056                                                                             {
00057                 Load::models('notifications');
00058                 $n = Notifications::get($id);
00059                 if ($n === false || !Users::is_current($n->get_user())) {
00060                         return self::ACCESS_DENIED;
00061                 }
00062                 
00063                 $src = $page_data->get_get()->get_item('src', false);
00064                 if ($src) {
00065                         $src = strtoupper($src);
00066                         if (key_exists($src, Notifications::get_read_sources())) {
00067                                 $cmd = CommandsFactory::create_command($n, 'markread', array('read_through' => $src, 'read_action' => 'click'));
00068                                 $cmd->execute(); 
00069                         }
00070                 }
00071                 
00072                 $page_data->head->title = $n->get_title();
00073                 $page_data->breadcrumb = WidgetBreadcrumb::output(array(
00074                         WidgetActionLink::output(tr('Your Notifications', 'notifications'), 'users_notifications'),
00075                         $n
00076                 ));
00077                 
00078                 
00079                 $view = ViewFactory::create_view(IViewFactory::CONTENT, 'notifications/view', $page_data);
00080                 $view->assign('notification', $n);
00081                 $view->render();
00082         }
NotificationsController::action_users_notifications ( PageData page_data  ) 

Show list of all notifications.

Parameters:
PageData  $page_data

Definition at line 34 of file notifications.controller.php.

00034                                                                         {
00035                 Load::models('notifications');
00036                 $adapter = Notifications::create_user_adapter(Users::get_current_user()->id);
00037 
00038                 $view = ViewFactory::create_view(IViewFactory::CONTENT, 'notifications/my', $page_data);
00039                 Load::tools('pager', 'filter');
00040                 
00041                 $filter = new Filter($page_data, $adapter->get_filters());
00042                 $filter->apply($adapter);
00043                 $filter->prepare_view($view);
00044                 
00045                 $pager = new Pager($page_data, $adapter->count(), Config::get_value(Config::ITEMS_PER_PAGE));
00046                 $pager->apply($adapter);
00047                 $pager->prepare_view($view);
00048                 
00049                 $view->assign('notifications', $adapter->execute());
00050                 $view->render();
00051         }
NotificationsController::do_notifications_settings ( PageData page_data,
FormHandler formhandler,
settings  
) [protected]

Save settings.

Definition at line 138 of file notifications.controller.php.

00138                                                                                                                {
00139                 $err = $formhandler->validate();
00140                 if ($err->is_ok()) {
00141                         $update = ($settings != false);
00142                         $data = $page_data->get_post()->get_array();
00143                         $data['id_user'] = Users::get_current_user()->id;
00144                         if (!$update) {
00145                                 $settings = new DAONotificationssettings();
00146                         }
00147                         $data = $settings->unset_internals($data);
00148                         
00149                         $cmd = $update 
00150                                 ? CommandsFactory::create_command($settings, 'update', $data) 
00151                                 : CommandsFactory::create_command('notificationssettings', 'create', $data);
00152                         $err->merge($cmd->execute());                   
00153                 }
00154                 $formhandler->finish($err, tr('Your settings have been saved', 'notifications'));
00155         }
NotificationsController::get_routes (  ) 

Return array of Route instances which are handled by this controller.

Returns:
array Array of Routes

Reimplemented from ControllerBase.

Definition at line 11 of file notifications.controller.php.

00011                                      {
00012                 return array(
00013                         new ExactMatchRoute('https://user/notifications/', $this, 'users_notifications', new AccessRenderDecorator()),
00014                         new ExactMatchRoute('https://user/notifications/settings/', $this, 'notifications_settings', new AccessRenderDecorator()),
00015                         new ParameterizedRoute('https://notifications/feeds/{id_user:ui>}/{feed_token:s:40}', $this, 'notifications_feed', new NoCacheCacheManager()),
00016                         new ParameterizedRoute('https://notifications/{id:ui>}/', $this, 'notifications_view', new AccessRenderDecorator()),
00017                         new NotificationsExcludeRoute('https://notifications/exclude/{source:s}/{source_id:ui>}/{token:s}/', $this, 'notifications_exclude', new AccessRenderDecorator()),
00018                         // Ajax
00019                         new ExactMatchRoute('https://ajax/notifications/toggle', $this, 'notifications_ajax_toggle', new AccessRenderDecorator()),
00020                         // Clicktracking
00021                         new ParameterizedRoute('https://notifications/{id:ui>}/click/', $this, 'notifications_clicktrack'),
00022                         // Command Line 
00023                         new ExactMatchRoute('notifications/digest', $this, 'notifications_digest', new ConsoleOnlyRenderDecorator()),
00024                         // COmmands
00025                         new CommandsRoute('https://process_commands/notifications/markallasread', $this, 'markallasread_cmd_handler', new AccessRenderDecorator()),
00026                 );      
00027         }       

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