public function create($request) { $params = $request->getParameters(); $params['force_push'] = Session::get()->isAdmin() ? $params['force_push'] : 0; if (isset($params['type'])) { switch ($params['type']) { case 'private': StaffNotification::createNotif('private', Session::get()->id, $params['to'], $params['content'], $params['level'], 'team_or_more', $params['force_push']); return new JsonResponse(['success' => true]); break; case 'broadcast': StaffNotification::createNotif('broadcast', Session::get()->id, null, $params['content'], $params['level'], 'team_or_more', $params['force_push']); return new JsonResponse(['success' => true]); break; } } else { $notif = new PushBulletNotification('Dreamvids', "Test de notification !", [Session::get()->details->push_bullet_email]); $notif->send(); } }
public static function createNotif($type, $id_one = null, $id_two = null, $value = null, $level = '', $viewers = 'team_or_more', $force_push = false) { $staff_notif = StaffNotification::create(['type' => $type, 'id_one' => $id_one, 'id_two' => $id_two, 'value' => $value, 'viewers' => $viewers, 'level' => $level, 'timestamp' => Utils::tps()]); $emails = []; $title = 'DreamVids'; $sub_title = ''; $is_link = !is_null($staff_notif->getLink()); $link_url = "http://" . @$_SERVER['HTTP_HOST'] . WEBROOT . $staff_notif->getLink(); foreach (User::getTeam() as $user) { $content = $staff_notif->getContent(); if (Utils::getRankArray($user)[$viewers] && (self::isEnabled($user) || $force_push)) { if (!is_null($user->details->push_bullet_email) && $user->details->push_bullet_email != '') { switch ($type) { case 'ticket_level_change': $ticket = $staff_notif->getAssociatedValue('Ticket'); $sub_title = 'Tickets'; if (in_array($ticket->ticket_levels_id, $user->getAssignedLevelsIds()) || $user->isAdmin()) { $emails[] = $user->details->push_bullet_email; } break; case 'ticket': $sub_title = 'Tickets'; $emails[] = $user->details->push_bullet_email; break; case 'news': $sub_title = 'News'; $emails[] = $user->details->push_bullet_email; break; case 'private': $sub_title = "Message privé"; $content = $staff_notif->value; if ($staff_notif->id_two == $user->id) { $emails[] = $user->details->push_bullet_email; } break; case 'private': $sub_title = "Message"; $content = $staff_notif->value; $emails[] = $user->details->push_bullet_email; break; default: $emails[] = $user->details->push_bullet_email; break; } } } } $notif = new PushBulletNotification($title . ($sub_title != '' ? ' - ' . $sub_title : ''), $content, $emails, $is_link, $link_url); $notif->send(); }