public function testGetNotification() { $SofortLibNotification = new Notification(); $statusNotification = ''; $this->assertFalse($SofortLibNotification->getNotification($statusNotification)); $statusNotification = '<?xml version="1.0" encoding="UTF-8"?> <status_notification> <transaction>1324-1234-5483-4891</transaction> <time>2010-04-14T19:01:08+02:00</time> </status_notification>'; $notification = '1324-1234-5483-4891'; $this->assertEquals($notification, $SofortLibNotification->getNotification($statusNotification)); $statusNotification = '<?xml version="1.0" encoding="UTF-8"?> <status_test> <transaction>1324-1234-5483-4891</transaction> <time>2010-04-14T19:01:08+02:00</time> </status_test>'; $this->assertFalse($SofortLibNotification->getNotification($statusNotification)); $statusNotification = '<?xml version="1.0" encoding="UTF-8"?> <status_notification> <nontransaction>1324-1234-5483-4891</nontransaction> <time>2010-04-14T19:01:08+02:00</time> </status_notification>'; $this->assertFalse($SofortLibNotification->getNotification($statusNotification)); }
function plugin_typology_uninstall() { global $DB; // Plugin tables deletion $tables = array("glpi_plugin_typology_profiles", "glpi_plugin_typology_typologies", "glpi_plugin_typology_typologycriterias", "glpi_plugin_typology_typologycriteriadefinitions", "glpi_plugin_typology_typologies_items"); foreach ($tables as $table) { $DB->query("DROP TABLE IF EXISTS `{$table}`;"); } // Plugin adding information on general table deletion $tables_glpi = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs"); foreach ($tables_glpi as $table_glpi) { $DB->query("DELETE FROM `{$table_glpi}` WHERE `itemtype` = 'PluginTypologyTypology';"); } //drop rules $Rule = new Rule(); $a_rules = $Rule->find("`sub_type`='PluginTypologyRuleTypology'"); foreach ($a_rules as $data) { $Rule->delete($data); } $notif = new Notification(); $options = array('itemtype' => 'PluginTypologyTypology', 'event' => 'AlertNotValidatedTypology', 'FIELDS' => 'id'); foreach ($DB->request('glpi_notifications', $options) as $data) { $notif->delete($data); } return true; }
/** * Fire this notification on given comment object * * @param type $comment */ public static function fire($comment) { $targetCreatorId = $comment->content->user_id; // gets also an new comment notification // Get Users which are also commented this model $userIds = array(); $otherComments = Comment::model()->findAllByAttributes(array('object_model' => $comment->object_model, 'object_id' => $comment->object_id)); foreach ($otherComments as $otherComment) { if ($comment->created_by != $otherComment->created_by && $otherComment->created_by != $targetCreatorId) { $userIds[] = $otherComment->created_by; } } $userIds = array_unique($userIds); // Write new Notification for them foreach ($userIds as $userId) { $notification = new Notification(); $notification->class = "AlsoCommentedNotification"; $notification->user_id = $userId; $notification->space_id = $comment->space_id; $notification->source_object_model = "Comment"; $notification->source_object_id = $comment->id; $notification->target_object_model = $comment->object_model; $notification->target_object_id = $comment->object_id; $notification->save(); } }
/** * Remove mreporting notifications from GLPI. * * @return array 'success' => true on success */ static function uninstall() { global $DB; $queries = array(); // Remove NotificationTargets and Notifications $notification = new Notification(); $result = $notification->find("itemtype = 'PluginMreportingNotification'"); foreach ($result as $row) { $notification_id = $row['id']; $queries[] = "DELETE FROM glpi_notificationtargets \n WHERE notifications_id = " . $notification_id; $queries[] = "DELETE FROM glpi_notifications \n WHERE id = " . $notification_id; } // Remove NotificationTemplateTranslations and NotificationTemplates $template = new NotificationTemplate(); $result = $template->find("itemtype = 'PluginMreportingNotification'"); foreach ($result as $row) { $template_id = $row['id']; $queries[] = "DELETE FROM glpi_notificationtemplatetranslations \n WHERE notificationtemplates_id = " . $template_id; $queries[] = "DELETE FROM glpi_notificationtemplates \n WHERE id = " . $template_id; } foreach ($queries as $query) { $DB->query($query); } return array('success' => true); }
public function execute(&$params) { $options =& $this->config['options']; $notif = new Notification(); $notif->user = $this->parseOption('user', $params); $notif->createdBy = 'API'; $notif->createDate = time(); // file_put_contents('triggerLog.txt',"\n".$notif->user,FILE_APPEND); // if($this->parseOption('type',$params) == 'auto') { // if(!isset($params['model'])) // return false; // $notif->modelType = get_class($params['model']); // $notif->modelId = $params['model']->id; // $notif->type = $this->getNotifType(); // } else { $notif->type = 'custom'; $notif->text = $this->parseOption('text', $params); // } if ($notif->save()) { return array(true, ""); } else { $errors = $notif->getErrors(); return array(false, array_shift($errors)); } }
public function getLatestNotificationsAndCounts($userId) { $notification = new Notification(); $listUnread = $notification->Find("toUser = ? and status = ?", array($userId, 'Unread')); $unreadCount = count($listUnread); $limit = $unreadCount < 10 ? 10 : $unreadCount; $list = $notification->Find("toUser = ? order by time desc limit ?", array($userId, $limit)); $newList = array(); $fs = new FileService(); foreach ($list as $noti) { if ($noti->fromEmployee > 0) { $employee = $this->baseService->getElement('Employee', $noti->fromEmployee, null, true); if (!empty($employee)) { $employee = $fs->updateEmployeeImage($employee); $noti->image = $employee->image; if (empty($noti->image)) { if ($employee->gender == 'Male') { $noti->image = BASE_URL . "images/user_male.png"; } else { $noti->image = BASE_URL . "images/user_female.png"; } } $newList[] = $noti; } } else { $noti->image = BASE_URL . "images/icehrm.png"; $newList[] = $noti; } } return array($unreadCount, $list); }
function check_writable_relative($dir) { $uid = posix_getuid(); $gid = posix_getgid(); $user_info = posix_getpwuid($uid); $user = $user_info['name']; $group_info = posix_getgrgid($gid); $group = $group_info['name']; $fix_cmd = '. ' . _("To fix that, execute following commands as root") . ':<br><br>' . "cd " . getcwd() . "<br>" . "mkdir -p {$dir}<br>" . "chown {$user}:{$group} {$dir}<br>" . "chmod 0700 {$dir}"; if (!is_dir($dir)) { $config_nt = array('content' => _("Required directory " . getcwd() . "{$dir} does not exist") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); exit; } if (!($stat = stat($dir))) { $config_nt = array('content' => _("Could not stat configs dir") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); exit; } // 2 -> file perms (must be 0700) // 4 -> uid (must be the apache uid) // 5 -> gid (must be the apache gid) if ($stat[2] != 16832 || $stat[4] !== $uid || $stat[5] !== $gid) { $config_nt = array('content' => _("Invalid perms for configs dir") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); exit; } }
/** * Fires this notification * * @param type $like */ public static function fire($like) { // Determine Space Id if exists $spaceId = ""; if ($like->content->container instanceof Space) { $spaceId = $like->content->container->id; } // Determine who created the liked content / content addon $createdBy = ""; if ($like->source instanceof HActiveRecordContent) { $createdBy = $like->source->content->created_by; } elseif ($like->source instanceof HActiveRecordContentAddon) { $createdBy = $like->source->created_by; } if ($createdBy != "" && $createdBy != $like->created_by) { // Send Notification to owner $notification = new Notification(); $notification->class = "NewLikeNotification"; $notification->user_id = $createdBy; $notification->space_id = $spaceId; $notification->source_object_model = "Like"; $notification->source_object_id = $like->id; $notification->target_object_model = $like->object_model; $notification->target_object_id = $like->object_id; $notification->save(); } }
function display_errors($info_error) { $errors = implode("</div><div style='padding-top: 3px;'>", $info_error); $error_msg = "<div>" . _("The following errors occurred:") . "</div><div style='padding-left: 15px;'><div>{$errors}</div></div>"; $config_nt = array('content' => $error_msg, 'options' => array('type' => 'nf_error', 'cancel_button' => FALSE), 'style' => 'width: 90%; margin: 20px auto; padding: 10px 0px; text-align: left; font-style: italic'); $nt = new Notification('nt_1', $config_nt); return $nt->show(FALSE); }
public static function createForUserRecord(User $user, PathRecord $record) { $notify = new Notification(); $notify->user_id = $user->id; $notify->path_record_id = $record->id; $notify->save(); return $notify; }
/** * Creates a by $type parameter specified message * * @param string $type * @param string $message * * @return Notification */ private function createMessageObject(string $type, string $message) : Notification { $msg = new Notification(); $msg->setType($type); $msg->setMessage($message); $this->handler->add($msg); return $msg; }
/** * Send the given notification with Apple Push Notification Service Server. * * @param Notification $notification the notification to send * @return boolean true on success, false if there was an error. */ public function send($notification) { $config = Config::getInstance(); $appRoot = $config->getString('appRootDir'); // Instanciate a new ApnsPHP_Push object, with the provider certificate $push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, $appRoot . $config->getString('monitoring/notification/push/providerCertificateDir')); // Set custom logger $push->setLogger(new ApnsPHP_Log_Fruition()); // Set the Provider Certificate passphrase $push->setProviderCertificatePassphrase($config->getString('monitoring/notification/push/passphrase')); // Set the Root Certificate Autority to verify the Apple remote peer $push->setRootCertificationAuthority($appRoot . $config->getString('monitoring/notification/push/rootCertificateAuthorityDir')); // Get recipient list. If no registration id (user did not connect to the // mobile app, we stop the process $stringRecipients = $notification->getRecipient(); if (empty($stringRecipients)) { Logger::info("No registration id was found. The notification is not sent."); return false; } // Connect to the Apple Push Notification Service $push->connect(); // Create a message for each device $message = new ApnsPHP_Message(); $message->setText($notification->getContent()); $message->setSound(); $message->setExpiry(30); // 60 seconds $recipientList = explode(",", $notification->getRecipient()); foreach ($recipientList as $registrationId) { $message->addRecipient($registrationId); } // Add the message to the message queue $push->add($message); // Send all messages in the message queue $push->send(); // Disconnect from the Apple Push Notification Service $push->disconnect(); // Examine the error message container. $aErrorQueue = $push->getErrors(); if (!empty($aErrorQueue)) { foreach ($aErrorQueue as $error) { foreach ($error['ERRORS'] as $err) { //For statusCode = 8, which is Invalid Token, we delete the token. if ($err['statusCode'] == self::INVALID_TOKEN) { if ($this->handlerErrorCallBack) { $token = $error['MESSAGE']->getRecipient(); call_user_func($this->handlerErrorCallBack, $token); } } Logger::error("Sending push notification failed. Error code: " . $err['statusCode'] . ". Message: " . $err['statusMessage']); } } return false; } //If success Logger::info("Notification sent with device token " . $notification->getRecipient()); return true; }
public function getLatestNotificationsAndCounts($userId) { $notification = new Notification(); $listUnread = $notification->Find("toUser = ? and status = ?", array($userId, 'Unread')); $unreadCount = count($listUnread); $limit = $unreadCount < 20 ? 20 : $unreadCount; $list = $notification->Find("toUser = ? order by time desc limit ?", array($userId, $limit)); return array($unreadCount, $list); }
function show_notification($msg, $type = 'nf_error') { echo "<div class='container' style='width:100%;height:30px;margin:10px auto;text-align:center'>"; $config_nt = array('content' => $msg, 'options' => array('type' => $type, 'cancel_button' => FALSE), 'style' => ' margin:0 auto;text-align:center;'); $nt = new Notification('nt_panel', $config_nt); $nt->show(); echo "</div>"; die; }
/** * A method to check whether a user is allowed to remove a notification * In particular, if it's the student who created the notification, only a supervisor can * remove it from the list (it is necessary for the supervisor to see every student action) * @param Notification $notif the notification object */ private function checkAuthCreatedByStudent(Notification $notif) { # If it's the student who created the notification, only a supervisor can # remove it from the list (it is necessary for the supervisor to see every student action) $creatorUserType = $this->model('User', $notif->getCreatorUserId())->getType(); if ($creatorUserType == User::USER_TYPE_STUDENT && HTTPSession::getInstance()->USER_TYPE != User::USER_TYPE_SUPERVISOR) { header('Location: ' . SITE_URL . 'notifications'); } }
public function downloadDismiss(Notification $notification) { $user = Auth::user(); if ($notification->user_id !== $user->id) { App::abort(403, 'That notification doesn\'t belong to you'); } $notification->dismiss(); $path = $notification->pathRecord->getPath(); return $this->download($path); }
public function unfollow($id) { $sql = 'delete from followers where user_id = ' . (int) $id . ' and follower_id = ' . $this->id; $query = $this->db->query($sql); $notification = new Notification(); $notification->text = 'Používateľ ' . $this->nick . ' vás prestal sledovať!'; $notification->user_id = (int) $id; $notification->link = 'uzivatel/' . $this->id; $notification->save(); }
function notify_and_die($msg, $db) { $config_nt = array('content' => $msg, 'options' => array('type' => 'nf_error', 'cancel_button' => ''), 'style' => ' margin:25px auto 0 auto;text-align:center;padding:3px 30px;'); $nt = new Notification('nt_panel', $config_nt); $nt->show(); if (is_object($db)) { $db->close(); } die; }
public function set($fields = array()) { if (!$this->_db->insert('posts', $fields)) { throw new Exception('There was a problem posting'); } $notification = new Notification(); $timestamp = date('Y-m-d H:i:s'); $notification->set(array('uid' => $fields['uid'], 'fid' => $fields['fid'], 'type' => 'new_post', 'timestamp' => $timestamp)); $notification->set(array('uid' => $fields['fid'], 'fid' => $fields['uid'], 'type' => 'posted', 'timestamp' => $timestamp)); }
function check_deploy_perms() { if (!Session::am_i_admin()) { $config_nt = array('content' => _("You do not have permission to see this section"), 'options' => array('type' => 'nf_error', 'cancel_button' => false), 'style' => 'width: 60%; margin: 30px auto; text-align:center;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); die; } return true; }
public static function fire($user_follow) { $notification = new Notification(); $notification->class = "FollowNotification"; $notification->user_id = $user_follow->object_id; $notification->source_object_model = "UserFollow"; $notification->source_object_id = $user_follow->id; $notification->target_object_model = $user_follow->object_model; $notification->target_object_id = $user_follow->user_id; $notification->save(); }
/** * Create new mock connection for testing exceptions * * @param string $responseData Binary response package * @return \Apple\ApnPush\Notification\Notification */ protected function createNotification($responseData) { $connectionMock = $this->getMock('Apple\\ApnPush\\Notification\\Connection', array('is', 'isReadyRead', 'write', 'read', 'create')); $connectionMock->expects($this->any())->method('isReadyRead')->will($this->returnValue(true)); $connectionMock->expects($this->any())->method('read')->with(6)->will($this->returnValue($responseData)); $notification = new Notification(); $payload = new PayloadFactory(); $notification->setConnection($connectionMock); $notification->setPayloadFactory($payload); return $notification; }
function save_notification($fields, $is_new = true) { $notification = new Notification(); $notification->id = $fields['id']; $notification->message = $fields['message']; $notification->category = $fields['category']; $notification->display_type = $fields['type']; $notification->read = $fields['read']; $notification->is_new = $is_new; $result = $notification->save(); return $this->status($result); }
private static function getType(\Notification $n) { switch ($n->getType()) { case NotifyUI::SUCCESS: return 'SUCCESS'; case NotifyUI::ERROR: return 'ERROR'; case NotifyUI::WARNING: return 'WARNING'; default: return 'UNKNOWN'; } }
private static function getType(Notification $n) { switch ($n->getType()) { case INTERN_SUCCESS: return 'SUCCESS'; case INTERN_ERROR: return 'ERROR'; case INTERN_WARNING: return 'WARNING'; default: return 'UNKNOWN'; } }
public static function fire($invitorUserId, $invitedUser, $room) { // Send Notification to owner $notification = new Notification(); $notification->class = "RoomInviteDeclinedNotification"; $notification->user_id = $invitorUserId; $notification->space_id = $room->id; $notification->source_object_model = "User"; $notification->source_object_id = $invitedUser->id; $notification->target_object_model = "Room"; $notification->target_object_id = $room->id; $notification->save(); }
public static function fire($invitorUserId, $invitedUser, $space) { // Send Notification to owner $notification = new Notification(); $notification->class = "SpaceInviteAcceptedNotification"; $notification->user_id = $invitorUserId; $notification->space_id = $space->id; $notification->source_object_model = "User"; $notification->source_object_id = $invitedUser->id; $notification->target_object_model = "Space"; $notification->target_object_id = $space->id; $notification->save(); }
/** * Fires this notification * * @param Album $like */ public static function fire($album) { foreach ($album->owner->getFollowers(null, true) as $user) { $notification = new Notification(); $notification->class = "AlbumNotification"; $notification->user_id = $user->id; $notification->source_object_model = "Album"; $notification->source_object_id = $album->id; $notification->target_object_model = 'Album'; $notification->target_object_id = $album->id; $notification->save(); } }
public static function fire($approverUserId, $requestor, $workspace) { // Send Notification to owner $notification = new Notification(); $notification->class = "SpaceApprovalRequestDeclinedNotification"; $notification->user_id = $requestor->id; $notification->space_id = $workspace->id; $notification->source_object_model = "User"; $notification->source_object_id = $approverUserId; $notification->target_object_model = "Space"; $notification->target_object_id = $workspace->id; $notification->save(); }
public function sendNotification(Notification $notification, $notifiers = array()) { if (!empty($notifiers)) { $notifiers = array_filter($this->notifiers, function ($notifier) use($notifiers) { return in_array($notifier->getNotifierKey(), $notifiers); }); } else { $notifiers = $this->notifiers; } foreach ($notifiers as $notifier) { $notifier->notify($notification->getUser(), $notification->getView(), $notification->getViewData(), $notification->getSubject()); } }