diff --git a/app/DB/TepRepo.php b/app/DB/TepRepo.php new file mode 100644 index 0000000..372da86 --- /dev/null +++ b/app/DB/TepRepo.php @@ -0,0 +1,88 @@ +paginate('20'); + return $data_user; + } + + public function getUserwithoutTrashedAll()// Design pattern , Solid(1) + { + $data_user_all = User::withoutTrashed() + ->get(); + return $data_user_all; + } + + public function getUserTrashedPaginated()// Design pattern , Solid(1) + { + $data_user = User::onlyTrashed() + ->paginate('20'); + return $data_user; + } + + public function getUserTrashedAll()// Design pattern , Solid(1) + { + $data_user_all = User::onlyTrashed() + ->get(); + return $data_user_all; + } + + public function restoreDeletedMobile($id)// Design pattern , Solid(1) + { + $restore_mobile = $this->getUserTrashedAll()->find($id)->restore(); + return $restore_mobile; + } + + public function UserCheckCount($username1, $password1) + { + $data3 = User::where('Emd_id', '=', $username1) + ->where('password', '=', $password1) + ->count(); + return $data3; + } + + public function UserSearchBasedEmpID($user_emp_id) + { + $data_user = User::where('Emd_id', $user_emp_id) + ->paginate('25'); + return $data_user; + } + public function getUserAllPaginate($page) + { + $data_user = User::paginate($page); + return $data_user; + } + public function UserDeleteBasedID($id) + { + $del_mobile = User::where('id', $id)->delete(); + return $del_mobile; + } + public function UserForceDeleteByID($id) + { + $del_mobile_force = User::withTrashed()->where('id', $id)->forceDelete(); + return $del_mobile_force; + } + public function UsersearchBasedID($id_user) + { + $update_mobile_user = User::where('id', $id_user); + return $update_mobile_user; + } + public function UserUpdateMobile($id_user,$new_mobile) + { + $set_mobile_user = $this->UsersearchBasedID($id_user)->update(['mobile' => $new_mobile]); + return $set_mobile_user; + } + + +} diff --git a/app/Decorates/Logger.php b/app/Decorates/Logger.php new file mode 100644 index 0000000..4ff0f03 --- /dev/null +++ b/app/Decorates/Logger.php @@ -0,0 +1,20 @@ +call($callable,[$param]); + Log::info('param is: '.implode(',',$param).'and result is: '.$result); + }; + + } + +} diff --git a/app/Http/Controllers/TelUserController.php b/app/Http/Controllers/TelUserController.php index 132f12a..21d3415 100644 --- a/app/Http/Controllers/TelUserController.php +++ b/app/Http/Controllers/TelUserController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\DB\TepRepo; use App\Imports\UsersImport; use App\Models\User; use http\Exception; @@ -12,6 +13,7 @@ use Illuminate\Support\Facades\DB; use App\Exports\ExportUser; use Illuminate\Support\Facades\Log; +use LaravelDaily\LaravelCharts\Classes\LaravelChart; use Maatwebsite\Excel\Facades\Excel; use App\Notifications\SendNotification; use \App\Notifications\TelegramNotification; @@ -22,22 +24,36 @@ class TelUserController extends Controller // public function index(Request $request) { - return "Welcome to TelUser Project"; +// $user_ip=$request->ip(); +// $user_agent=$request->userAgent(); +// Cache::store('database')->increment('visit_page_cache'); +// Cache::store('file')->forever('visit_page_cache',1); + + try{ + Cache::store('database')->put('visit_page_cache',1,20); + +// if(!session()->has('ip_address') and !session()->has('user_agent') ) +// { +// session(['ip_address' => $user_ip]); +// session(['user_agent' => $user_agent]); +// } + } + catch (\Exception $e){ + Log::error($e); + } + return view('welcome'); } public function CheckUser(Request $request) { + $telFunctionClasses=resolve(TepRepo::class); try { if ($request->ajax()) { //$data = DB::table('weblinks')->orderBy('id','desc')->get(); $username1 = $request->user1; $password1 = $request->pass1; - $data3 = DB::table('users') - ->select('*') - ->where('Emd_id', '=', $username1) - ->where('password', '=', $password1) - ->count(); + $data3 = $telFunctionClasses->UserCheckCount($username1, $password1); //->paginate(30); //echo $data3; @@ -93,18 +109,56 @@ public function fileImport(Request $request) public function adminLTE() { // $data_user=User::get(); - $data_user = $this->getUserwithoutTrashedPaginated(); - $data_user_all = $this->getUserwithoutTrashedAll(); + $telFunctionClasses=resolve(TepRepo::class); + $data_user = $telFunctionClasses->getUserwithoutTrashedPaginated(); + $data_user_all = $telFunctionClasses->getUserwithoutTrashedAll(); + + + // echo "Find ID successfuly "; return view('Login.AdminLTE', compact('data_user', 'data_user_all')); // redirect('Login.AdminLTE'); } + public function UserStastics(Request $request) + { +// $chart_options = [ +// 'chart_title' => 'Users by months', +// 'report_type' => 'group_by_date', +// 'model' => 'App\Models\User', +// 'group_by_field' => 'created_at', +// 'group_by_period' => 'week', +// 'chart_type' => 'bar', +//// 'conditions' => [ +//// ['name' => 'UserLogin', 'condition' => 'category_id = 1', 'color' => 'yellow', 'fill' => true] +//// ], +// +// ]; + + $chart_options = [ + 'chart_title' => 'Transactions by dates', + 'report_type' => 'group_by_date', + 'model' => 'App\Models\User', + 'group_by_field' => 'created_at', + 'group_by_period' => 'month', +// 'aggregate_function' => 'sum', +// 'aggregate_field' => 'amount', + 'chart_type' => 'line', + ]; + try { + $chart1 = new LaravelChart($chart_options); + } catch (\Exception $e) { + Log::error($e); + } + return view('Charts.UserStastics',compact('chart1')); + } + public function Deleted_Mobile_users() { // $data_user=User::get(); - $data_user = $this->getUserTrashedPaginated(); - $data_user_all = $this->getUserTrashedAll(); + $telFunctionClasses=resolve(TepRepo::class); + $data_user = $telFunctionClasses->getUserTrashedPaginated(); + $data_user_all = $telFunctionClasses->getUserTrashedAll(); // echo "Find ID successfuly "; return view('Results.Deleted_User', compact('data_user', 'data_user_all')); // redirect('Login.AdminLTE'); @@ -114,7 +168,8 @@ public function restore_user(Request $request) { // $data_user=User::get(); $id = $request->id; - $restore_mobile = $this->restoreDeletedMobile($id);//db part + $telFunctionClasses=resolve(TepRepo::class); + $restore_mobile = $telFunctionClasses->restoreDeletedMobile($id);//db part if ($restore_mobile) {// http response return response()->json([ 'success' => 'بازنشانی باموفقیت صورت گرفت' @@ -126,11 +181,10 @@ public function restore_user(Request $request) public function prs_search(Request $request) { // $data_user=User::get(); + $telFunctionClasses=resolve(TepRepo::class); + $user_emp_id = $request->emp_id; - $data_user = DB::table('users') - ->select('*') - ->where('Emd_id', '=', $user_emp_id) - ->paginate('25'); + $data_user = $telFunctionClasses->UserSearchBasedEmpID($user_emp_id); return view('Results.usershowByPrs', compact('data_user')); @@ -139,20 +193,18 @@ public function prs_search(Request $request) public function FilterUser() { - $data_user = DB::table('users') - ->select('*') - ->paginate('20'); + $page=20; + $telFunctionClasses=resolve(TepRepo::class); + $data_user = $telFunctionClasses->getUserAllPaginate($page); return view('Results.user_management', compact('data_user')); } public function destroy($id) { - //User::find($id)->delete($id); -// DB::table('user_msg') -// ->where('id', $id) -// ->delete(); - $del_mobile = User::where('id', $id)->delete();// by the way the deleted_at generated in mysql + + $telFunctionClasses=resolve(TepRepo::class); + $del_mobile = $telFunctionClasses->UserDeleteBasedID($id);// by the way the deleted_at generated in mysql if ($del_mobile) { return response()->json([ 'success' => 'حذف با موفقیت صورت گرفت!' @@ -163,7 +215,8 @@ public function destroy($id) public function destroyForce($id) { - $del_mobile_force = User::withTrashed()->where('id', $id)->forceDelete();// by the way the deleted_at generated in mysql + $telFunctionClasses=resolve(TepRepo::class); + $del_mobile_force = $telFunctionClasses->UserForceDeleteByID($id);// by the way the deleted_at generated in mysql if ($del_mobile_force) { return response()->json([ 'success' => 'موبایل به طور کامل از دیتا بیس حذف گردید.' @@ -183,17 +236,15 @@ public function Update_mobile(Request $request) //if($request->ajax()) if ($request->ajax()) { + $telFunctionClasses=resolve(TepRepo::class); $user_mobile_new = $request->new_mobile; + $id_user=$request->id_ajax; $time2 = time(); //$time2=jdate('Y/n/j H:i:s'); //$time2="123456789"; try { // Validate the value... - $update_mobile_user = User::where('id', $request->id_ajax)// in this part I used to user_msg model for query - ->update(['mobile' => $user_mobile_new]); -// if(DB::table('user_msg') -// ->where('id', $request->id_ajax) -// ->update(['msg_response'=>$msg_admin1, 'date_response'=>$time2])) + $update_mobile_user = $telFunctionClasses->UserUpdateMobile($id_user,$user_mobile_new);//Use Design pattern and The first principal of Solid if ($update_mobile_user) { echo '
آپدیت موفقیت آمیز بود.
'; // return "ok";// for testing code by postman @@ -204,6 +255,7 @@ public function Update_mobile(Request $request) } } catch (Exception $e) { echo '
error exist in your code
'; + Log::log($e); //consloe.log($ex->getMessage()); //dd($e->getMessage()); //return false; @@ -225,60 +277,5 @@ public function telegram() // return (new TelegramNotification()); } - /** - * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator - */ - private function getUserwithoutTrashedPaginated()// Design pattern , Solid(1) - { - $data_user = User::withoutTrashed() - ->paginate('20'); - return $data_user; - } - - /** - * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|\Illuminate\Support\Collection - */ - private function getUserwithoutTrashedAll()// Design pattern , Solid(1) - { - $data_user_all = User::withoutTrashed() - ->get(); - return $data_user_all; - } - - /** - * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator - */ - private function getUserTrashedPaginated()// Design pattern , Solid(1) - { - $data_user = User::onlyTrashed() - ->paginate('20'); - return $data_user; - } - - /** - * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|\Illuminate\Support\Collection - */ - private function getUserTrashedAll()// Design pattern , Solid(1) - { - $data_user_all = User::onlyTrashed() - ->get(); - return $data_user_all; - } - - /** - * @param $id - * @return mixed - */ - private function restoreDeletedMobile($id)// Design pattern , Solid(1) - { - $restore_mobile = $this->getUserTrashedAll()->find($id)->restore(); - return $restore_mobile; - } - - /** - * @param $user_emp_id - * @return mixed - */ - } diff --git a/composer.json b/composer.json index 3968196..3677230 100644 --- a/composer.json +++ b/composer.json @@ -9,12 +9,14 @@ "babenkoivan/telegram-notifications": "^1.1", "doctrine/dbal": "*", "guzzlehttp/guzzle": "^7.2", + "imanghafoori/laravel-decorator": "^1.0", "irazasyed/telegram-bot-sdk": "^3.9", "laravel-notification-channels/telegram": "^3.0", "laravel/framework": "^9.19", "laravel/sanctum": "^3.0", "laravel/tinker": "^2.7", "laravel/ui": "^4.1", + "laraveldaily/laravel-charts": "^0.1.29", "maatwebsite/excel": "^3.1", "psr/simple-cache": "1.0" }, diff --git a/composer.lock b/composer.lock index c304c9c..c55c3c8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "240fd4316c8225614381be3ba8c2ad4e", + "content-hash": "8e181a3811332f9128397b925ddbc52d", "packages": [ { "name": "babenkoivan/telegram-notifications", @@ -1352,6 +1352,77 @@ ], "time": "2022-10-26T14:07:24+00:00" }, + { + "name": "imanghafoori/laravel-decorator", + "version": "v1.0.7", + "source": { + "type": "git", + "url": "https://github.com/imanghafoori1/laravel-decorator.git", + "reference": "797da654524b896b0ad348d304051905270e344d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/imanghafoori1/laravel-decorator/zipball/797da654524b896b0ad348d304051905270e344d", + "reference": "797da654524b896b0ad348d304051905270e344d", + "shasum": "" + }, + "require": { + "laravel/framework": "~5.1|6.*|7.*|8.*|9.*|10.*", + "php": "7.2.*|7.3.*|7.4.*|8.0.*|8.1.*|8.2.*" + }, + "require-dev": { + "orchestra/testbench": "~6.0", + "squizlabs/php_codesniffer": "3.*" + }, + "suggest": { + "imanghafoori/laravel-anypass": " Allows you login with any password in local environment.", + "imanghafoori/laravel-heyman": "It allows to write expressive code to authorize, validate and authenticate.", + "imanghafoori/laravel-masterpass": "You can set a master password for your accounts.", + "imanghafoori/laravel-widgetize": "Gives you a better structure and caching opportunity for your laravel apps." + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Imanghafoori\\Decorator\\DecoratorServiceProvider" + ], + "aliases": { + "Decorator": "Imanghafoori\\Decorator\\Facade" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Imanghafoori\\Decorator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Iman Ghafoori", + "email": "imanghafoori1@gmail.com" + } + ], + "description": "A package to easily decorate your function calls.", + "homepage": "https://github.com/imanghafoori1/laravel-decorator", + "keywords": [ + "decorator pattern", + "design patterns", + "laravel", + "php decorator pattern" + ], + "support": { + "issues": "https://github.com/imanghafoori1/laravel-decorator/issues", + "source": "https://github.com/imanghafoori1/laravel-decorator/tree/v1.0.7" + }, + "time": "2022-05-03T10:23:36+00:00" + }, { "name": "irazasyed/telegram-bot-sdk", "version": "v3.9", @@ -1942,6 +2013,50 @@ }, "time": "2022-12-05T15:09:21+00:00" }, + { + "name": "laraveldaily/laravel-charts", + "version": "0.1.29", + "source": { + "type": "git", + "url": "https://github.com/LaravelDaily/laravel-charts.git", + "reference": "ed91d6e7dedabec8eb3c71cca0a22c8616faea01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/LaravelDaily/laravel-charts/zipball/ed91d6e7dedabec8eb3c71cca0a22c8616faea01", + "reference": "ed91d6e7dedabec8eb3c71cca0a22c8616faea01", + "shasum": "" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "LaravelDaily\\LaravelCharts\\LaravelChartsServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "LaravelDaily\\LaravelCharts\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Povilas Korop", + "email": "povilas@laraveldaily.com" + } + ], + "description": "Create charts and reports from Laravel", + "support": { + "issues": "https://github.com/LaravelDaily/laravel-charts/issues", + "source": "https://github.com/LaravelDaily/laravel-charts/tree/0.1.29" + }, + "time": "2022-01-04T04:41:41+00:00" + }, { "name": "league/commonmark", "version": "2.3.7", diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 34d1b0f..caee022 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -25,7 +25,8 @@ public function definition() 'family'=>fake()->lastName(), 'type'=>fake()->randomElement(['user', 'admin']), // 'type'=>new Sequence('user','admin'), - 'password' => fake()->numberBetween(100000,999999), + 'password' => fake()->numberBetween(1000000,999999), + 'created_at'=>fake()->dateTimeBetween("-1000 day", now()), ]; } diff --git a/database/migrations/2023_01_11_142824_create_sessions_table.php b/database/migrations/2023_01_11_142824_create_sessions_table.php new file mode 100644 index 0000000..06c3e45 --- /dev/null +++ b/database/migrations/2023_01_11_142824_create_sessions_table.php @@ -0,0 +1,35 @@ +string('id')->primary(); + $table->foreignId('user_id')->nullable()->index(); + $table->string('ip_address', 45)->nullable(); + $table->text('user_agent')->nullable(); + $table->longText('payload'); + $table->integer('last_activity')->index(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('sessions'); + } +}; diff --git a/database/migrations/2023_01_11_160040_create_cache_table.php b/database/migrations/2023_01_11_160040_create_cache_table.php new file mode 100644 index 0000000..eee35e9 --- /dev/null +++ b/database/migrations/2023_01_11_160040_create_cache_table.php @@ -0,0 +1,39 @@ +string('key')->primary(); + $table->mediumText('value'); + $table->integer('expiration'); + }); + + Schema::create('cache_locks', function (Blueprint $table) { + $table->string('key')->primary(); + $table->string('owner'); + $table->integer('expiration'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('cache'); + Schema::dropIfExists('cache_locks'); + } +}; diff --git a/database/seeders/userseeder.php b/database/seeders/userseeder.php index 09e75e4..227b411 100644 --- a/database/seeders/userseeder.php +++ b/database/seeders/userseeder.php @@ -17,7 +17,7 @@ public function run() { // User::truncate(); - $user=User::factory()->count(50)->create(); + $user=User::factory()->count(1000)->create(); } } diff --git a/resources/views/Charts/UserStastics.blade.php b/resources/views/Charts/UserStastics.blade.php new file mode 100644 index 0000000..adbe098 --- /dev/null +++ b/resources/views/Charts/UserStastics.blade.php @@ -0,0 +1,25 @@ +@extends('layouts.AdminLayout') +@section('content') +
+
+
+
+
Dashboard
+ +
+ +

