|  | @ -1,33 +1,107 @@ | 
		
	
		
			
				|  |  | <?php |  |  | <?php | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | /** |  |  |  | 
		
	
		
			
				|  |  |  * @package Widgets |  |  |  | 
		
	
		
			
				|  |  |  * |  |  |  | 
		
	
		
			
				|  |  |  * @file Notifs.php |  |  |  | 
		
	
		
			
				|  |  |  * This file is part of MOVIM. |  |  |  | 
		
	
		
			
				|  |  |  * |  |  |  | 
		
	
		
			
				|  |  |  * @brief The notification widget |  |  |  | 
		
	
		
			
				|  |  |  * |  |  |  | 
		
	
		
			
				|  |  |  * @author Timothée Jaussoin <edhelas@gmail.com> |  |  |  | 
		
	
		
			
				|  |  |  * |  |  |  | 
		
	
		
			
				|  |  |  * @version 1.0 |  |  |  | 
		
	
		
			
				|  |  |  * @date 16 juin 2011 |  |  |  | 
		
	
		
			
				|  |  |  * |  |  |  | 
		
	
		
			
				|  |  |  * Copyright (C)2010 MOVIM project |  |  |  | 
		
	
		
			
				|  |  |  * |  |  |  | 
		
	
		
			
				|  |  |  * See COPYING for licensing information. |  |  |  | 
		
	
		
			
				|  |  |  */ |  |  |  | 
		
	
		
			
				|  |  | 
 |  |  |  | 
		
	
		
			
				|  |  | class Notification extends WidgetCommon |  |  | class Notification extends WidgetCommon | 
		
	
		
			
				|  |  | { |  |  | { | 
		
	
		
			
				|  |  |     function load() |  |  |     function load() | 
		
	
		
			
				|  |  |     { |  |  |     { | 
		
	
		
			
				|  |  |         //$this->addcss('notification.css');
 |  |  |  | 
		
	
		
			
				|  |  |         $this->addjs('notification.js'); |  |  |         $this->addjs('notification.js'); | 
		
	
		
			
				|  |  |         $this->registerEvent('pubsuberror', 'onPubsubError'); |  |  |  | 
		
	
		
			
				|  |  |         $this->registerEvent('moxlerror', 'onMoxlError'); |  |  |  | 
		
	
		
			
				|  |  |  |  |  |         /*$this->registerEvent('pubsuberror', 'onPubsubError'); | 
		
	
		
			
				|  |  |  |  |  |         $this->registerEvent('moxlerror', 'onMoxlError');*/ | 
		
	
		
			
				|  |  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |     /** | 
		
	
		
			
				|  |  |  |  |  |      * @brief Notify something | 
		
	
		
			
				|  |  |  |  |  |      * | 
		
	
		
			
				|  |  |  |  |  |      * @param string $key The key to group the notifications | 
		
	
		
			
				|  |  |  |  |  |      * @param string $title The displayed title | 
		
	
		
			
				|  |  |  |  |  |      * @param string $body The displayed body | 
		
	
		
			
				|  |  |  |  |  |      * @param string $body The displayed URL | 
		
	
		
			
				|  |  |  |  |  |      * @param integer $time The displayed time (in secondes) | 
		
	
		
			
				|  |  |  |  |  |      * @param integer $action An action | 
		
	
		
			
				|  |  |  |  |  |      * @return void | 
		
	
		
			
				|  |  |  |  |  |      */     | 
		
	
		
			
				|  |  |  |  |  |     static function append($key = null, $title, $body = null, $picture = null, $time = 2, $action = null) | 
		
	
		
			
				|  |  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |  |         // In this case we have an action confirmation
 | 
		
	
		
			
				|  |  |  |  |  |         if($key == null) { | 
		
	
		
			
				|  |  |  |  |  |             RPC::call('Notification.toast', $title); | 
		
	
		
			
				|  |  |  |  |  |             return; | 
		
	
		
			
				|  |  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |  |          | 
		
	
		
			
				|  |  |  |  |  |         $session = Session::start(); | 
		
	
		
			
				|  |  |  |  |  |         $notifs = $session->get('notifs'); | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         if($notifs == null) $notifs = array(); | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         $first = reset(explode('|', $key)); | 
		
	
		
			
				|  |  |  |  |  |         if(array_key_exists($first, $notifs)) { | 
		
	
		
			
				|  |  |  |  |  |             $notifs[$first]++; | 
		
	
		
			
				|  |  |  |  |  |         } else { | 
		
	
		
			
				|  |  |  |  |  |             $notifs[$first] = 1; | 
		
	
		
			
				|  |  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         RPC::call('Notification.counter', $first, $notifs[$first]); | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         if(array_key_exists($key, $notifs)) { | 
		
	
		
			
				|  |  |  |  |  |             $notifs[$key]++; | 
		
	
		
			
				|  |  |  |  |  |         } else { | 
		
	
		
			
				|  |  |  |  |  |             $notifs[$key] = 1; | 
		
	
		
			
				|  |  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         RPC::call('Notification.counter', $key, $notifs[$key]); | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         $n = new Notification; | 
		
	
		
			
				|  |  |  |  |  |         RPC::call('Notification.snackbar', $n->prepareSnackbar($title, $body, $picture), $time); | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         $session->set('notifs', $notifs); | 
		
	
		
			
				|  |  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |     function ajaxClear($key) | 
		
	
		
			
				|  |  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |  |         $session = Session::start(); | 
		
	
		
			
				|  |  |  |  |  |         $notifs = $session->get('notifs'); | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         if($notifs != null && array_key_exists($key, $notifs)) { | 
		
	
		
			
				|  |  |  |  |  |             $counter = $notifs[$key]; | 
		
	
		
			
				|  |  |  |  |  |             unset($notifs[$key]); | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |             RPC::call('Notification.counter', $key, ''); | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |             $first = reset(explode('|', $key)); | 
		
	
		
			
				|  |  |  |  |  |             if(array_key_exists($first, $notifs)) { | 
		
	
		
			
				|  |  |  |  |  |                 $notifs[$first] = $notifs[$first] - $counter; | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |                 if($notifs[$first] <= 0) { | 
		
	
		
			
				|  |  |  |  |  |                     unset($notifs[$first]); | 
		
	
		
			
				|  |  |  |  |  |                     RPC::call('Notification.counter', $first, ''); | 
		
	
		
			
				|  |  |  |  |  |                 } else { | 
		
	
		
			
				|  |  |  |  |  |                     RPC::call('Notification.counter', $first, $notifs[$first]); | 
		
	
		
			
				|  |  |  |  |  |                 } | 
		
	
		
			
				|  |  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         $session->set('notifs', $notifs); | 
		
	
		
			
				|  |  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |     function ajaxGet() | 
		
	
		
			
				|  |  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |  |         $session = Session::start(); | 
		
	
		
			
				|  |  |  |  |  |         $notifs = $session->get('notifs'); | 
		
	
		
			
				|  |  |  |  |  |         if($notifs != null) RPC::call('Notification.refresh', $notifs); | 
		
	
		
			
				|  |  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |     function prepareSnackbar($title, $body = false, $picture = false) | 
		
	
		
			
				|  |  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |  |         $view = $this->tpl(); | 
		
	
		
			
				|  |  |  |  |  |          | 
		
	
		
			
				|  |  |  |  |  |         $view->assign('title', $title); | 
		
	
		
			
				|  |  |  |  |  |         $view->assign('body', $body); | 
		
	
		
			
				|  |  |  |  |  |         $view->assign('picture', $picture); | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |         return $view->draw('_notification', true); | 
		
	
		
			
				|  |  |     } |  |  |     } | 
		
	
		
			
				|  |  |      |  |  |      | 
		
	
		
			
				|  |  |  |  |  |     /* | 
		
	
		
			
				|  |  |     static function appendNotification($message, $type = 'info') |  |  |     static function appendNotification($message, $type = 'info') | 
		
	
		
			
				|  |  |     { |  |  |     { | 
		
	
		
			
				|  |  |         $id = md5($message.$type); |  |  |         $id = md5($message.$type); | 
		
	
	
		
			
				|  | @ -48,13 +122,13 @@ class Notification extends WidgetCommon | 
		
	
		
			
				|  |  |             default: |  |  |             default: | 
		
	
		
			
				|  |  |                 $icon = 'fa-info-circle'; |  |  |                 $icon = 'fa-info-circle'; | 
		
	
		
			
				|  |  |                 break; |  |  |                 break; | 
		
	
		
			
				|  |  |         } |  |  |  | 
		
	
		
			
				|  |  |  |  |  |         }*/ | 
		
	
		
			
				|  |  |          |  |  |          | 
		
	
		
			
				|  |  |         /*$html = ' |  |  |         /*$html = ' | 
		
	
		
			
				|  |  |             <div class="notif notificationAnim '.$type.'" id="'.$id.'"> |  |  |             <div class="notif notificationAnim '.$type.'" id="'.$id.'"> | 
		
	
		
			
				|  |  |                 <i class="fa '.$icon.'"></i> '.$message.' |  |  |                 <i class="fa '.$icon.'"></i> '.$message.' | 
		
	
		
			
				|  |  |             </div>';*/ |  |  |             </div>';*/ | 
		
	
		
			
				|  |  |         $html = $message; |  |  |  | 
		
	
		
			
				|  |  |  |  |  |     /*    $html = $message; | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  |         RPC::call('removeDiff', 'toast', $html, $id); |  |  |         RPC::call('removeDiff', 'toast', $html, $id); | 
		
	
		
			
				|  |  |     } |  |  |     } | 
		
	
	
		
			
				|  | @ -65,5 +139,5 @@ class Notification extends WidgetCommon | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  |     function onMoxlError($arr) { |  |  |     function onMoxlError($arr) { | 
		
	
		
			
				|  |  |         Notification::appendNotification($arr[1], 'error'); |  |  |         Notification::appendNotification($arr[1], 'error'); | 
		
	
		
			
				|  |  |     } |  |  |  | 
		
	
		
			
				|  |  |  |  |  |     }*/ | 
		
	
		
			
				|  |  | } |  |  | } |