Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-tharwat committed Nov 4, 2021
1 parent a0aebd4 commit 160317d
Show file tree
Hide file tree
Showing 18 changed files with 425 additions and 86 deletions.
19 changes: 12 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"



DEFAULT_IMAGE=
DEFAULT_FAVICON=
DEFAULT_AVATAR=
DEFAULT_LOGO=
DEFAULT_WIDE_LOGO=
DEFAULT_COVER=
#########

DEFAULT_IMAGE="${APP_URL}/images/default/image.jpg"
DEFAULT_IMAGE_FAVICON="${APP_URL}/images/default/favicon.png"
DEFAULT_IMAGE_AVATAR="${APP_URL}/images/default/avatar.png"
DEFAULT_IMAGE_LOGO="${APP_URL}/images/default/logo.png"
DEFAULT_IMAGE_WIDELOGO="${APP_URL}/images/default/wide-logo.png"
DEFAULT_IMAGE_COVER="${APP_URL}/images/default/cover.png"
DEFAULT_IMAGE_NOTIFICATION="${APP_URL}/images/default/notification.png"

DEFAULT_EMAIL=[email protected]
DEFAULT_PASSWORD=password
33 changes: 33 additions & 0 deletions app/Helpers/MainHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
// This class file to define all general functions
namespace App\Helpers;

class MainHelper {


public function notify_user(
$options=[]
){
$options = array_merge([
'user_id'=>1,
'message'=>"",
'url'=>"",
'methods'=>['database'],
'image'=>"",
'btn_text'=>"عرض الإشعار"
],$options);
$user = \App\Models\User::where('id',$options['user_id'])->first();
if($user!=null){
\App\Models\User::where('email', $user->email )->first()->notify(
new \App\Notifications\GeneralNotification([
'content'=>[$options['message']],
'url'=>$options['url'],
'btn_text'=>$options['btn_text'],
'methods'=>$options['methods'],
'image'=>$options['image']
])
);
}
}

}
25 changes: 2 additions & 23 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@ public function index(Request $request)
{
return view('admin.index');
}
public function upload_image(Request $request){

$file = $this->store_file([
'source'=>$request->upload,
'validation'=>"image",
'path_to_save'=>'/uploads/images/',
'type'=>'IMAGE',
'user_id'=>\Auth::user()->id,
'resize'=>[500,1000],
'small_path'=>'small/',
'visibility'=>'PUBLIC',
'file_system_type'=>env('FILESYSTEM_DRIVER'),
/*'watermark'=>true,*/
'compress'=>'auto'
]);
return [
'fileName'=>$file['filename'],
'uploaded'=>1,
'url'=>env('STORAGE_URL')."/uploads/images/".$file['filename'] ];
}
public function seen_notifications(Request $request){
auth()->user()->unreadNotifications->markAsRead();
}


}
29 changes: 29 additions & 0 deletions app/Http/Controllers/HelperController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HelperController extends Controller
{
public function upload_image(Request $request){

$file = $this->store_file([
'source'=>$request->upload,
'validation'=>"image",
'path_to_save'=>'/uploads/images/',
'type'=>'IMAGE',
'user_id'=>\Auth::user()->id,
'resize'=>[500,1000],
'small_path'=>'small/',
'visibility'=>'PUBLIC',
'file_system_type'=>env('FILESYSTEM_DRIVER'),
/*'watermark'=>true,*/
'compress'=>'auto'
]);
return [
'fileName'=>$file['filename'],
'uploaded'=>1,
'url'=>env('STORAGE_URL')."/uploads/images/".$file['filename'] ];
}
}
36 changes: 36 additions & 0 deletions app/Http/Controllers/NotificationsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\View\Components\Notifications as NotificationComponent;
class NotificationsController extends Controller
{
public function notifications_see(Request $request){
session(['seen_notifications'=>0]);
auth()->user()->unreadNotifications->markAsRead();
}

public function notifications_ajax(Request $request){

$notifications = \Auth::user()->notifications()->limit(15)->get();
$not_response = array(
'response' => (new NotificationComponent($notifications))->render(1),
'count_unseen_notifications' => intval($notifications->whereNull('read_at')->count()),
);
$data = [
'notifications' => [
'response' => $not_response,
'counter_session' => intval(session('seen_notifications')),
],
'alert' => false,
];

if ($data['notifications']['counter_session'] < $not_response['count_unseen_notifications'])
$data['alert'] = true;

session(['seen_notifications' => $not_response['count_unseen_notifications']]);
return $data;
}

}
17 changes: 17 additions & 0 deletions app/Http/Controllers/TestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
public function index(Request $request)
{
(new \MainHelper)->notify_user([
'user_id'=>1,
'message'=>"هذا النص هو مثال لنص يمكن أن يستبدل في نفس المساحة، لقد تم توليد هذا النص من مولد النص العربى، حيث يمكنك أن تولد مثل هذا النص أو العديد من النصوص الأخرى إضافة إلى زيادة عدد الحروف التى يولدها التطبيق.",
'url'=>env("APP_URL"),
]);
}
}
61 changes: 61 additions & 0 deletions app/Notifications/GeneralNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;

class GeneralNotification extends Notification implements ShouldQueue
{
use Queueable;
public $tries = 2;
public $timeout = 10;

public $inline_content;
public $action_url;
public $btn_text;
public $methods;
public $image;




public function __construct($options=[]){

$this->inline_content= implode("\n",$options['content']);
$this->action_url=$options['url'];
$this->btn_text=$options['btn_text'];
$this->methods=$options['methods'];
$this->image=$options['image'];
}

public function via($notifiable){

return $this->methods;

}

public function toMail($notifiable){

return (new MailMessage)
//->level($this->level)
->subject("لديك إشعار جديد")
->greeting("مرحباً")
->line($this->inline_content)
->action($this->btn_text, $this->action_url);

}
public function toDatabase($notifiable){

$content=$this->inline_content;
return [
'message'=>'<a href="'.$this->action_url.'">'.$content.'</a>',
'image'=>$this->image,
];
}
}
33 changes: 33 additions & 0 deletions app/View/Components/Notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\View\Components;

use Illuminate\View\Component;

class Notifications extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public $notifications;
public function __construct($notifications)
{
$this->notifications=$notifications;
}

/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render($render=null)
{
$notifications=$this->notifications;
return (null!==$render)?view('components.notifications',compact('notifications'))->render():view('components.notifications');
}
}



3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"laravel/tinker": "^2.5",
"laravel/ui": "^3.3",
"livewire/livewire": "^2.7",
"mckenziearts/laravel-notify": "^2.2"
"mckenziearts/laravel-notify": "^2.2",
"nesbot/carbon": "^2.54"
},
"require-dev": {
"facade/ignition": "^2.5",
Expand Down
13 changes: 7 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'MainHelper'=> \App\Helpers\MainHelper::class,
'Carbon'=> Carbon\Carbon::class,

],

Expand Down
Binary file added public/images/default/notification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions public/js/favicon_notification.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/sounds/notification.wav
Binary file not shown.
Loading

0 comments on commit 160317d

Please sign in to comment.