{{ $chart1->options['chart_title'] }}

+ {!! $chart1->renderHtml() !!} + +
+ +
+
+
+
+@endsection + +@section('javascript') + {!! $chart1->renderChartJsLibrary() !!} + {!! $chart1->renderJs() !!} +@endsection diff --git a/resources/views/Charts/javascript.blade.php b/resources/views/Charts/javascript.blade.php new file mode 100644 index 0000000..2644f29 --- /dev/null +++ b/resources/views/Charts/javascript.blade.php @@ -0,0 +1,67 @@ + diff --git a/resources/views/Login/AdminLTE.blade.php b/resources/views/Login/AdminLTE.blade.php index b144bd5..82f72e8 100644 --- a/resources/views/Login/AdminLTE.blade.php +++ b/resources/views/Login/AdminLTE.blade.php @@ -35,7 +35,7 @@ id }}>{{ $value->Emd_id }} id }}>{{ $value->name }} id }}>{{ $value->family }} - id }}>{{ $value->mobile }} + id }}>{{ $value->mobile }} @@ -125,7 +125,7 @@ function(a) { return a.charCodeAt(0) & 0xf } // Remove the Unicode base(2) r document.getElementById("demo").innerHTML =""; for (i = 0; i < tr.length; i++) {// repeat this loop for each row of table td = tr[i].getElementsByTagName("td")[radioValue]; - + if (td) { txtValue = td.textContent || td.innerText; @@ -137,7 +137,7 @@ function(a) { return a.charCodeAt(0) & 0xf } // Remove the Unicode base(2) r // }) } - + if (txtValue.toLowerCase().indexOf(input) > -1) { flag++; tr[i].style.display = ""; diff --git a/resources/views/layouts/AdminLayout.blade.php b/resources/views/layouts/AdminLayout.blade.php index 23fd44e..b68b972 100644 --- a/resources/views/layouts/AdminLayout.blade.php +++ b/resources/views/layouts/AdminLayout.blade.php @@ -219,7 +219,7 @@ class="w3-button w3-display-topright">×
- اطلاعات بیشتر + اطلاعات بیشتر @@ -251,12 +251,15 @@ class="w3-button w3-display-topright">× اطلاعات بیشتر +
{{-- This place is for content --}} @yield('content') + @yield('javascript') +
@@ -360,4 +363,3 @@ function Make_Snow() { } - diff --git a/routes/web.php b/routes/web.php index ed50566..d4c35f4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,9 +15,10 @@ | */ -Route::get('/', function () { - return view('welcome'); -}); +//Route::get('/', function () { +// return view('welcome'); +//}); +Route::get('/', [App\Http\Controllers\TelUserController::class,'index']); Route::get('/loginlogin', function (){ return view('Login.login'); }); @@ -35,6 +36,7 @@ Route::get('/telegram', [TelUserController::class, 'telegram'])->name('telegram'); Route::get('/updated-activity', [TelegramBotController::class,'updatedActivity'])->name('updated-activity'); Route::get('/call_madeline', [TelegramBotController::class,'call_madeline']); +Route::get('/UserStastics', [App\Http\Controllers\TelUserController::class,'UserStastics']);