EGroupware /
egroupware
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * EGroupware - Notifications Java Desktop App |
||
| 4 | * |
||
| 5 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
||
| 6 | * @package notifications |
||
| 7 | * @subpackage jdesk |
||
| 8 | * @link http://www.egroupware.org |
||
| 9 | * @author Stefan Werfling <[email protected]>, Maik H�ttner <[email protected]> |
||
| 10 | */ |
||
| 11 | |||
| 12 | use EGroupware\Api; |
||
| 13 | |||
| 14 | class notifications_jpopup implements notifications_iface |
||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Appname |
||
| 19 | */ |
||
| 20 | const _appname = 'notifications'; |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 21 | |||
| 22 | /** |
||
| 23 | * Notification table in SQL database |
||
| 24 | */ |
||
| 25 | const _notification_table = 'egw_notificationpopup'; |
||
|
0 ignored issues
–
show
|
|||
| 26 | |||
| 27 | /** |
||
| 28 | * Notification type |
||
| 29 | */ |
||
| 30 | const _type = 'jpopup'; |
||
|
0 ignored issues
–
show
|
|||
| 31 | |||
| 32 | /** |
||
| 33 | * holds account object for user who sends the message |
||
| 34 | * |
||
| 35 | * @var object |
||
| 36 | */ |
||
| 37 | private $sender; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * holds account object for user to notify |
||
| 41 | * |
||
| 42 | * @var object |
||
| 43 | */ |
||
| 44 | private $recipient; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * holds config object (sitewide application config) |
||
| 48 | * |
||
| 49 | * @var object |
||
| 50 | */ |
||
| 51 | private $config; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * holds preferences object of user to notify |
||
| 55 | * |
||
| 56 | * @var object |
||
| 57 | */ |
||
| 58 | private $preferences; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * holds db object of SQL database |
||
| 62 | * |
||
| 63 | * @var Api\Db |
||
| 64 | */ |
||
| 65 | private $db; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * constructor of notifications_egwpopup |
||
| 69 | * |
||
| 70 | * @param object $_sender |
||
| 71 | * @param object $_recipient |
||
| 72 | * @param object $_config |
||
| 73 | * @param object $_preferences |
||
| 74 | */ |
||
| 75 | public function __construct($_sender, $_recipient, $_config = null, $_preferences = null) |
||
| 76 | { |
||
| 77 | if( !is_object($_sender) ) { throw new Exception("no sender given."); } |
||
| 78 | if( !is_object($_recipient) ) { throw new Exception("no recipient given."); } |
||
| 79 | |||
| 80 | $this->sender = $_sender; |
||
| 81 | $this->recipient = $_recipient; |
||
| 82 | $this->config = $_config; |
||
| 83 | $this->preferences = $_preferences; |
||
| 84 | $this->db = $GLOBALS['egw']->db; |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * sends notification if user is online |
||
| 89 | * |
||
| 90 | * @param array $_messages |
||
| 91 | * @param string $_subject |
||
| 92 | * @param array $_links |
||
| 93 | * @param array $_attachments |
||
| 94 | * @param array $_data |
||
| 95 | */ |
||
| 96 | public function send(array $_messages, $_subject=false, $_links=false, $_attachments=false, $_data = false) |
||
| 97 | { |
||
| 98 | unset($_attachments, $_data); // not used |
||
| 99 | |||
| 100 | $jmessage = array(); |
||
| 101 | |||
| 102 | // app-message |
||
| 103 | if( ($_links != null) && (count($_links) > 0) ) |
||
| 104 | { |
||
| 105 | $tlink = $_links[0]; |
||
| 106 | $appname = ""; |
||
| 107 | |||
| 108 | if( key_exists('menuaction', $tlink->view) ) |
||
| 109 | { |
||
| 110 | $tmp = explode(".", $tlink->view['menuaction']); |
||
| 111 | $appname = $tmp[0]; |
||
| 112 | } |
||
| 113 | |||
| 114 | $link = array(); |
||
| 115 | |||
| 116 | foreach( $tlink->view as $pkey => $pvalue ) |
||
| 117 | { |
||
| 118 | $link[] = $pkey . '=' . $pvalue; |
||
| 119 | } |
||
| 120 | |||
| 121 | // TODO more links? |
||
| 122 | $jmessage['link'] = implode("&", $link); |
||
| 123 | } |
||
| 124 | |||
| 125 | $message = $this->render_infos($_subject) |
||
| 126 | .Api\Html::hr() |
||
| 127 | .$_messages['html']; |
||
| 128 | |||
| 129 | $jmessage['msghtml'] = $message; |
||
| 130 | $jmessage['app'] = $appname; |
||
| 131 | |||
| 132 | |||
| 133 | $this->save( serialize($jmessage) ); |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * renders additional infos from sender and subject |
||
| 138 | * |
||
| 139 | * @param string $_subject |
||
| 140 | * @return string html rendered info as complete string |
||
| 141 | */ |
||
| 142 | private function render_infos($_subject = false) { |
||
| 143 | $infos = array(); |
||
| 144 | $newline = "<br />"; |
||
| 145 | |||
| 146 | $sender = $this->sender->account_fullname ? $this->sender->account_fullname : $this->sender_account_email; |
||
|
0 ignored issues
–
show
|
|||
| 147 | $infos[] = lang('Message from').': '.$sender; |
||
| 148 | if(!empty($_subject)) { $infos[] = Api\Html::bold($_subject); } |
||
| 149 | return implode($newline,$infos); |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * saves notification into database so that the client can fetch it from there |
||
| 154 | * |
||
| 155 | * @param string $_message |
||
| 156 | * @param array $_user_sessions |
||
| 157 | */ |
||
| 158 | private function save( $_message ) { |
||
| 159 | $result = $this->db->insert( self::_notification_table, array( |
||
| 160 | 'account_id' => $this->recipient->account_id, |
||
| 161 | 'notify_message' => $_message, |
||
| 162 | 'notify_type' => self::_type |
||
| 163 | ), false,__LINE__,__FILE__,self::_appname); |
||
| 164 | if ($result === false) throw new Exception("Can't save notification into SQL table"); |
||
|
0 ignored issues
–
show
|
|||
| 165 | } |
||
| 166 | } |
||
| 167 |