Merge branch '2.0.0' into 'develop'
2.0.0 See merge request ldc-web/projets/volena!3
This commit is contained in:
commit
d71d72af86
600 changed files with 164153 additions and 11320 deletions
13
.browserslistrc
Normal file
13
.browserslistrc
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Browsers that we support
|
||||
|
||||
# https://github.com/browserslist/browserslist#readme
|
||||
|
||||
>= 0.5%
|
||||
last 2 major versions
|
||||
not dead
|
||||
Chrome >= 60
|
||||
Firefox >= 60
|
||||
Firefox ESR
|
||||
iOS >= 12
|
||||
Safari >= 12
|
||||
not Explorer <= 11
|
||||
40
.env.example
40
.env.example
|
|
@ -3,6 +3,7 @@ APP_ENV=local
|
|||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
ASSET_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
|
|
@ -22,6 +23,12 @@ QUEUE_CONNECTION=sync
|
|||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=mailpit
|
||||
MAIL_PORT=1025
|
||||
|
|
@ -31,8 +38,37 @@ MAIL_ENCRYPTION=null
|
|||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
# Matomo
|
||||
MATOMO_SITE_ID=
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_HOST=
|
||||
PUSHER_PORT=443
|
||||
PUSHER_SCHEME=https
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
||||
# Sentry
|
||||
SENTRY_LARAVEL_DSN=
|
||||
|
||||
# MAILS
|
||||
MAIL_CONTACT_REMARK="equipe.web@ldc.fr"
|
||||
MAIL_CONTACT_SPONSORING="equipe.web@ldc.fr"
|
||||
MAIL_CONTACT_SERVICE="equipe.web@ldc.fr"
|
||||
MAIL_CONTACT_OTHER="equipe.web@ldc.fr"
|
||||
|
||||
# GOOGLE
|
||||
# - RECAPTCHA
|
||||
GOOGLE_RECAPTCHA_PUBLIC=
|
||||
GOOGLE_RECAPTCHA_PRIVATE=
|
||||
GOOGLE_RECAPTCHA_VERSION=
|
||||
|
|
|
|||
|
|
@ -10,16 +10,16 @@
|
|||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts", "*.vue"],
|
||||
"rules": {
|
||||
"no-undef": "off"
|
||||
}
|
||||
"files": ["*.ts", "*.vue"],
|
||||
"rules": {
|
||||
"no-undef": "off"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["*.vue"],
|
||||
"rules": {
|
||||
"indent": "off"
|
||||
}
|
||||
"files": ["*.vue"],
|
||||
"rules": {
|
||||
"indent": "off"
|
||||
}
|
||||
}
|
||||
],
|
||||
"parser": "vue-eslint-parser",
|
||||
|
|
@ -29,7 +29,14 @@
|
|||
"sourceType": "module"
|
||||
},
|
||||
"plugins": ["vue", "@typescript-eslint"],
|
||||
"ignorePatterns": ["webpack.mix.js", "**/vendor/*.js", "**/vendor/**/*.js"],
|
||||
"ignorePatterns": [
|
||||
"webpack.mix.js",
|
||||
"**/*.php",
|
||||
"**/*.svg",
|
||||
"**/vendor/*.js",
|
||||
"**/vendor/**/*.js",
|
||||
"**/vendor/**/*.scss"
|
||||
],
|
||||
"rules": {
|
||||
"indent": ["error", 4, { "SwitchCase": 1 }],
|
||||
"linebreak-style": ["error", "unix"],
|
||||
|
|
|
|||
16
.gitignore
vendored
16
.gitignore
vendored
|
|
@ -8,6 +8,7 @@
|
|||
/.phpunit.cache
|
||||
/.vscode
|
||||
/node_modules
|
||||
/bootstrap
|
||||
/public/build
|
||||
/public/cache
|
||||
/public/hot
|
||||
|
|
@ -21,4 +22,17 @@ Homestead.json
|
|||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
.npmrc
|
||||
.npmrc
|
||||
|
||||
# Ignore public favicon
|
||||
/public/android-chrome-192x192.png
|
||||
/public/android-chrome-512x512.png
|
||||
/public/apple-touch-icon.png
|
||||
/public/browserconfig.xml
|
||||
/public/browserconfig.xml
|
||||
/public/favicon-16x16.png
|
||||
/public/favicon-32x32.png
|
||||
/public/favicon.ico
|
||||
/public/mstile-150x150.png
|
||||
/public/safari-pinned-tab.svg
|
||||
/public/site.webmanifest
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
include:
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'lint/lint.yml'
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'security/security.yml'
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'build/build.yml'
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'test/test.yml'
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'deploy/deploy.yml'
|
||||
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "lint/lint8.3.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "security/security8.3.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "build/build8.3.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "test/test.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "deploy/deploy.yml"
|
||||
|
||||
stages:
|
||||
- lint
|
||||
- security
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
- lint
|
||||
- security
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
|
|
|
|||
|
|
@ -4,8 +4,13 @@
|
|||
"stylelint-config-sass-guidelines",
|
||||
"stylelint-config-idiomatic-order"
|
||||
],
|
||||
"plugins": ["stylelint-scss"],
|
||||
"files": ["**/*.css", "**/*.scss"],
|
||||
"plugins": [
|
||||
"stylelint-scss"
|
||||
],
|
||||
"files": [
|
||||
"**/*.css",
|
||||
"**/*.scss"
|
||||
],
|
||||
"ignoreFiles": [
|
||||
"**/vendor/*.css",
|
||||
"**/vendor/**/*.css",
|
||||
|
|
@ -18,15 +23,12 @@
|
|||
],
|
||||
"customSyntax": "postcss-scss",
|
||||
"rules": {
|
||||
"indentation": 4,
|
||||
"string-quotes": "double",
|
||||
"declaration-property-value-no-unknown": true,
|
||||
"selector-max-id": null,
|
||||
"color-no-invalid-hex": true,
|
||||
"order/properties-alphabetical-order": null,
|
||||
"max-nesting-depth": 5,
|
||||
"selector-max-compound-selectors": 5,
|
||||
"declaration-colon-space-after": "always-single-line",
|
||||
"function-parentheses-space-inside": "never-single-line",
|
||||
"declaration-colon-newline-after": null,
|
||||
"value-list-comma-newline-after": null,
|
||||
"scss/double-slash-comment-empty-line-before": [
|
||||
|
|
|
|||
21
.vscode/extensions.json
vendored
21
.vscode/extensions.json
vendored
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"recommendations": [
|
||||
"esbenp.prettier-vscode",
|
||||
"rvest.vs-code-prettier-eslint",
|
||||
"onecentlin.laravel-extension-pack",
|
||||
"johnpapa.vscode-peacock",
|
||||
"xdebug.php-debug",
|
||||
"neilbrayfield.php-docblocker",
|
||||
"bmewburn.vscode-intelephense-client",
|
||||
"valeryanm.vscode-phpsab",
|
||||
"shevaua.phpcs",
|
||||
"syler.sass-indented",
|
||||
"sibiraj-s.vscode-scss-formatter",
|
||||
"mrmlnc.vscode-scss",
|
||||
"stylelint.vscode-stylelint",
|
||||
"vue.vscode-typescript-vue-plugin",
|
||||
"wscats.vue",
|
||||
"vue.volar",
|
||||
"misterj.vue-volar-extention-pack"
|
||||
]
|
||||
}
|
||||
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -20,7 +20,7 @@
|
|||
"commandCenter.border": "#e7e7e799"
|
||||
},
|
||||
"peacock.remoteColor": "#103251",
|
||||
"intelephense.environment.phpVersion": "8.2.0",
|
||||
"intelephense.environment.phpVersion": "8.3.0",
|
||||
"intelephense.completion.fullyQualifyGlobalConstantsAndFunctions": true,
|
||||
"intelephense.phpdoc.useFullyQualifiedNames": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/ldcweb-production-8.2:latest
|
||||
COPY . /app/srcs
|
||||
COPY ./public/build /app/srcs/public/build
|
||||
COPY ./vendor /app/srcs/vendor
|
||||
COPY --chown=www-data:www-data . /app/srcs
|
||||
USER root
|
||||
RUN chmod -R 755 /app/srcs/storage
|
||||
USER www-data
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
# VOLENA
|
||||
|
||||
## Installation
|
||||
```
|
||||
|
||||
``` bash
|
||||
cp .env.example .env
|
||||
php artisan key:generate
|
||||
|
||||
|
|
@ -9,7 +10,9 @@ npm i && npm run prod
|
|||
```
|
||||
|
||||
## Crons
|
||||
|
||||
Put every min in PROD :
|
||||
```
|
||||
|
||||
``` bash
|
||||
php artisan schedule:run
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,177 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class CreateAdmin extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:create';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a backend admin user';
|
||||
|
||||
/**
|
||||
* The firstname of the new user.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $firstname;
|
||||
|
||||
/**
|
||||
* The lastname of the new user.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $lastname;
|
||||
|
||||
/**
|
||||
* The email of the new user.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* The password of the new user.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->firstname = null;
|
||||
$this->addFirstname();
|
||||
|
||||
$this->lastname = null;
|
||||
$this->addLastname();
|
||||
|
||||
$this->email = null;
|
||||
$this->addEmail();
|
||||
|
||||
$this->password = null;
|
||||
$this->addPassword();
|
||||
|
||||
$user = new User([
|
||||
'firstname' => $this->firstname,
|
||||
'lastname' => $this->lastname,
|
||||
'email' => $this->email,
|
||||
'password' => $this->password,
|
||||
]);
|
||||
$user->saveOrFail();
|
||||
|
||||
$this->info('User created 👌');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a firstname to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addFirstname(): void
|
||||
{
|
||||
while (is_null($this->firstname)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user firstname', 'Admin');
|
||||
$validator = Validator::make(['firstname' => $tmp], [
|
||||
'firstname' => 'required|min:3|max:255'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->firstname = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid firstname %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
}; //end while
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a lastname to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addLastname(): void
|
||||
{
|
||||
while (is_null($this->lastname)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user lastname', 'Saïtama');
|
||||
$validator = Validator::make(['lastname' => $tmp], [
|
||||
'lastname' => 'required|min:3|max:255'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->lastname = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid lastname %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
}; //end while
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an email to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addEmail(): void
|
||||
{
|
||||
while (is_null($this->email)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user email', 'equipe.web@ldc.fr');
|
||||
$validator = Validator::make(['email' => $tmp], [
|
||||
'email' => 'required|unique:users,email|email:rfc,dns'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->email = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid email %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
}; //end while
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a password to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addPassword(): void
|
||||
{
|
||||
while (
|
||||
($this->password = $this->secret(
|
||||
(!\is_null($this->password) ? 'Failed to confirm, ' : '') . 'Type the wanted user password'
|
||||
)) !== $this->secret('Confirm the password')
|
||||
) {
|
||||
continue;
|
||||
}; //end while
|
||||
}
|
||||
}
|
||||
35
app/Console/Commands/TestMail.php
Normal file
35
app/Console/Commands/TestMail.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class TestMail extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'uwil:mail:test';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Send test email to equipe.web@ldc.fr';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Mail::raw(sprintf('UWIL mail-test from %s %s', \config('app.name'), \config('app.url')), function ($msg) {
|
||||
$msg->to('equipe.web@ldc.fr')->subject('Test Email');
|
||||
});
|
||||
}
|
||||
}
|
||||
236
app/Console/Commands/UserCreate.php
Normal file
236
app/Console/Commands/UserCreate.php
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UserCreate extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'uwil:user:create';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a backend admin user';
|
||||
|
||||
/**
|
||||
* The first name of the new user.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $first_name;
|
||||
|
||||
/**
|
||||
* The last name of the new user.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $last_name;
|
||||
|
||||
/**
|
||||
* The email of the new user.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* The password of the new user.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* The role of the new user.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $role;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->first_name = null;
|
||||
$this->addFirstName();
|
||||
|
||||
$this->last_name = null;
|
||||
$this->addLastName();
|
||||
|
||||
$this->email = null;
|
||||
$this->addEmail();
|
||||
|
||||
$this->password = null;
|
||||
$this->addPassword();
|
||||
|
||||
$this->role = null;
|
||||
$this->addRole();
|
||||
|
||||
$user = new User([
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'email' => $this->email,
|
||||
'password' => $this->password,
|
||||
'role' => $this->role,
|
||||
'published' => true,
|
||||
'published_at' => Carbon::now(),
|
||||
]);
|
||||
$user->saveOrFail();
|
||||
|
||||
$this->info('User created 👌');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a first name to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addFirstName(): void
|
||||
{
|
||||
while (is_null($this->first_name)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user first name', 'Admin');
|
||||
$validator = Validator::make(['first_name' => $tmp], [
|
||||
'first_name' => 'required|min:3|max:255'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->first_name = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid first name %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
}; //end while
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a last name to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addLastName(): void
|
||||
{
|
||||
while (is_null($this->last_name)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user last name', 'Saïtama');
|
||||
$validator = Validator::make(['last_name' => $tmp], [
|
||||
'last_name' => 'required|min:3|max:255'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->last_name = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid last_name %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
}; //end while
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an email to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addEmail(): void
|
||||
{
|
||||
while (is_null($this->email)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user email', 'equipe.web@ldc.fr');
|
||||
$validator = Validator::make(['email' => $tmp], [
|
||||
'email' => 'required|unique:users,email|email:rfc,dns'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->email = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid email %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
}; //end while
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a password to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addPassword(): void
|
||||
{
|
||||
while (
|
||||
($this->password = $this->secret(
|
||||
(!\is_null($this->password) ? 'Failed to confirm, ' : '') . 'Type the wanted user password'
|
||||
)) !== $this->secret('Confirm the password')
|
||||
) {
|
||||
continue;
|
||||
}; //end while
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a role to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addRole(): void
|
||||
{
|
||||
while (is_null($this->role)) {
|
||||
try {
|
||||
$tmp = $this->choice(
|
||||
'Select his role',
|
||||
[
|
||||
Str::ucFirst(RoleEnum::conceptor->label()),
|
||||
Str::ucFirst(RoleEnum::admin->label()),
|
||||
Str::ucFirst(RoleEnum::visitor->label())
|
||||
],
|
||||
Str::ucFirst(RoleEnum::visitor->label()),
|
||||
$maxAttempts = null,
|
||||
$allowMultipleSelections = false
|
||||
);
|
||||
if ($tmp === Str::ucFirst(RoleEnum::conceptor->label())) {
|
||||
$tmp = RoleEnum::conceptor;
|
||||
}
|
||||
if ($tmp === Str::ucFirst(RoleEnum::admin->label())) {
|
||||
$tmp = RoleEnum::admin;
|
||||
}
|
||||
if ($tmp === Str::ucFirst(RoleEnum::visitor->label())) {
|
||||
$tmp = RoleEnum::visitor;
|
||||
}
|
||||
$validator = Validator::make(['role' => $tmp], [
|
||||
'role' => 'required'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->role = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please choose from the selection %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
}; //end while
|
||||
}
|
||||
}
|
||||
48
app/Enums/ActivityLogs/ActivityLogsEventEnum.php
Normal file
48
app/Enums/ActivityLogs/ActivityLogsEventEnum.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\ActivityLogs;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ActivityLogsEventEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case created = 1;
|
||||
case updated = 2;
|
||||
case duplicated = 3;
|
||||
case deleted = 4;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::created->name => 'Création',
|
||||
self::updated->name => 'Mise à jour',
|
||||
self::duplicated->name => 'Duplication',
|
||||
self::deleted->name => 'Suppression',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Custom added classes definition
|
||||
*/
|
||||
private const BOOTSTRAPCLASS = [
|
||||
self::created->name => 'success',
|
||||
self::updated->name => 'warning',
|
||||
self::duplicated->name => 'secondary',
|
||||
self::deleted->name => 'danger',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get Class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function bootstrapClass(): string
|
||||
{
|
||||
return self::BOOTSTRAPCLASS[$this->name];
|
||||
}
|
||||
}
|
||||
25
app/Enums/CkEditorConfigName.php
Normal file
25
app/Enums/CkEditorConfigName.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum CkEditorConfigName: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case minimal = 1;
|
||||
case base = 2;
|
||||
case advanced = 3;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::minimal->name => 'minimal',
|
||||
self::base->name => 'base',
|
||||
self::advanced->name => 'advanced',
|
||||
];
|
||||
}
|
||||
862
app/Enums/Country.php
Normal file
862
app/Enums/Country.php
Normal file
|
|
@ -0,0 +1,862 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum Country: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case afghanistan = 1;
|
||||
case alandIslands = 2;
|
||||
case albania = 3;
|
||||
case algeria = 4;
|
||||
case americanSamoa = 5;
|
||||
case andorra = 6;
|
||||
case angola = 7;
|
||||
case anguilla = 8;
|
||||
case antarctica = 9;
|
||||
case antiguaAndBarbuda = 10;
|
||||
case argentina = 11;
|
||||
case armenia = 12;
|
||||
case aruba = 13;
|
||||
case australia = 14;
|
||||
case austria = 15;
|
||||
case azerbaijan = 16;
|
||||
case bahrain = 17;
|
||||
case bahamas = 18;
|
||||
case bangladesh = 19;
|
||||
case barbados = 20;
|
||||
case belarus = 21;
|
||||
case belgium = 22;
|
||||
case belize = 23;
|
||||
case benin = 24;
|
||||
case bermuda = 25;
|
||||
case bhutan = 26;
|
||||
case boliviaPlurinationalStateOf = 27;
|
||||
case bonaireSintEustatiusAndSaba = 28;
|
||||
case bosniaAndHerzegovina = 29;
|
||||
case botswana = 30;
|
||||
case bouvetIsland = 31;
|
||||
case brazil = 32;
|
||||
case britishIndianOceanTerritory = 33;
|
||||
case bruneiDarussalam = 34;
|
||||
case bulgaria = 35;
|
||||
case burkinaFaso = 36;
|
||||
case burundi = 37;
|
||||
case cambodia = 38;
|
||||
case cameroon = 39;
|
||||
case canada = 40;
|
||||
case capeVerde = 41;
|
||||
case caymanIslands = 42;
|
||||
case centralAfricanRepublic = 43;
|
||||
case chad = 44;
|
||||
case chile = 45;
|
||||
case china = 46;
|
||||
case christmasIsland = 47;
|
||||
case cocosKeelingIslands = 48;
|
||||
case colombia = 49;
|
||||
case comoros = 50;
|
||||
case congo = 51;
|
||||
case congoTheDemocraticRepublicOfThe = 52;
|
||||
case cookIslands = 53;
|
||||
case costaRica = 54;
|
||||
case coteDivoire = 55;
|
||||
case croatia = 56;
|
||||
case cuba = 57;
|
||||
case curacao = 58;
|
||||
case cyprus = 59;
|
||||
case czechRepublic = 60;
|
||||
case denmark = 61;
|
||||
case djibouti = 62;
|
||||
case dominica = 63;
|
||||
case dominicanRepublic = 64;
|
||||
case ecuador = 65;
|
||||
case egypt = 66;
|
||||
case elSalvador = 67;
|
||||
case equatorialGuinea = 68;
|
||||
case eritrea = 69;
|
||||
case estonia = 70;
|
||||
case ethiopia = 71;
|
||||
case falklandIslandsMalvinas = 72;
|
||||
case faroeIslands = 73;
|
||||
case fiji = 74;
|
||||
case finland = 75;
|
||||
case france = 76;
|
||||
case frenchGuiana = 77;
|
||||
case frenchPolynesia = 78;
|
||||
case frenchSouthernTerritories = 79;
|
||||
case gabon = 80;
|
||||
case gambia = 81;
|
||||
case georgia = 82;
|
||||
case germany = 83;
|
||||
case ghana = 84;
|
||||
case gibraltar = 85;
|
||||
case greece = 86;
|
||||
case greenland = 87;
|
||||
case grenada = 88;
|
||||
case guadeloupe = 89;
|
||||
case guam = 90;
|
||||
case guatemala = 91;
|
||||
case guernsey = 92;
|
||||
case guinea = 93;
|
||||
case guineaBissau = 94;
|
||||
case guyana = 95;
|
||||
case haiti = 96;
|
||||
case heardIslandAndMcdonaldIslands = 97;
|
||||
case holySeeVaticanCityState = 98;
|
||||
case honduras = 99;
|
||||
case hongKong = 100;
|
||||
case hungary = 101;
|
||||
case iceland = 102;
|
||||
case india = 103;
|
||||
case indonesia = 104;
|
||||
case iranIslamicRepublicOf = 105;
|
||||
case iraq = 106;
|
||||
case ireland = 107;
|
||||
case isleOfMan = 108;
|
||||
case israel = 109;
|
||||
case italy = 110;
|
||||
case jamaica = 111;
|
||||
case japan = 112;
|
||||
case jersey = 113;
|
||||
case jordan = 114;
|
||||
case kazakhstan = 115;
|
||||
case kenya = 116;
|
||||
case kiribati = 117;
|
||||
case koreaDemocraticPeoplesRepublicOf = 118;
|
||||
case koreaRepublicOf = 119;
|
||||
case kuwait = 120;
|
||||
case kyrgyzstan = 121;
|
||||
case laoPeoplesDemocraticRepublic = 122;
|
||||
case latvia = 123;
|
||||
case lebanon = 124;
|
||||
case lesotho = 125;
|
||||
case liberia = 126;
|
||||
case libya = 127;
|
||||
case liechtenstein = 128;
|
||||
case lithuania = 129;
|
||||
case luxembourg = 130;
|
||||
case macao = 131;
|
||||
case macedoniaTheFormerYugoslavRepublicOf = 132;
|
||||
case madagascar = 133;
|
||||
case malawi = 134;
|
||||
case malaysia = 135;
|
||||
case maldives = 136;
|
||||
case mali = 137;
|
||||
case malta = 138;
|
||||
case marshallIslands = 139;
|
||||
case martinique = 140;
|
||||
case mauritania = 141;
|
||||
case mauritius = 142;
|
||||
case mayotte = 143;
|
||||
case mexico = 144;
|
||||
case micronesiaFederatedStatesOf = 145;
|
||||
case moldovaRepublicOf = 146;
|
||||
case monaco = 147;
|
||||
case mongolia = 148;
|
||||
case montenegro = 149;
|
||||
case montserrat = 150;
|
||||
case morocco = 151;
|
||||
case mozambique = 152;
|
||||
case myanmar = 153;
|
||||
case namibia = 154;
|
||||
case nauru = 155;
|
||||
case nepal = 156;
|
||||
case netherlands = 157;
|
||||
case newCaledonia = 158;
|
||||
case newZealand = 159;
|
||||
case nicaragua = 160;
|
||||
case niger = 161;
|
||||
case nigeria = 162;
|
||||
case niue = 163;
|
||||
case norfolkIsland = 164;
|
||||
case northernMarianaIslands = 165;
|
||||
case norway = 166;
|
||||
case oman = 167;
|
||||
case pakistan = 168;
|
||||
case palau = 169;
|
||||
case palestineStateOf = 170;
|
||||
case panama = 171;
|
||||
case papuaNewGuinea = 172;
|
||||
case paraguay = 173;
|
||||
case peru = 174;
|
||||
case philippines = 175;
|
||||
case pitcairn = 176;
|
||||
case poland = 177;
|
||||
case portugal = 178;
|
||||
case puertoRico = 179;
|
||||
case qatar = 180;
|
||||
case reunion = 181;
|
||||
case romania = 182;
|
||||
case russianFederation = 183;
|
||||
case rwanda = 184;
|
||||
case saintBarthelemy = 185;
|
||||
case saintHelenaAscensionAndTristanDaCunha = 186;
|
||||
case saintKittsAndNevis = 187;
|
||||
case saintLucia = 188;
|
||||
case saintMartinFrenchPart = 189;
|
||||
case saintPierreAndMiquelon = 190;
|
||||
case saintVincentAndTheGrenadines = 191;
|
||||
case samoa = 192;
|
||||
case sanMarino = 193;
|
||||
case saoTomeAndPrincipe = 194;
|
||||
case saudiArabia = 195;
|
||||
case senegal = 196;
|
||||
case serbia = 197;
|
||||
case seychelles = 198;
|
||||
case sierraLeone = 199;
|
||||
case singapore = 200;
|
||||
case sintMaartenDutchPart = 201;
|
||||
case slovakia = 202;
|
||||
case slovenia = 203;
|
||||
case solomonIslands = 204;
|
||||
case somalia = 205;
|
||||
case southAfrica = 206;
|
||||
case southGeorgiaAndTheSouthSandwichIslands = 207;
|
||||
case southSudan = 208;
|
||||
case spain = 209;
|
||||
case sriLanka = 210;
|
||||
case sudan = 211;
|
||||
case suriname = 212;
|
||||
case svalbardAndJanMayen = 213;
|
||||
case swaziland = 214;
|
||||
case sweden = 215;
|
||||
case switzerland = 216;
|
||||
case syrianArabRepublic = 217;
|
||||
case taiwanProvinceOfChina = 218;
|
||||
case tajikistan = 219;
|
||||
case tanzaniaUnitedRepublicOf = 220;
|
||||
case thailand = 221;
|
||||
case timorLeste = 222;
|
||||
case togo = 223;
|
||||
case tokelau = 224;
|
||||
case tonga = 225;
|
||||
case trinidadAndTobago = 226;
|
||||
case tunisia = 227;
|
||||
case turkey = 228;
|
||||
case turkmenistan = 229;
|
||||
case turksAndCaicosIslands = 230;
|
||||
case tuvalu = 231;
|
||||
case uganda = 232;
|
||||
case ukraine = 233;
|
||||
case unitedArabEmirates = 234;
|
||||
case unitedKingdom = 235;
|
||||
case unitedStates = 236;
|
||||
case unitedStatesMinorOutlyingIslands = 237;
|
||||
case uruguay = 238;
|
||||
case uzbekistan = 239;
|
||||
case vanuatu = 240;
|
||||
case venezuelaBolivarianRepublicOf = 241;
|
||||
case vietNam = 242;
|
||||
case virginIslandsBritish = 243;
|
||||
case virginIslandsUs = 244;
|
||||
case wallisAndFutuna = 245;
|
||||
case westernSahara = 246;
|
||||
case yemen = 247;
|
||||
case zambia = 248;
|
||||
case zimbabwe = 249;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::afghanistan->name => 'Afghanistan',
|
||||
self::alandIslands->name => 'Åland Islands',
|
||||
self::albania->name => 'Albania',
|
||||
self::algeria->name => 'Algeria',
|
||||
self::americanSamoa->name => 'American Samoa',
|
||||
self::andorra->name => 'Andorra',
|
||||
self::angola->name => 'Angola',
|
||||
self::anguilla->name => 'Anguilla',
|
||||
self::antarctica->name => 'Antarctica',
|
||||
self::antiguaAndBarbuda->name => 'Antigua and Barbuda',
|
||||
self::argentina->name => 'Argentina',
|
||||
self::armenia->name => 'Armenia',
|
||||
self::aruba->name => 'Aruba',
|
||||
self::australia->name => 'Australia',
|
||||
self::austria->name => 'Austria',
|
||||
self::azerbaijan->name => 'Azerbaijan',
|
||||
self::bahrain->name => 'Bahrain',
|
||||
self::bahamas->name => 'Bahamas',
|
||||
self::bangladesh->name => 'Bangladesh',
|
||||
self::barbados->name => 'Barbados',
|
||||
self::belarus->name => 'Belarus',
|
||||
self::belgium->name => 'Belgium',
|
||||
self::belize->name => 'Belize',
|
||||
self::benin->name => 'Benin',
|
||||
self::bermuda->name => 'Bermuda',
|
||||
self::bhutan->name => 'Bhutan',
|
||||
self::boliviaPlurinationalStateOf->name => 'Bolivia, Plurinational State of',
|
||||
self::bonaireSintEustatiusAndSaba->name => 'Bonaire, Sint Eustatius and Saba',
|
||||
self::bosniaAndHerzegovina->name => 'Bosnia and Herzegovina',
|
||||
self::botswana->name => 'Botswana',
|
||||
self::bouvetIsland->name => 'Bouvet Island',
|
||||
self::brazil->name => 'Brazil',
|
||||
self::britishIndianOceanTerritory->name => 'British Indian Ocean Territory',
|
||||
self::bruneiDarussalam->name => 'Brunei Darussalam',
|
||||
self::bulgaria->name => 'Bulgaria',
|
||||
self::burkinaFaso->name => 'Burkina Faso',
|
||||
self::burundi->name => 'Burundi',
|
||||
self::cambodia->name => 'Cambodia',
|
||||
self::cameroon->name => 'Cameroon',
|
||||
self::canada->name => 'Canada',
|
||||
self::capeVerde->name => 'Cape Verde',
|
||||
self::caymanIslands->name => 'Cayman Islands',
|
||||
self::centralAfricanRepublic->name => 'Central African Republic',
|
||||
self::chad->name => 'Chad',
|
||||
self::chile->name => 'Chile',
|
||||
self::china->name => 'China',
|
||||
self::christmasIsland->name => 'Christmas Island',
|
||||
self::cocosKeelingIslands->name => 'Cocos (Keeling) Islands',
|
||||
self::colombia->name => 'Colombia',
|
||||
self::comoros->name => 'Comoros',
|
||||
self::congo->name => 'Congo',
|
||||
self::congoTheDemocraticRepublicOfThe->name => 'Congo, the Democratic Republic of the',
|
||||
self::cookIslands->name => 'Cook Islands',
|
||||
self::costaRica->name => 'Costa Rica',
|
||||
self::coteDivoire->name => 'Côte d\'Ivoire',
|
||||
self::croatia->name => 'Croatia',
|
||||
self::cuba->name => 'Cuba',
|
||||
self::curacao->name => 'Curaçao',
|
||||
self::cyprus->name => 'Cyprus',
|
||||
self::czechRepublic->name => 'Czech Republic',
|
||||
self::denmark->name => 'Denmark',
|
||||
self::djibouti->name => 'Djibouti',
|
||||
self::dominica->name => 'Dominica',
|
||||
self::dominicanRepublic->name => 'Dominican Republic',
|
||||
self::ecuador->name => 'Ecuador',
|
||||
self::egypt->name => 'Egypt',
|
||||
self::elSalvador->name => 'El Salvador',
|
||||
self::equatorialGuinea->name => 'Equatorial Guinea',
|
||||
self::eritrea->name => 'Eritrea',
|
||||
self::estonia->name => 'Estonia',
|
||||
self::ethiopia->name => 'Ethiopia',
|
||||
self::falklandIslandsMalvinas->name => 'Falkland Islands (Malvinas)',
|
||||
self::faroeIslands->name => 'Faroe Islands',
|
||||
self::fiji->name => 'Fiji',
|
||||
self::finland->name => 'Finland',
|
||||
self::france->name => 'France',
|
||||
self::frenchGuiana->name => 'French Guiana',
|
||||
self::frenchPolynesia->name => 'French Polynesia',
|
||||
self::frenchSouthernTerritories->name => 'French Southern Territories',
|
||||
self::gabon->name => 'Gabon',
|
||||
self::gambia->name => 'Gambia',
|
||||
self::georgia->name => 'Georgia',
|
||||
self::germany->name => 'Germany',
|
||||
self::ghana->name => 'Ghana',
|
||||
self::gibraltar->name => 'Gibraltar',
|
||||
self::greece->name => 'Greece',
|
||||
self::greenland->name => 'Greenland',
|
||||
self::grenada->name => 'Grenada',
|
||||
self::guadeloupe->name => 'Guadeloupe',
|
||||
self::guam->name => 'Guam',
|
||||
self::guatemala->name => 'Guatemala',
|
||||
self::guernsey->name => 'Guernsey',
|
||||
self::guinea->name => 'Guinea',
|
||||
self::guineaBissau->name => 'Guinea Bissau',
|
||||
self::guyana->name => 'Guyana',
|
||||
self::haiti->name => 'Haïti',
|
||||
self::heardIslandAndMcdonaldIslands->name => 'Heard Island and McDonald Islands',
|
||||
self::holySeeVaticanCityState->name => 'Holy See (Vatican City State)',
|
||||
self::honduras->name => 'Honduras',
|
||||
self::hongKong->name => 'Hong Kong',
|
||||
self::hungary->name => 'Hungary',
|
||||
self::iceland->name => 'Iceland',
|
||||
self::india->name => 'India',
|
||||
self::indonesia->name => 'Indonesia',
|
||||
self::iranIslamicRepublicOf->name => 'Iran, Islamic Republic of',
|
||||
self::iraq->name => 'Iraq',
|
||||
self::ireland->name => 'Ireland',
|
||||
self::isleOfMan->name => 'Isle of Man',
|
||||
self::israel->name => 'Israel',
|
||||
self::italy->name => 'Italy',
|
||||
self::jamaica->name => 'Jamaica',
|
||||
self::japan->name => 'Japan',
|
||||
self::jersey->name => 'Jersey',
|
||||
self::jordan->name => 'Jordan',
|
||||
self::kazakhstan->name => 'Kazakhstan',
|
||||
self::kenya->name => 'Kenya',
|
||||
self::kiribati->name => 'Kiribati',
|
||||
self::koreaDemocraticPeoplesRepublicOf->name => 'Korea, Democratic People\'s Republic of',
|
||||
self::koreaRepublicOf->name => 'Korea, Republic of',
|
||||
self::kuwait->name => 'Kuwait',
|
||||
self::kyrgyzstan->name => 'Kyrgyzstan',
|
||||
self::laoPeoplesDemocraticRepublic->name => 'Lao People\'s Democratic Republic',
|
||||
self::latvia->name => 'Latvia',
|
||||
self::lebanon->name => 'Lebanon',
|
||||
self::lesotho->name => 'Lesotho',
|
||||
self::liberia->name => 'Liberia',
|
||||
self::libya->name => 'Libya',
|
||||
self::liechtenstein->name => 'Liechtenstein',
|
||||
self::lithuania->name => 'Lithuania',
|
||||
self::luxembourg->name => 'Luxembourg',
|
||||
self::macao->name => 'Macao',
|
||||
self::macedoniaTheFormerYugoslavRepublicOf->name => 'Macedonia, the Former Yugoslav Republic of',
|
||||
self::madagascar->name => 'Madagascar',
|
||||
self::malawi->name => 'Malawi',
|
||||
self::malaysia->name => 'Malaysia',
|
||||
self::maldives->name => 'Maldives',
|
||||
self::mali->name => 'Mali',
|
||||
self::malta->name => 'Malta',
|
||||
self::marshallIslands->name => 'Marshall Islands',
|
||||
self::martinique->name => 'Martinique',
|
||||
self::mauritania->name => 'Mauritania',
|
||||
self::mauritius->name => 'Mauritius',
|
||||
self::mayotte->name => 'Mayotte',
|
||||
self::mexico->name => 'Mexico',
|
||||
self::micronesiaFederatedStatesOf->name => 'Micronesia, Federated States of',
|
||||
self::moldovaRepublicOf->name => 'Moldova, Republic of',
|
||||
self::monaco->name => 'Monaco',
|
||||
self::mongolia->name => 'Mongolia',
|
||||
self::montenegro->name => 'Montenegro',
|
||||
self::montserrat->name => 'Montserrat',
|
||||
self::morocco->name => 'Morocco',
|
||||
self::mozambique->name => 'Mozambique',
|
||||
self::myanmar->name => 'Myanmar',
|
||||
self::namibia->name => 'Namibia',
|
||||
self::nauru->name => 'Nauru',
|
||||
self::nepal->name => 'Nepal',
|
||||
self::netherlands->name => 'Netherlands',
|
||||
self::newCaledonia->name => 'New Caledonia',
|
||||
self::newZealand->name => 'New Zealand',
|
||||
self::nicaragua->name => 'Nicaragua',
|
||||
self::niger->name => 'Niger',
|
||||
self::nigeria->name => 'Nigeria',
|
||||
self::niue->name => 'Niue',
|
||||
self::norfolkIsland->name => 'Norfolk Island',
|
||||
self::northernMarianaIslands->name => 'Northern Mariana Islands',
|
||||
self::norway->name => 'Norway',
|
||||
self::oman->name => 'Oman',
|
||||
self::pakistan->name => 'Pakistan',
|
||||
self::palau->name => 'Palau',
|
||||
self::palestineStateOf->name => 'Palestine, State of',
|
||||
self::panama->name => 'Panama',
|
||||
self::papuaNewGuinea->name => 'Papua New Guinea',
|
||||
self::paraguay->name => 'Paraguay',
|
||||
self::peru->name => 'Peru',
|
||||
self::philippines->name => 'Philippines',
|
||||
self::pitcairn->name => 'Pitcairn',
|
||||
self::poland->name => 'Poland',
|
||||
self::portugal->name => 'Portugal',
|
||||
self::puertoRico->name => 'Puerto Rico',
|
||||
self::qatar->name => 'Qatar',
|
||||
self::reunion->name => 'Réunion',
|
||||
self::romania->name => 'Romania',
|
||||
self::russianFederation->name => 'Russian Federation',
|
||||
self::rwanda->name => 'Rwanda',
|
||||
self::saintBarthelemy->name => 'Saint Barthélemy',
|
||||
self::saintHelenaAscensionAndTristanDaCunha->name => 'Saint Helena, Ascension and Tristan da Cunha',
|
||||
self::saintKittsAndNevis->name => 'Saint Kitts and Nevis',
|
||||
self::saintLucia->name => 'Saint Lucia',
|
||||
self::saintMartinFrenchPart->name => 'Saint Martin (French part)',
|
||||
self::saintPierreAndMiquelon->name => 'Saint Pierre and Miquelon',
|
||||
self::saintVincentAndTheGrenadines->name => 'Saint Vincent and the Grenadines',
|
||||
self::samoa->name => 'Samoa',
|
||||
self::sanMarino->name => 'San Marino',
|
||||
self::saoTomeAndPrincipe->name => 'Sao Tome and Principe',
|
||||
self::saudiArabia->name => 'Saudi Arabia',
|
||||
self::senegal->name => 'Senegal',
|
||||
self::serbia->name => 'Serbia',
|
||||
self::seychelles->name => 'Seychelles',
|
||||
self::sierraLeone->name => 'Sierra Leone',
|
||||
self::singapore->name => 'Singapore',
|
||||
self::sintMaartenDutchPart->name => 'Sint Maarten (Dutch part)',
|
||||
self::slovakia->name => 'Slovakia',
|
||||
self::slovenia->name => 'Slovenia',
|
||||
self::solomonIslands->name => 'Solomon Islands',
|
||||
self::somalia->name => 'Somalia',
|
||||
self::southAfrica->name => 'South Africa',
|
||||
self::southGeorgiaAndTheSouthSandwichIslands->name => 'South Georgia and the South Sandwich Islands',
|
||||
self::southSudan->name => 'South Sudan',
|
||||
self::spain->name => 'Spain',
|
||||
self::sriLanka->name => 'Sri Lanka',
|
||||
self::sudan->name => 'Sudan',
|
||||
self::suriname->name => 'Suriname',
|
||||
self::svalbardAndJanMayen->name => 'Svalbard and Jan Mayen',
|
||||
self::swaziland->name => 'Swaziland',
|
||||
self::sweden->name => 'Sweden',
|
||||
self::switzerland->name => 'Switzerland',
|
||||
self::syrianArabRepublic->name => 'Syrian Arab Republic',
|
||||
self::taiwanProvinceOfChina->name => 'Taiwan, Province of China',
|
||||
self::tajikistan->name => 'Tajikistan',
|
||||
self::tanzaniaUnitedRepublicOf->name => 'Tanzania, United Republic of',
|
||||
self::thailand->name => 'Thailand',
|
||||
self::timorLeste->name => 'TimorLeste',
|
||||
self::togo->name => 'Togo',
|
||||
self::tokelau->name => 'Tokelau',
|
||||
self::tonga->name => 'Tonga',
|
||||
self::trinidadAndTobago->name => 'Trinidad and Tobago',
|
||||
self::tunisia->name => 'Tunisia',
|
||||
self::turkey->name => 'Turkey',
|
||||
self::turkmenistan->name => 'Turkmenistan',
|
||||
self::turksAndCaicosIslands->name => 'Turks and Caicos Islands',
|
||||
self::tuvalu->name => 'Tuvalu',
|
||||
self::uganda->name => 'Uganda',
|
||||
self::ukraine->name => 'Ukraine',
|
||||
self::unitedArabEmirates->name => 'United Arab Emirates',
|
||||
self::unitedKingdom->name => 'United Kingdom',
|
||||
self::unitedStates->name => 'United States',
|
||||
self::unitedStatesMinorOutlyingIslands->name => 'United States Minor Outlying Islands',
|
||||
self::uruguay->name => 'Uruguay',
|
||||
self::uzbekistan->name => 'Uzbekistan',
|
||||
self::vanuatu->name => 'Vanuatu',
|
||||
self::venezuelaBolivarianRepublicOf->name => 'Venezuela, Bolivarian Republic of',
|
||||
self::vietNam->name => 'Viet Nam',
|
||||
self::virginIslandsBritish->name => 'Virgin Islands, British',
|
||||
self::virginIslandsUs->name => 'Virgin Islands, U.S.',
|
||||
self::wallisAndFutuna->name => 'Wallis and Futuna',
|
||||
self::westernSahara->name => 'Western Sahara',
|
||||
self::yemen->name => 'Yemen',
|
||||
self::zambia->name => 'Zambia',
|
||||
self::zimbabwe->name => 'Zimbabwe',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get Valid Shipping Countries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function validShippingCountries(): array
|
||||
{
|
||||
return [
|
||||
self::france,
|
||||
/**
|
||||
* // * DROM COM .
|
||||
// self::guadeloupe,
|
||||
// self::martinique,
|
||||
// self::frenchGuiana,
|
||||
// self::reunion,
|
||||
// self::saintPierreAndMiquelon,
|
||||
// self::mayotte,
|
||||
// self::saintBarthelemy,
|
||||
// self::saintMartinFrenchPart,
|
||||
// self::wallisAndFutuna,
|
||||
// self::frenchPolynesia,
|
||||
// self::newCaledonia
|
||||
*/
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Valid Shipping Countries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function validBillingCountries(): array
|
||||
{
|
||||
return [
|
||||
self::france,
|
||||
// * DROM COM.
|
||||
self::guadeloupe,
|
||||
self::martinique,
|
||||
self::frenchGuiana,
|
||||
self::reunion,
|
||||
self::saintPierreAndMiquelon,
|
||||
self::mayotte,
|
||||
self::saintBarthelemy,
|
||||
self::saintMartinFrenchPart,
|
||||
self::wallisAndFutuna,
|
||||
self::frenchPolynesia,
|
||||
self::newCaledonia
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Alpha 2 ISO code of valid shipping countries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getValidShippingCountriesIsoAplha2Codes(): array
|
||||
{
|
||||
return ['FR'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Alpha 2 ISO code of valid billing countries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getValidBillingCountriesIsoAplha2Codes(): array
|
||||
{
|
||||
return \array_values(self::ISOCODES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom added ISOCODES definition
|
||||
*/
|
||||
private const ISOCODES = [
|
||||
self::afghanistan->name => 'AFG',
|
||||
self::alandIslands->name => 'ALA',
|
||||
self::albania->name => 'ALB',
|
||||
self::algeria->name => 'DZA',
|
||||
self::americanSamoa->name => 'ASM',
|
||||
self::andorra->name => 'AND',
|
||||
self::angola->name => 'AGO',
|
||||
self::anguilla->name => 'AIA',
|
||||
self::antarctica->name => 'AQ',
|
||||
self::antiguaAndBarbuda->name => 'ATG',
|
||||
self::argentina->name => 'ARG',
|
||||
self::armenia->name => 'ARM',
|
||||
self::aruba->name => 'ABW',
|
||||
self::australia->name => 'AUS',
|
||||
self::austria->name => 'AUT',
|
||||
self::azerbaijan->name => 'AZE',
|
||||
self::bahrain->name => 'BHR',
|
||||
self::bahamas->name => 'BHS',
|
||||
self::bangladesh->name => 'BGD',
|
||||
self::barbados->name => 'BRB',
|
||||
self::belarus->name => 'BLR',
|
||||
self::belgium->name => 'BEL',
|
||||
self::belize->name => 'BLZ',
|
||||
self::benin->name => 'BEN',
|
||||
self::bermuda->name => 'BMU',
|
||||
self::bhutan->name => 'BTN',
|
||||
self::boliviaPlurinationalStateOf->name => 'BOL',
|
||||
self::bonaireSintEustatiusAndSaba->name => 'BES',
|
||||
self::bosniaAndHerzegovina->name => 'BIH',
|
||||
self::botswana->name => 'BWA',
|
||||
self::bouvetIsland->name => 'BVT',
|
||||
self::brazil->name => 'BRA',
|
||||
self::britishIndianOceanTerritory->name => 'IOT',
|
||||
self::bruneiDarussalam->name => 'BRN',
|
||||
self::bulgaria->name => 'BGR',
|
||||
self::burkinaFaso->name => 'BFA',
|
||||
self::burundi->name => 'BDI',
|
||||
self::cambodia->name => 'KHM',
|
||||
self::cameroon->name => 'CMR',
|
||||
self::canada->name => 'CAN',
|
||||
self::capeVerde->name => 'CPV',
|
||||
self::caymanIslands->name => 'CYM',
|
||||
self::centralAfricanRepublic->name => 'CAF',
|
||||
self::chad->name => 'TCD',
|
||||
self::chile->name => 'CHL',
|
||||
self::china->name => 'CHN',
|
||||
self::christmasIsland->name => 'CXR',
|
||||
self::cocosKeelingIslands->name => 'CCK',
|
||||
self::colombia->name => 'COL',
|
||||
self::comoros->name => 'COM',
|
||||
self::congo->name => 'COG',
|
||||
self::congoTheDemocraticRepublicOfThe->name => 'COD',
|
||||
self::cookIslands->name => 'COK',
|
||||
self::costaRica->name => 'CRI',
|
||||
self::coteDivoire->name => 'CIV',
|
||||
self::croatia->name => 'HRV',
|
||||
self::cuba->name => 'CUB',
|
||||
self::curacao->name => 'CUW',
|
||||
self::cyprus->name => 'CYP',
|
||||
self::czechRepublic->name => 'CZE',
|
||||
self::denmark->name => 'DNK',
|
||||
self::djibouti->name => 'DJI',
|
||||
self::dominica->name => 'DMA',
|
||||
self::dominicanRepublic->name => 'DOM',
|
||||
self::ecuador->name => 'ECU',
|
||||
self::egypt->name => 'EGY',
|
||||
self::elSalvador->name => 'SLV',
|
||||
self::equatorialGuinea->name => 'GNQ',
|
||||
self::eritrea->name => 'ERI',
|
||||
self::estonia->name => 'EST',
|
||||
self::ethiopia->name => 'ETH',
|
||||
self::falklandIslandsMalvinas->name => 'FLK',
|
||||
self::faroeIslands->name => 'FRO',
|
||||
self::fiji->name => 'FJI',
|
||||
self::finland->name => 'FIN',
|
||||
self::france->name => 'FRA',
|
||||
self::frenchGuiana->name => 'GUF',
|
||||
self::frenchPolynesia->name => 'PYF',
|
||||
self::frenchSouthernTerritories->name => 'ATF',
|
||||
self::gabon->name => 'GAB',
|
||||
self::gambia->name => 'GMB',
|
||||
self::georgia->name => 'GEO',
|
||||
self::germany->name => 'DEU',
|
||||
self::ghana->name => 'GHA',
|
||||
self::gibraltar->name => 'GIB',
|
||||
self::greece->name => 'GRC',
|
||||
self::greenland->name => 'GRL',
|
||||
self::grenada->name => 'GRD',
|
||||
self::guadeloupe->name => 'GLP',
|
||||
self::guam->name => 'GUM',
|
||||
self::guatemala->name => 'GTM',
|
||||
self::guernsey->name => 'GGY',
|
||||
self::guinea->name => 'GIN',
|
||||
self::guineaBissau->name => 'GNB',
|
||||
self::guyana->name => 'GUY',
|
||||
self::haiti->name => 'HTI',
|
||||
self::heardIslandAndMcdonaldIslands->name => 'HMD',
|
||||
self::holySeeVaticanCityState->name => 'VAT',
|
||||
self::honduras->name => 'HND',
|
||||
self::hongKong->name => 'HKG',
|
||||
self::hungary->name => 'HUN',
|
||||
self::iceland->name => 'ISL',
|
||||
self::india->name => 'IND',
|
||||
self::indonesia->name => 'IDN',
|
||||
self::iranIslamicRepublicOf->name => 'IRN',
|
||||
self::iraq->name => 'IRQ',
|
||||
self::ireland->name => 'IRL',
|
||||
self::isleOfMan->name => 'IMN',
|
||||
self::israel->name => 'ISR',
|
||||
self::italy->name => 'ITA',
|
||||
self::jamaica->name => 'JAM',
|
||||
self::japan->name => 'JPN',
|
||||
self::jersey->name => 'JEY',
|
||||
self::jordan->name => 'JOR',
|
||||
self::kazakhstan->name => 'KAZ',
|
||||
self::kenya->name => 'KEN',
|
||||
self::kiribati->name => 'KIR',
|
||||
self::koreaDemocraticPeoplesRepublicOf->name => 'PRK',
|
||||
self::koreaRepublicOf->name => 'KOR',
|
||||
self::kuwait->name => 'KWT',
|
||||
self::kyrgyzstan->name => 'KGZ',
|
||||
self::laoPeoplesDemocraticRepublic->name => 'LAO',
|
||||
self::latvia->name => 'LVA',
|
||||
self::lebanon->name => 'LBN',
|
||||
self::lesotho->name => 'LSO',
|
||||
self::liberia->name => 'LBR',
|
||||
self::libya->name => 'LBY',
|
||||
self::liechtenstein->name => 'LIE',
|
||||
self::lithuania->name => 'LTU',
|
||||
self::luxembourg->name => 'LUX',
|
||||
self::macao->name => 'MAC',
|
||||
self::macedoniaTheFormerYugoslavRepublicOf->name => 'MKD',
|
||||
self::madagascar->name => 'MDG',
|
||||
self::malawi->name => 'MWI',
|
||||
self::malaysia->name => 'MYS',
|
||||
self::maldives->name => 'MDV',
|
||||
self::mali->name => 'MLI',
|
||||
self::malta->name => 'MLT',
|
||||
self::marshallIslands->name => 'MHL',
|
||||
self::martinique->name => 'MTQ',
|
||||
self::mauritania->name => 'MRT',
|
||||
self::mauritius->name => 'MUS',
|
||||
self::mayotte->name => 'MYT',
|
||||
self::mexico->name => 'MEX',
|
||||
self::micronesiaFederatedStatesOf->name => 'FSM',
|
||||
self::moldovaRepublicOf->name => 'MDA',
|
||||
self::monaco->name => 'MCO',
|
||||
self::mongolia->name => 'MNG',
|
||||
self::montenegro->name => 'MNE',
|
||||
self::montserrat->name => 'MSR',
|
||||
self::morocco->name => 'MAR',
|
||||
self::mozambique->name => 'MOZ',
|
||||
self::myanmar->name => 'MMR',
|
||||
self::namibia->name => 'NAM',
|
||||
self::nauru->name => 'NRU',
|
||||
self::nepal->name => 'NPL',
|
||||
self::netherlands->name => 'NLD',
|
||||
self::newCaledonia->name => 'NCL',
|
||||
self::newZealand->name => 'NZL',
|
||||
self::nicaragua->name => 'NIC',
|
||||
self::niger->name => 'NER',
|
||||
self::nigeria->name => 'NGA',
|
||||
self::niue->name => 'NIU',
|
||||
self::norfolkIsland->name => 'NFK',
|
||||
self::northernMarianaIslands->name => 'MNP',
|
||||
self::norway->name => 'NOR',
|
||||
self::oman->name => 'OMN',
|
||||
self::pakistan->name => 'PAK',
|
||||
self::palau->name => 'PLW',
|
||||
self::palestineStateOf->name => 'PSE',
|
||||
self::panama->name => 'PAN',
|
||||
self::papuaNewGuinea->name => 'PNG',
|
||||
self::paraguay->name => 'PRY',
|
||||
self::peru->name => 'PER',
|
||||
self::philippines->name => 'PHL',
|
||||
self::pitcairn->name => 'PCN',
|
||||
self::poland->name => 'POL',
|
||||
self::portugal->name => 'PRT',
|
||||
self::puertoRico->name => 'PRI',
|
||||
self::qatar->name => 'QAT',
|
||||
self::reunion->name => 'REU',
|
||||
self::romania->name => 'ROU',
|
||||
self::russianFederation->name => 'RUS',
|
||||
self::rwanda->name => 'RWA',
|
||||
self::saintBarthelemy->name => 'BLM',
|
||||
self::saintHelenaAscensionAndTristanDaCunha->name => 'SHN',
|
||||
self::saintKittsAndNevis->name => 'KNA',
|
||||
self::saintLucia->name => 'LCA',
|
||||
self::saintMartinFrenchPart->name => 'MAF',
|
||||
self::saintPierreAndMiquelon->name => 'SPM',
|
||||
self::saintVincentAndTheGrenadines->name => 'VCT',
|
||||
self::samoa->name => 'WSM',
|
||||
self::sanMarino->name => 'SMR',
|
||||
self::saoTomeAndPrincipe->name => 'STP',
|
||||
self::saudiArabia->name => 'SAU',
|
||||
self::senegal->name => 'SEN',
|
||||
self::serbia->name => 'SRB',
|
||||
self::seychelles->name => 'SYC',
|
||||
self::sierraLeone->name => 'SLE',
|
||||
self::singapore->name => 'SGP',
|
||||
self::sintMaartenDutchPart->name => 'SXM',
|
||||
self::slovakia->name => 'SVK',
|
||||
self::slovenia->name => 'SVN',
|
||||
self::solomonIslands->name => 'SLB',
|
||||
self::somalia->name => 'SOM',
|
||||
self::southAfrica->name => 'ZAF',
|
||||
self::southGeorgiaAndTheSouthSandwichIslands->name => 'SGS',
|
||||
self::southSudan->name => 'SSD',
|
||||
self::spain->name => 'ESP',
|
||||
self::sriLanka->name => 'LKA',
|
||||
self::sudan->name => 'SDN',
|
||||
self::suriname->name => 'SUR',
|
||||
self::svalbardAndJanMayen->name => 'SJM',
|
||||
self::swaziland->name => 'SWZ',
|
||||
self::sweden->name => 'SWE',
|
||||
self::switzerland->name => 'CHE',
|
||||
self::syrianArabRepublic->name => 'SYR',
|
||||
self::taiwanProvinceOfChina->name => 'TWN',
|
||||
self::tajikistan->name => 'TJK',
|
||||
self::tanzaniaUnitedRepublicOf->name => 'TZA',
|
||||
self::thailand->name => 'THA',
|
||||
self::timorLeste->name => 'TLS',
|
||||
self::togo->name => 'TGO',
|
||||
self::tokelau->name => 'TKL',
|
||||
self::tonga->name => 'TON',
|
||||
self::trinidadAndTobago->name => 'TTO',
|
||||
self::tunisia->name => 'TUN',
|
||||
self::turkey->name => 'TUR',
|
||||
self::turkmenistan->name => 'TKM',
|
||||
self::turksAndCaicosIslands->name => 'TCA',
|
||||
self::tuvalu->name => 'TUV',
|
||||
self::uganda->name => 'UGA',
|
||||
self::ukraine->name => 'UKR',
|
||||
self::unitedArabEmirates->name => 'ARE',
|
||||
self::unitedKingdom->name => 'GBR',
|
||||
self::unitedStates->name => 'USA',
|
||||
self::unitedStatesMinorOutlyingIslands->name => 'UMI',
|
||||
self::uruguay->name => 'URY',
|
||||
self::uzbekistan->name => 'UZB',
|
||||
self::vanuatu->name => 'VUT',
|
||||
self::venezuelaBolivarianRepublicOf->name => 'VEN',
|
||||
self::vietNam->name => 'VNM',
|
||||
self::virginIslandsBritish->name => 'VGB',
|
||||
self::virginIslandsUs->name => 'VIR',
|
||||
self::wallisAndFutuna->name => 'WLF',
|
||||
self::westernSahara->name => 'ESH',
|
||||
self::yemen->name => 'YEM',
|
||||
self::zambia->name => 'ZMB',
|
||||
self::zimbabwe->name => 'ZWE',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get ISOCODE
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function iso(): string
|
||||
{
|
||||
return self::ISOCODES[$this->name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enum ISOCODES
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function toIsoCodes(): array
|
||||
{
|
||||
return self::ISOCODES;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,10 @@ enum InputType: int
|
|||
case string = 11;
|
||||
case text = 12;
|
||||
case url = 13;
|
||||
case videoVimeo = 14;
|
||||
case videoYoutube = 15;
|
||||
/** Vimeo only */
|
||||
case videoVimeo = 14;
|
||||
/** Youtube only */
|
||||
case videoYoutube = 15;
|
||||
/** Youtube or Vimeo. */
|
||||
case video = 16;
|
||||
}
|
||||
|
|
|
|||
27
app/Enums/Listen/ObjectEnum.php
Normal file
27
app/Enums/Listen/ObjectEnum.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Listen;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ObjectEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case remark = 1;
|
||||
case sponsoring = 2;
|
||||
case service = 3;
|
||||
case other = 4;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::remark->name => 'Contact Commercial ou remarque sur nos produits',
|
||||
self::sponsoring->name => 'Demande de partenariat ou sponsoring',
|
||||
self::service->name => 'Proposition de service au fournisseur',
|
||||
self::other->name => 'Autre demande',
|
||||
];
|
||||
}
|
||||
16
app/Enums/Pagination/ItemsPerPaginationEnum.php
Normal file
16
app/Enums/Pagination/ItemsPerPaginationEnum.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Pagination;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ItemsPerPaginationEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case five = 5;
|
||||
case twelve = 12;
|
||||
case twentyfive = 25;
|
||||
case fifty = 50;
|
||||
case onehundred = 100;
|
||||
}
|
||||
161
app/Enums/Sections/PageSectionEnum.php
Normal file
161
app/Enums/Sections/PageSectionEnum.php
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Sections;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum PageSectionEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case home_missions = 1;
|
||||
case home_ambition = 2;
|
||||
case home_team = 3;
|
||||
case home_life = 4;
|
||||
case unveil_pole = 5;
|
||||
case unveil_missions = 6;
|
||||
case unveil_local = 7;
|
||||
case unveil_sites = 8;
|
||||
case unveil_history = 9;
|
||||
case unveil_commitments = 10;
|
||||
case hire_life = 11;
|
||||
case hire_formation = 12;
|
||||
case hire_grow = 13;
|
||||
case hire_parity = 14;
|
||||
case hire_find = 15;
|
||||
case commit_ambition = 16;
|
||||
case commit_breeding = 17;
|
||||
case commit_living = 18;
|
||||
case commit_respect_earth = 19;
|
||||
case commit_feed = 20;
|
||||
case commit_commitments = 21;
|
||||
case move_life = 22;
|
||||
case move_commitments = 23;
|
||||
case produce_local = 24;
|
||||
case produce_gms = 25;
|
||||
case produce_rhd = 26;
|
||||
case produce_export = 27;
|
||||
case produce_quality = 28;
|
||||
case produce_linking = 29;
|
||||
case listening_study = 30;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::home_missions->name => 'Nos Missions',
|
||||
self::home_ambition->name => 'Notre Ambition',
|
||||
self::home_team->name => 'L\'équipe VOLENA',
|
||||
self::home_life->name => 'La vie chez VOLENA',
|
||||
self::unveil_pole->name => 'Le Pôle Volena',
|
||||
self::unveil_missions->name => 'Nos Missions',
|
||||
self::unveil_local->name => 'Notre Filière Locale',
|
||||
self::unveil_sites->name => 'Nos Sites',
|
||||
self::unveil_history->name => 'Histoire',
|
||||
self::unveil_commitments->name => 'Engagements',
|
||||
self::hire_life->name => 'Vie de l\'Entreprise',
|
||||
self::hire_formation->name => 'Alternance et Formation',
|
||||
self::hire_grow->name => 'Fiers d\'évoluer ensemble',
|
||||
self::hire_parity->name => 'Parité',
|
||||
self::hire_find->name => 'On se retrouve',
|
||||
self::commit_ambition->name => 'Ambition',
|
||||
self::commit_breeding->name => 'Elever Durablement',
|
||||
self::commit_living->name => 'Mieux vivre',
|
||||
self::commit_respect_earth->name => 'Respecter la terre',
|
||||
self::commit_feed->name => 'Bien nourrir',
|
||||
self::commit_commitments->name => 'Engagements',
|
||||
self::move_life->name => 'Vie de l\'Entreprise',
|
||||
self::move_commitments->name => 'Engagements',
|
||||
self::produce_local->name => 'Large Gamme Locale',
|
||||
self::produce_gms->name => 'Retrouvez en GMS',
|
||||
self::produce_rhd->name => 'RHD',
|
||||
self::produce_export->name => 'Export',
|
||||
self::produce_quality->name => 'Qualité',
|
||||
self::produce_linking->name => 'Liens',
|
||||
self::listening_study->name => 'On étudie',
|
||||
];
|
||||
|
||||
/**
|
||||
* Does the section have datas ?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function containsData(): bool
|
||||
{
|
||||
return match ($this) {
|
||||
self::home_missions,
|
||||
self::home_ambition,
|
||||
self::home_team,
|
||||
self::home_life,
|
||||
self::unveil_pole,
|
||||
self::hire_grow,
|
||||
self::hire_parity,
|
||||
self::commit_breeding,
|
||||
self::commit_living,
|
||||
self::commit_respect_earth,
|
||||
self::commit_feed,
|
||||
self::move_commitments,
|
||||
self::produce_linking => true,
|
||||
self::unveil_missions,
|
||||
self::unveil_local,
|
||||
self::unveil_sites,
|
||||
self::unveil_history,
|
||||
self::unveil_commitments,
|
||||
self::hire_life,
|
||||
self::hire_formation,
|
||||
self::hire_find,
|
||||
self::commit_ambition,
|
||||
self::commit_commitments,
|
||||
self::move_life,
|
||||
self::produce_local,
|
||||
self::produce_gms,
|
||||
self::produce_rhd,
|
||||
self::produce_export,
|
||||
self::produce_quality,
|
||||
self::listening_study => false,
|
||||
}; //end match
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ckEditor type for the first WYSIWYG content of the section.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFirstWysiwygType(): string|null
|
||||
{
|
||||
return match ($this) {
|
||||
self::home_missions,
|
||||
self::home_ambition,
|
||||
self::home_team,
|
||||
self::home_life,
|
||||
self::unveil_sites,
|
||||
self::unveil_history,
|
||||
self::unveil_commitments => \App\Enums\CkEditorConfigName::base->label(),
|
||||
self::unveil_pole,
|
||||
self::unveil_missions,
|
||||
self::unveil_local,
|
||||
self::hire_life,
|
||||
self::hire_formation,
|
||||
self::hire_parity,
|
||||
self::hire_find,
|
||||
self::commit_ambition,
|
||||
self::commit_breeding,
|
||||
self::commit_living,
|
||||
self::commit_respect_earth,
|
||||
self::commit_feed,
|
||||
self::commit_commitments,
|
||||
self::move_life,
|
||||
self::move_commitments,
|
||||
self::produce_local,
|
||||
self::produce_gms,
|
||||
self::produce_rhd,
|
||||
self::produce_export,
|
||||
self::produce_quality,
|
||||
self::listening_study => \App\Enums\CkEditorConfigName::advanced->label(),
|
||||
self::produce_linking,
|
||||
self::hire_grow, => null,
|
||||
}; //end match
|
||||
}
|
||||
}
|
||||
33
app/Enums/Sites/SpeciesEnum.php
Normal file
33
app/Enums/Sites/SpeciesEnum.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Sites;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum SpeciesEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case chicken = 1;
|
||||
case turkey = 2;
|
||||
case hen = 3;
|
||||
case duck = 4;
|
||||
case rabbit = 5;
|
||||
case guinea_fowl = 6;
|
||||
case rooster = 7;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::chicken->name => 'Poulet',
|
||||
self::turkey->name => 'Dinde',
|
||||
self::hen->name => 'Poule',
|
||||
self::duck->name => 'Canard',
|
||||
self::rabbit->name => 'Lapin',
|
||||
self::guinea_fowl->name => 'Pintade',
|
||||
self::rooster->name => 'Coq',
|
||||
];
|
||||
}
|
||||
25
app/Enums/Slides/SliderTypeEnum.php
Normal file
25
app/Enums/Slides/SliderTypeEnum.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Slides;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum SliderTypeEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case home = 1;
|
||||
case better_life = 2;
|
||||
case respect_earth = 3;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::home->name => 'Accueil',
|
||||
self::better_life->name => 'Mieux vivre',
|
||||
self::respect_earth->name => 'Respecter la terre',
|
||||
];
|
||||
}
|
||||
80
app/Enums/StaticPageType.php
Normal file
80
app/Enums/StaticPageType.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum StaticPageType: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case contact = 1;
|
||||
case legals = 2;
|
||||
case confidentiality = 3;
|
||||
case home = 4;
|
||||
case unveil = 5;
|
||||
case we_hire = 6;
|
||||
case we_commit = 7;
|
||||
case we_move = 8;
|
||||
case we_produce = 9;
|
||||
case we_listen = 10;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::contact->name => 'Contact',
|
||||
self::legals->name => 'Mentions légales',
|
||||
self::confidentiality->name => 'Confidentialité',
|
||||
self::home->name => 'Accueil',
|
||||
self::unveil->name => 'On se Dévoile',
|
||||
self::we_hire->name => 'On Embauche',
|
||||
self::we_commit->name => 'On s\'Engage',
|
||||
self::we_move->name => 'On Bouge Ensemble',
|
||||
self::we_produce->name => 'On Produit',
|
||||
self::we_listen->name => 'On Vous Ecoute',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the enums for the page which contains sections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function containsSection(): array
|
||||
{
|
||||
return [
|
||||
self::home,
|
||||
self::unveil,
|
||||
self::we_hire,
|
||||
self::we_commit,
|
||||
self::we_move,
|
||||
self::we_produce,
|
||||
self::we_listen,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the static page need to fill its 'content' column ?
|
||||
*
|
||||
* @return boolean
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
*/
|
||||
public function containsContent(): bool
|
||||
{
|
||||
// @phpcs:enable
|
||||
return match ($this) {
|
||||
self::contact => false,
|
||||
self::legals => false,
|
||||
self::confidentiality => true,
|
||||
self::home => false,
|
||||
self::unveil => false,
|
||||
self::we_hire => false,
|
||||
self::we_commit => false,
|
||||
self::we_move => false,
|
||||
self::we_produce => false,
|
||||
self::we_listen => true,
|
||||
};
|
||||
}
|
||||
}
|
||||
98
app/Enums/Strips/PictoEnum.php
Normal file
98
app/Enums/Strips/PictoEnum.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Strips;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum PictoEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case none = 1;
|
||||
case danger = 2;
|
||||
case respect_earth = 3;
|
||||
case breeding = 4;
|
||||
case feed = 5;
|
||||
case better_life = 6;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::none->name => 'Aucun',
|
||||
self::danger->name => 'Danger',
|
||||
self::respect_earth->name => 'Respecter la terre',
|
||||
self::breeding->name => 'Elever Durablement',
|
||||
self::feed->name => 'Bien Nourrir',
|
||||
self::better_life->name => 'Mieux vivre en équipe',
|
||||
];
|
||||
|
||||
/**
|
||||
* Pictures paths.
|
||||
*/
|
||||
private const PICTURES = [
|
||||
self::none->name => '',
|
||||
self::danger->name => 'resources/assets/images/pictos/danger.png',
|
||||
self::respect_earth->name => 'resources/assets/images/pictos/respect_earth.png',
|
||||
self::breeding->name => 'resources/assets/images/pictos/breeding.png',
|
||||
self::feed->name => 'resources/assets/images/pictos/feed.png',
|
||||
self::better_life->name => 'resources/assets/images/pictos/better_life.png',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get picture path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function picture(): string
|
||||
{
|
||||
return self::PICTURES[$this->name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Alt attributes for pictures.
|
||||
*/
|
||||
private const ALTS = [
|
||||
self::none->name => '',
|
||||
self::danger->name => 'Pictogramme pour la catégorie \'Danger\'',
|
||||
self::respect_earth->name => 'Pictogramme pour la catégorie \'Respecter la terre\'',
|
||||
self::breeding->name => 'Pictogramme pour la catégorie \'Elever durablement\'',
|
||||
self::feed->name => 'Pictogramme pour la catégorie \'Bien nourrir\'',
|
||||
self::better_life->name => 'Pictogramme pour la catégorie \'Mieux vivre en équipe\'',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get picture alt attribute
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function alt(): string
|
||||
{
|
||||
return self::ALTS[$this->name];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Alt attributes for pictures.
|
||||
*/
|
||||
private const TITLES = [
|
||||
self::none->name => '',
|
||||
self::danger->name => 'Pictogramme pour la catégorie \'Danger\'',
|
||||
self::respect_earth->name => 'Pictogramme pour la catégorie \'Respecter la terre\'',
|
||||
self::breeding->name => 'Pictogramme pour la catégorie \'Elever durablement\'',
|
||||
self::feed->name => 'Pictogramme pour la catégorie \'Bien nourrir\'',
|
||||
self::better_life->name => 'Pictogramme pour la catégorie \'Mieux vivre en équipe\'',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get picture alt attribute
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return self::TITLES[$this->name];
|
||||
}
|
||||
}
|
||||
50
app/Enums/Testimonials/TypeEnum.php
Normal file
50
app/Enums/Testimonials/TypeEnum.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Testimonials;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum TypeEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case breeding = 1;
|
||||
case better_life = 2;
|
||||
case respect_earth = 3;
|
||||
case feed = 4;
|
||||
case volena = 5;
|
||||
case hire = 6;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::breeding->name => 'Elever Durablement',
|
||||
self::better_life->name => 'Mieux vivre en équipe',
|
||||
self::respect_earth->name => 'Respecter la terre',
|
||||
self::feed->name => 'Bien Nourrir',
|
||||
self::volena->name => 'Voléna',
|
||||
self::hire->name => 'On Embauche',
|
||||
];
|
||||
|
||||
private const COLORS = [
|
||||
self::breeding->name => 'tertiary',
|
||||
self::better_life->name => 'quad',
|
||||
self::respect_earth->name => 'quint',
|
||||
self::feed->name => 'sixt',
|
||||
self::volena->name => 'primary',
|
||||
self::hire->name => 'primary',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get color name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function color(): string
|
||||
{
|
||||
return self::COLORS[$this->name];
|
||||
}
|
||||
}
|
||||
23
app/Enums/Theme/BootstrapThemeEnum.php
Normal file
23
app/Enums/Theme/BootstrapThemeEnum.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Theme;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum BootstrapThemeEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case light = 1;
|
||||
case dark = 2;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::light->name => 'enums.bootstrap-theme.light',
|
||||
self::dark->name => 'enums.bootstrap-theme.dark',
|
||||
];
|
||||
}
|
||||
25
app/Enums/Users/RoleEnum.php
Normal file
25
app/Enums/Users/RoleEnum.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Users;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum RoleEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case conceptor = 1;
|
||||
case admin = 2;
|
||||
case visitor = 3;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::conceptor->name => 'enums.user-role.conceptor',
|
||||
self::admin->name => 'enums.user-role.admin',
|
||||
self::visitor->name => 'enums.user-role.visitor',
|
||||
];
|
||||
}
|
||||
69
app/Http/Controllers/Bo/ActivityLogController.php
Normal file
69
app/Http/Controllers/Bo/ActivityLogController.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ActivityLogController extends Controller
|
||||
{
|
||||
use ChangesModelOrder;
|
||||
use UpdateModelPublished;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = ActivityLog::query()->with('user');
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$query,
|
||||
$search,
|
||||
null,
|
||||
'model_class',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
trans('validation.custom.target'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($query);
|
||||
|
||||
/** Custom pagination */
|
||||
$activitylogModels = $this->paginate($query);
|
||||
|
||||
return view('bo.pages.activity_logs.index', compact('activitylogModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\ActivityLog $activity_log
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show(ActivityLog $activity_log): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$targetModelClass = $activity_log->model_class;
|
||||
$targetModel = $activity_log->model_class::where(
|
||||
(new $targetModelClass())->getRouteKeyName(),
|
||||
$activity_log->model_id
|
||||
)->first();
|
||||
|
||||
return view('bo.pages.activity_logs.show', [
|
||||
'activitylogModel' => $activity_log,
|
||||
'targetModel' => $targetModel,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,8 @@
|
|||
namespace App\Http\Controllers\Bo\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class LoginController extends Controller
|
||||
|
|
@ -27,7 +26,7 @@ class LoginController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\Auth\StatefulGuard
|
||||
*/
|
||||
protected function guard(): StatefulGuard
|
||||
protected function guard(): \Illuminate\Contracts\Auth\StatefulGuard
|
||||
{
|
||||
return Auth::guard('backend');
|
||||
}
|
||||
|
|
@ -37,7 +36,7 @@ class LoginController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function showLoginForm(): View
|
||||
public function showLoginForm(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.auth.login');
|
||||
}
|
||||
|
|
@ -51,4 +50,21 @@ class LoginController extends Controller
|
|||
{
|
||||
return response()->redirectToIntended()->getTargetUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to log the user into the application.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return boolean
|
||||
*/
|
||||
protected function attemptLogin(Request $request): bool
|
||||
{
|
||||
$credentials = $this->credentials($request);
|
||||
// * Attempt login only using published users.
|
||||
$credentials['published'] = true;
|
||||
return $this->guard()->attempt(
|
||||
$credentials,
|
||||
$request->boolean('remember')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Http\Controllers\Bo\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
|
@ -16,7 +15,7 @@ class ResetPasswordController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\Auth\StatefulGuard
|
||||
*/
|
||||
protected function guard(): StatefulGuard
|
||||
protected function guard(): \Illuminate\Contracts\Auth\StatefulGuard
|
||||
{
|
||||
return Auth::guard('backend');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
|
|
@ -12,7 +11,7 @@ class DashboardController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): View
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.dashboard');
|
||||
}
|
||||
|
|
|
|||
167
app/Http/Controllers/Bo/HistoricalMilestoneController.php
Normal file
167
app/Http/Controllers/Bo/HistoricalMilestoneController.php
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\HistoricalMilestones\StoreHistoricalMilestoneRequest;
|
||||
use App\Http\Requests\Bo\HistoricalMilestones\UpdateHistoricalMilestoneRequest;
|
||||
use App\Models\HistoricalMilestone;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class HistoricalMilestoneController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(HistoricalMilestone::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $historicalMilestoneModels */
|
||||
$historicalMilestoneModels = HistoricalMilestone::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->input('search');
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$historicalMilestoneModels,
|
||||
$search,
|
||||
null,
|
||||
'title',
|
||||
'year',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(trans('validation.attributes.title')),
|
||||
trans('validation.attributes.year'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($historicalMilestoneModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$historicalMilestoneModels = $this->paginate($historicalMilestoneModels);
|
||||
|
||||
return view(
|
||||
'bo.pages.historicalmilestones.index',
|
||||
compact('historicalMilestoneModels', 'search', 'searchFields')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\HistoricalMilestone $historicalMilestone
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(HistoricalMilestone $historicalMilestone): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.historicalmilestones.create', ['historicalMilestoneModel' => $historicalMilestone]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\HistoricalMilestones\StoreHistoricalMilestoneRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreHistoricalMilestoneRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$historicalMilestone = new HistoricalMilestone();
|
||||
$historicalMilestone->fill($request->validated());
|
||||
|
||||
if ($historicalMilestone->saveOrFail()) {
|
||||
return redirect()->route('bo.historicalmilestones.edit', $historicalMilestone)
|
||||
->with('success', trans('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.historicalMilestone', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.historicalMilestone', 1))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\HistoricalMilestone $historicalMilestone
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(HistoricalMilestone $historicalMilestone): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.historicalmilestones.edit', ['historicalMilestoneModel' => $historicalMilestone]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\HistoricalMilestones\UpdateHistoricalMilestoneRequest $request
|
||||
* @param \App\Models\HistoricalMilestone $historicalMilestone
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(
|
||||
UpdateHistoricalMilestoneRequest $request,
|
||||
HistoricalMilestone $historicalMilestone
|
||||
): \Illuminate\Http\RedirectResponse {
|
||||
return DB::transaction(function () use ($request, $historicalMilestone) {
|
||||
$historicalMilestone->fill($request->validated());
|
||||
|
||||
if ($historicalMilestone->saveOrFail()) {
|
||||
return redirect()->route('bo.historicalmilestones.edit', $historicalMilestone)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.historicalMilestone', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.historicalmilestones.edit', $historicalMilestone)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.historicalMilestone', 1))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\HistoricalMilestone $historicalMilestone
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(HistoricalMilestone $historicalMilestone): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($historicalMilestone->deleteOrFail()) {
|
||||
return redirect()->route('bo.historicalmilestones.index')
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.historicalMilestone', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.historicalMilestone', 1))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\HistoricalMilestone $historicalMilestone
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(HistoricalMilestone $historicalMilestone): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($historicalMilestone->replicate());
|
||||
}
|
||||
}
|
||||
167
app/Http/Controllers/Bo/JobVideoController.php
Normal file
167
app/Http/Controllers/Bo/JobVideoController.php
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\JobVideos\StoreJobVideoRequest;
|
||||
use App\Http\Requests\Bo\JobVideos\UpdateJobVideoRequest;
|
||||
use App\Models\JobVideo;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class JobVideoController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(JobVideo::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $jobVideoModels */
|
||||
$jobVideoModels = JobVideo::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->input('search');
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$jobVideoModels,
|
||||
$search,
|
||||
null,
|
||||
'title',
|
||||
'place',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(trans('validation.attributes.title')),
|
||||
trans('validation.custom.place'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($jobVideoModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$jobVideoModels = $this->paginate($jobVideoModels);
|
||||
|
||||
return view(
|
||||
'bo.pages.job_videos.index',
|
||||
compact('jobVideoModels', 'search', 'searchFields')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\JobVideo $jobVideo
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(JobVideo $jobVideo): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.job_videos.create', ['jobVideoModel' => $jobVideo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\JobVideos\StoreJobVideoRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreJobVideoRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$jobVideo = new JobVideo();
|
||||
$jobVideo->fill($request->validated());
|
||||
|
||||
if ($jobVideo->saveOrFail()) {
|
||||
return redirect()->route('bo.jobvideos.edit', $jobVideo)
|
||||
->with('success', trans('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\JobVideo $jobVideo
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(JobVideo $jobVideo): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.job_videos.edit', ['jobVideoModel' => $jobVideo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\JobVideos\UpdateJobVideoRequest $request
|
||||
* @param \App\Models\JobVideo $jobVideo
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(
|
||||
UpdateJobVideoRequest $request,
|
||||
JobVideo $jobVideo
|
||||
): \Illuminate\Http\RedirectResponse {
|
||||
return DB::transaction(function () use ($request, $jobVideo) {
|
||||
$jobVideo->fill($request->validated());
|
||||
|
||||
if ($jobVideo->saveOrFail()) {
|
||||
return redirect()->route('bo.jobvideos.edit', $jobVideo)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.jobvideos.edit', $jobVideo)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\JobVideo $jobVideo
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(JobVideo $jobVideo): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($jobVideo->deleteOrFail()) {
|
||||
return redirect()->route('bo.jobvideos.index')
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\JobVideo $jobVideo
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(JobVideo $jobVideo): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($jobVideo->replicate());
|
||||
}
|
||||
}
|
||||
161
app/Http/Controllers/Bo/LogoController.php
Normal file
161
app/Http/Controllers/Bo/LogoController.php
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Logos\StoreLogoRequest;
|
||||
use App\Http\Requests\Bo\Logos\UpdateLogoRequest;
|
||||
use App\Models\Logo;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LogoController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Logo::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $logoModels */
|
||||
$logoModels = Logo::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$logoModels,
|
||||
$search,
|
||||
null,
|
||||
'label',
|
||||
'picture_alt',
|
||||
'picture_title',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(trans('validation.custom.label')),
|
||||
trans('validation.custom.alt_attribute'),
|
||||
trans('validation.custom.title_attribute'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($logoModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$logoModels = $this->paginate($logoModels);
|
||||
|
||||
return view('bo.pages.logos.index', compact('logoModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\Logo $logo
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(Logo $logo): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.logos.create', ['logoModel' => $logo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Logos\StoreLogoRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreLogoRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$logo = new Logo();
|
||||
|
||||
if ($logo->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.logos.edit', $logo)
|
||||
->with('success', trans('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.logo'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.logo'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Logo $logo
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Logo $logo): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.logos.edit', ['logoModel' => $logo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Logos\UpdateLogoRequest $request
|
||||
* @param \App\Models\Logo $logo
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateLogoRequest $request, Logo $logo): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $logo) {
|
||||
if ($logo->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.logos.edit', $logo)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.logo'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.logos.edit', $logo)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.logo'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Logo $logo
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Logo $logo): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($logo->deleteOrFail()) {
|
||||
return redirect()->route('bo.logos.index')
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.logo'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.logo'))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\Logo $logo
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(Logo $logo): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($logo->replicate());
|
||||
}
|
||||
}
|
||||
166
app/Http/Controllers/Bo/NewsController.php
Normal file
166
app/Http/Controllers/Bo/NewsController.php
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\News\StoreNewsRequest;
|
||||
use App\Http\Requests\Bo\News\UpdateNewsRequest;
|
||||
use App\Models\News;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
use ChangesModelOrder;
|
||||
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(News::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $newsModels */
|
||||
$newsModels = News::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$newsModels,
|
||||
$search,
|
||||
null,
|
||||
'title',
|
||||
'introduction',
|
||||
'content',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(trans('validation.attributes.title')),
|
||||
trans('validation.custom.introduction'),
|
||||
trans('validation.attributes.content'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($newsModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$newsModels = $this->paginate($newsModels);
|
||||
|
||||
return view('bo.pages.news.index', compact('newsModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(News $news): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.news.create', ['newsModel' => $news]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\News\StoreNewsRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreNewsRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$news = new News();
|
||||
|
||||
if ($news->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.news.edit', $news)
|
||||
->with('success', trans('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(News $news): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.news.edit', ['newsModel' => $news]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\News\UpdateNewsRequest $request
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateNewsRequest $request, News $news): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $news) {
|
||||
if ($news->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.news.edit', $news)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.news.edit', $news)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(News $news): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($news->deleteOrFail()) {
|
||||
return redirect()->route('bo.news.index')
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(News $news): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($news->replicate());
|
||||
}
|
||||
}
|
||||
112
app/Http/Controllers/Bo/SectionController.php
Normal file
112
app/Http/Controllers/Bo/SectionController.php
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Enums\StaticPageType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Sections\UpdateSectionRequest;
|
||||
use App\Models\Section;
|
||||
use App\Models\StaticPage;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SectionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Section::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = Section::query()->with('page');
|
||||
|
||||
// Filter by related page if requested.
|
||||
if (
|
||||
$request->related_page &&
|
||||
null !== StaticPage::where('type', \collect(StaticPageType::all())
|
||||
->where('name', $request->related_page)->first())->first()
|
||||
) {
|
||||
$query = $query->whereBelongsTo(
|
||||
StaticPage::where(
|
||||
'type',
|
||||
\collect(StaticPageType::all())->where('name', $request->related_page)->first()
|
||||
)->first(),
|
||||
'page'
|
||||
);
|
||||
}
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$query,
|
||||
$search,
|
||||
null,
|
||||
'h2_title',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(__('validation.custom.h2_title')),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($query);
|
||||
|
||||
/** Custom pagination */
|
||||
$sectionModelList = $this->paginate($query);
|
||||
|
||||
return view('bo.pages.sections.index', compact('sectionModelList', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Section $section
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Section $section): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.sections.edit', ['sectionModel' => $section]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Sections\UpdateSectionRequest $request
|
||||
* @param \App\Models\Section $section
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateSectionRequest $request, Section $section): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $section) {
|
||||
$section->fill(array_replace_recursive(
|
||||
\json_decode(\json_encode($section->toArray()), true),
|
||||
$request->validated()
|
||||
));
|
||||
|
||||
|
||||
if ($section->saveOrFail()) {
|
||||
return redirect()->route('bo.sections.edit', $section)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.section'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.sections.edit', $section)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.section'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
}
|
||||
184
app/Http/Controllers/Bo/SiteController.php
Normal file
184
app/Http/Controllers/Bo/SiteController.php
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Sites\StoreSiteRequest;
|
||||
use App\Http\Requests\Bo\Sites\UpdateSiteRequest;
|
||||
use App\Models\Logo;
|
||||
use App\Models\Site;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
use ChangesModelOrder;
|
||||
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Site::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $siteModels */
|
||||
$siteModels = Site::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$siteModels,
|
||||
$search,
|
||||
null,
|
||||
'title',
|
||||
'introduction',
|
||||
'content',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(trans('validation.attributes.title')),
|
||||
trans('validation.custom.introduction'),
|
||||
trans('validation.attributes.content'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($siteModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$siteModels = $this->paginate($siteModels);
|
||||
|
||||
return view('bo.pages.sites.index', compact('siteModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\Site $site
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(Site $site): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$logoModels = Logo::all();
|
||||
|
||||
return view('bo.pages.sites.create', [
|
||||
'siteModel' => $site,
|
||||
'logoModels' => $logoModels
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Sites\StoreSiteRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreSiteRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$site = new Site();
|
||||
$site->fill($request->safe()->except(['logos']));
|
||||
|
||||
if ($site->saveOrFail()) {
|
||||
$site->logos()->attach(collect($request->validated('logos'))->pluck('id'));
|
||||
return redirect()->route('bo.sites.edit', $site)
|
||||
->with('success', trans('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.site'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.site'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Site $site
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Site $site): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$logoModels = Logo::all();
|
||||
|
||||
return view('bo.pages.sites.edit', [
|
||||
'siteModel' => $site,
|
||||
'logoModels' => $logoModels
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Sites\UpdateSiteRequest $request
|
||||
* @param \App\Models\Site $site
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateSiteRequest $request, Site $site): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $site) {
|
||||
$site->fill($request->safe()->except(['logos']));
|
||||
$site->logos()->sync(collect($request->validated('logos'))->pluck('id'));
|
||||
|
||||
if ($site->saveOrFail()) {
|
||||
return redirect()->route('bo.sites.edit', $site)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.site'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.sites.edit', $site)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.site'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Site $site
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Site $site): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($site) {
|
||||
$site->logos()->detach();
|
||||
|
||||
if ($site->deleteOrFail()) {
|
||||
return redirect()->route('bo.sites.index')
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.site'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.site'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\Site $site
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(Site $site): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($site->replicate());
|
||||
}
|
||||
}
|
||||
159
app/Http/Controllers/Bo/SlideController.php
Normal file
159
app/Http/Controllers/Bo/SlideController.php
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Slides\StoreSlideRequest;
|
||||
use App\Http\Requests\Bo\Slides\UpdateSlideRequest;
|
||||
use App\Models\Slide;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SlideController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Slide::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $slideModels */
|
||||
$slideModels = Slide::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$slideModels,
|
||||
$search,
|
||||
null,
|
||||
'slider',
|
||||
'title',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(trans('validation.custom.slider')),
|
||||
trans('validation.attributes.title'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($slideModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$slideModels = $this->paginate($slideModels);
|
||||
|
||||
return view('bo.pages.slides.index', compact('slideModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(Slide $slide): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.slides.create', ['slideModel' => $slide]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Slides\StoreSlideRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreSlideRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$slide = new Slide();
|
||||
|
||||
if ($slide->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.slides.edit', $slide)
|
||||
->with('success', trans('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.slide'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.slide'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Slide $slide): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.slides.edit', ['slideModel' => $slide]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Slides\UpdateSlideRequest $request
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateSlideRequest $request, Slide $slide): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $slide) {
|
||||
if ($slide->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.slides.edit', $slide)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.slide'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.slides.edit', $slide)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.slide'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Slide $slide): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($slide->deleteOrFail()) {
|
||||
return redirect()->route('bo.slides.index')
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.slide'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.slide'))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(Slide $slide): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($slide->replicate());
|
||||
}
|
||||
}
|
||||
91
app/Http/Controllers/Bo/StaticPageController.php
Normal file
91
app/Http/Controllers/Bo/StaticPageController.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\StaticPages\UpdateStaticPageRequest;
|
||||
use App\Models\StaticPage;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class StaticPageController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(StaticPage::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = StaticPage::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$query,
|
||||
$search,
|
||||
null,
|
||||
'title',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
trans('validation.attributes.title'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($query);
|
||||
|
||||
/** Custom pagination */
|
||||
$staticPageModelList = $this->paginate($query);
|
||||
|
||||
return view('bo.pages.static_pages.index', compact('staticPageModelList', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\StaticPage $static_page
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(StaticPage $static_page): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.static_pages.edit', ['staticPageModel' => $static_page]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\StaticPages\UpdateStaticPageRequest $request
|
||||
* @param \App\Models\StaticPage $static_page
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateStaticPageRequest $request, StaticPage $static_page): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $static_page) {
|
||||
$static_page->fill($request->validated());
|
||||
|
||||
if ($static_page->saveOrFail()) {
|
||||
return redirect()->route('bo.static_pages.edit', $static_page)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(\trans_choice('models.classes.static_page', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.static_pages.edit', $static_page)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(\trans_choice('models.classes.static_page', 1))
|
||||
]));
|
||||
});
|
||||
}
|
||||
}
|
||||
177
app/Http/Controllers/Bo/StripController.php
Normal file
177
app/Http/Controllers/Bo/StripController.php
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Strips\StoreStripRequest;
|
||||
use App\Http\Requests\Bo\Strips\UpdateStripRequest;
|
||||
use App\Models\News;
|
||||
use App\Models\Strip;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class StripController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Strip::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $stripModels */
|
||||
$stripModels = Strip::query()->with('news');
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$stripModels,
|
||||
$search,
|
||||
null,
|
||||
'text',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(trans('validation.attributes.content')),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($stripModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$stripModels = $this->paginate($stripModels);
|
||||
|
||||
return view('bo.pages.strips.index', compact('stripModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\Strip $strip
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(Strip $strip): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$newsModels = News::query()->where('published', true)->get();
|
||||
return view('bo.pages.strips.create', [
|
||||
'stripModel' => $strip,
|
||||
'newsModels' => $newsModels
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Strips\StoreStripRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreStripRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$strip = new Strip();
|
||||
$strip->fill($request->validated());
|
||||
if ($request->news_id === null) {
|
||||
$strip->news()->dissociate();
|
||||
}
|
||||
|
||||
if ($strip->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.strips.edit', $strip)
|
||||
->with('success', trans('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.strip', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.strip', 1))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Strip $strip
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Strip $strip): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$newsModels = News::query()->where('published', true)->get();
|
||||
return view('bo.pages.strips.edit', [
|
||||
'stripModel' => $strip,
|
||||
'newsModels' => $newsModels
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Strips\UpdateStripRequest $request
|
||||
* @param \App\Models\Strip $strip
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateStripRequest $request, Strip $strip): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $strip) {
|
||||
$strip->fill($request->validated());
|
||||
if ($request->news_id === null) {
|
||||
$strip->news()->dissociate();
|
||||
}
|
||||
if ($strip->saveOrFail()) {
|
||||
return redirect()->route('bo.strips.edit', $strip)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.strip', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.strips.edit', $strip)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.strip', 1))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Strip $strip
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Strip $strip): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($strip->deleteOrFail()) {
|
||||
return redirect()->route('bo.strips.index')
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.strip', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans_choice('models.classes.strip', 1))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\Strip $strip
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(Strip $strip): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($strip->replicate());
|
||||
}
|
||||
}
|
||||
165
app/Http/Controllers/Bo/TestimonialController.php
Normal file
165
app/Http/Controllers/Bo/TestimonialController.php
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Testimonials\StoreTestimonialRequest;
|
||||
use App\Http\Requests\Bo\Testimonials\UpdateTestimonialRequest;
|
||||
use App\Models\Testimonial;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class TestimonialController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Testimonial::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $testimonialModels */
|
||||
$testimonialModels = Testimonial::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$testimonialModels,
|
||||
$search,
|
||||
null,
|
||||
'name',
|
||||
'job',
|
||||
'content',
|
||||
'type',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(trans('validation.attributes.name')),
|
||||
trans('validation.custom.job'),
|
||||
trans('validation.attributes.content'),
|
||||
trans('validation.custom.type'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($testimonialModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$testimonialModels = $this->paginate($testimonialModels);
|
||||
|
||||
return view('bo.pages.testimonials.index', compact('testimonialModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\Testimonial $testimonial
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(Testimonial $testimonial): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.testimonials.create', ['testimonialModel' => $testimonial]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Testimonials\StoreTestimonialRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreTestimonialRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$testimonial = new Testimonial();
|
||||
|
||||
if ($testimonial->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.testimonials.edit', $testimonial)
|
||||
->with('success', trans('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.testimonial'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.testimonial'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Testimonial $testimonial
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Testimonial $testimonial): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.testimonials.edit', ['testimonialModel' => $testimonial]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Testimonials\UpdateTestimonialRequest $request
|
||||
* @param \App\Models\Testimonial $testimonial
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(
|
||||
UpdateTestimonialRequest $request,
|
||||
Testimonial $testimonial
|
||||
): \Illuminate\Http\RedirectResponse {
|
||||
return DB::transaction(function () use ($request, $testimonial) {
|
||||
if ($testimonial->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.testimonials.edit', $testimonial)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.testimonial'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.testimonials.edit', $testimonial)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.testimonial'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Testimonial $testimonial
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Testimonial $testimonial): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($testimonial->deleteOrFail()) {
|
||||
return redirect()->route('bo.testimonials.index')
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.testimonial'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.testimonial'))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\Testimonial $testimonial
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(Testimonial $testimonial): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($testimonial->replicate());
|
||||
}
|
||||
}
|
||||
30
app/Http/Controllers/Bo/UploadController.php
Normal file
30
app/Http/Controllers/Bo/UploadController.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\UploadFileRequest;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Models\Section;
|
||||
|
||||
class UploadController extends Controller
|
||||
{
|
||||
/**
|
||||
* Upload a file sent in a request.
|
||||
* Used for picture upload in CKEditor.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\UploadFileRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function uploadFile(UploadFileRequest $request)
|
||||
{
|
||||
/** @var \Illuminate\Http\UploadedFile $image */
|
||||
$image = $request->upload;
|
||||
|
||||
$path = FileStorageHelper::storeFile(new Section(), $image, true);
|
||||
|
||||
return response()->json([
|
||||
'url' => "/{$path}"
|
||||
]);
|
||||
}
|
||||
}
|
||||
171
app/Http/Controllers/Bo/UserController.php
Normal file
171
app/Http/Controllers/Bo/UserController.php
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Users\StoreUserRequest;
|
||||
use App\Http\Requests\Bo\Users\UpdateUserRequest;
|
||||
use App\Models\User;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $userModels */
|
||||
$userModels = User::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$userModels,
|
||||
$search,
|
||||
null,
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'role',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
trans('validation.attributes.first_name'),
|
||||
trans('validation.attributes.last_name'),
|
||||
trans('validation.attributes.email'),
|
||||
trans('validation.attributes.role'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($userModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$userModels = $this->paginate($userModels);
|
||||
|
||||
return view('bo.pages.users.index', compact('userModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(User $user): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.users.create', ['userModel' => $user]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Users\StoreUserRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreUserRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$user = new User();
|
||||
$user->fill($request->validated());
|
||||
|
||||
if ($user->saveOrFail()) {
|
||||
return redirect()->route('bo.users.edit', $user)
|
||||
->with('success', trans('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.user'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(trans('models.classes.user'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(User $user): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.users.edit', ['userModel' => $user]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Users\UpdateUserRequest $request
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateUserRequest $request, User $user): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $user) {
|
||||
$user->fill($request->validated());
|
||||
|
||||
if ($user->saveOrFail()) {
|
||||
return redirect()->route('bo.users.edit', $user)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.user'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.users.edit', $user)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.user'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(User $user): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
/** @var array<string,string> */
|
||||
$previousQueries = [];
|
||||
\parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries);
|
||||
if ($user->deleteOrFail()) {
|
||||
return redirect()->route('bo.users.index', $previousQueries)
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.user'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.user'))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(User $user): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($user->replicate());
|
||||
}
|
||||
}
|
||||
|
|
@ -2,12 +2,18 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\Pagination\ItemsPerPaginationEnum;
|
||||
use App\Enums\Theme\BootstrapThemeEnum;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
|
|
@ -31,7 +37,7 @@ class Controller extends BaseController
|
|||
string $search,
|
||||
callable $searchQuery = null,
|
||||
string ...$fields
|
||||
): Builder {
|
||||
): \Illuminate\Database\Eloquent\Builder {
|
||||
if (count($fields)) {
|
||||
// Search using words.
|
||||
$words = explode(' ', $search);
|
||||
|
|
@ -60,45 +66,97 @@ class Controller extends BaseController
|
|||
* @param array $fields
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
private function searchOnFields(Builder $query, string $search, array $fields): Builder
|
||||
{
|
||||
private function searchOnFields(
|
||||
Builder $query,
|
||||
string $search,
|
||||
array $fields
|
||||
): \Illuminate\Database\Eloquent\Builder {
|
||||
$table = $query->getModel()->getTable();
|
||||
foreach ($fields as $f) {
|
||||
$f = str_replace('?', '\?', $f);
|
||||
if (is_array($f)) {
|
||||
foreach ($fields as $field) {
|
||||
$field = str_replace('?', '\?', $field);
|
||||
if (is_array($field)) {
|
||||
$query->orWhereRaw(
|
||||
sprintf("UPPER(CONCAT(%s)) LIKE UPPER(?)", collect($f)->map(function ($q) use ($table) {
|
||||
sprintf("UPPER(CONCAT(%s)) LIKE UPPER(?)", collect($field)->map(function ($q) use ($table) {
|
||||
return "`$table`.`$q`";
|
||||
})->implode(', \' \', ')),
|
||||
['%' . filter_var($search, FILTER_SANITIZE_STRING) . '%']
|
||||
);
|
||||
} else {
|
||||
$query->orWhereRaw(
|
||||
"UPPER(`$table`.`$f`) LIKE UPPER(?)",
|
||||
['%' . filter_var($search, FILTER_SANITIZE_STRING) . '%']
|
||||
['%' . htmlspecialchars($search) . '%']
|
||||
);
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
// Get models woth enum's label.
|
||||
if (is_array($this->getSearchValue($query, $search, $field))) {
|
||||
foreach ($this->getSearchValue($query, $search, $field) as $array) {
|
||||
$query->orWhereRaw(
|
||||
"UPPER(`$table`.`$field`) LIKE UPPER(?)",
|
||||
['%' . htmlspecialchars($array->value) . '%']
|
||||
);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
// Get models with relation's name/label.
|
||||
if (Str::endsWith($field, '_id')) {
|
||||
$query->orWhereHas(Str::remove('_id', $field), function ($queryRelation) use ($field, $search) {
|
||||
if (Schema::hasColumn(Str::remove('_id', $field) . 's', 'name')) {
|
||||
$queryRelation->where('name', 'like', '%' . $search . '%');
|
||||
} elseif (Schema::hasColumn(Str::remove('_id', $field) . 's', 'label')) {
|
||||
$queryRelation->where('label', 'like', '%' . $search . '%');
|
||||
}
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
$query->orWhereRaw(
|
||||
"UPPER(`$table`.`$field`) LIKE UPPER(?)",
|
||||
['%' . htmlspecialchars($this->getSearchValue($query, $search, $field)) . '%']
|
||||
);
|
||||
} //end foreach
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort columns with a query
|
||||
* Get the search value (on string or Enum).
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $search
|
||||
* @param string $field
|
||||
* @return string|array
|
||||
*/
|
||||
protected function getSearchValue(Builder $query, string $search, string $field): string|array
|
||||
{
|
||||
$cast = $query->getModel()->getCasts()[$field] ?? null;
|
||||
if (
|
||||
count($query->getModel()->getCasts()) and // Check if the model has casts.
|
||||
$cast and // Check if there is cast about specific field.
|
||||
enum_exists($cast) // Check if the cast is an enum.
|
||||
) {
|
||||
/** @var \App\Traits\Enums $cast */
|
||||
// @phpstan-ignore-next-line
|
||||
$cases = collect($cast::toArray());
|
||||
$enum = $cases->filter(function ($item) use ($search) {
|
||||
return preg_match('/' . Str::lower($search) . '/', Str::lower($item->label));
|
||||
});
|
||||
return $enum->toArray();
|
||||
} else {
|
||||
return $search;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort columns with a query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $ignore
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function sortQuery(Builder $query, array $ignore = []): Builder
|
||||
protected function sortQuery(Builder $query, array $ignore = []): \Illuminate\Database\Eloquent\Builder
|
||||
{
|
||||
$rName = request()->route()->getName();
|
||||
$table = $query->getModel()->getTable();
|
||||
if (request()->sort_col) {
|
||||
Session::put("$rName.sort_col", request()->sort_col);
|
||||
if (request()->input('sort_col')) {
|
||||
Session::put("$rName.sort_col", request()->input('sort_col'));
|
||||
Session::put("$rName.sorted", true);
|
||||
}
|
||||
if (request()->sort_way) {
|
||||
Session::put("$rName.sort_way", request()->sort_way);
|
||||
if (request()->input('sort_way')) {
|
||||
Session::put("$rName.sort_way", request()->input('sort_way'));
|
||||
Session::put("$rName.sorted", true);
|
||||
}
|
||||
if (request()->rst) {
|
||||
|
|
@ -106,18 +164,75 @@ class Controller extends BaseController
|
|||
Session::remove("$rName.sort_col");
|
||||
Session::remove("$rName.sort_way");
|
||||
}
|
||||
if (request()->sort_col and request()->sort_way and Schema::hasColumn($table, request()->sort_col)) {
|
||||
if (
|
||||
!isset($ignore) or
|
||||
(isset($ignore) and !in_array(request()->sort_col, $ignore))
|
||||
) {
|
||||
$query = $query->orderBy(\sprintf("$table.%s", request()->sort_col), request()->sort_way);
|
||||
if (
|
||||
request()->input('sort_col') and
|
||||
request()->input('sort_way') and
|
||||
Schema::hasColumn($table, request()->input('sort_col'))
|
||||
) {
|
||||
if (!in_array(request()->input('sort_col'), $ignore)) {
|
||||
$query = $query->orderBy(
|
||||
\sprintf("$table.%s", request()->input('sort_col')),
|
||||
request()->input('sort_way')
|
||||
);
|
||||
}
|
||||
} elseif (Schema::hasColumn($table, 'order')) {
|
||||
$query = $query->orderBy('order', 'ASC');
|
||||
Session::put("$rName.sort_col", 'order');
|
||||
Session::put("$rName.sort_way", 'asc');
|
||||
} elseif (Schema::hasColumn($table, 'updated_at')) {
|
||||
$query = $query->orderBy('updated_at', 'DESC');
|
||||
Session::put("$rName.sort_col", 'updated_at');
|
||||
Session::put("$rName.sort_way", 'desc');
|
||||
} elseif (Schema::hasColumn($table, 'created_at')) {
|
||||
$query = $query->orderBy('created_at', 'DESC');
|
||||
Session::put("$rName.sort_col", 'created_at');
|
||||
Session::put("$rName.sort_way", 'desc');
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize pagination with cache or config (default).
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \App\Enums\Pagination\ItemsPerPaginationEnum|null $pagination
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
protected function paginate(
|
||||
Builder $query,
|
||||
ItemsPerPaginationEnum $pagination = null
|
||||
): \Illuminate\Contracts\Pagination\LengthAwarePaginator {
|
||||
$currentRoutePath = Str::slug(request()->route()->getName());
|
||||
$cacheKey = "pagination.{$currentRoutePath}";
|
||||
$pagination = $pagination ?? ItemsPerPaginationEnum::twelve;
|
||||
$pagination = ToolboxHelper::getValidatedEnum(
|
||||
Cache::get($cacheKey, $pagination->value()),
|
||||
'pagination',
|
||||
'\App\Enums\Pagination\ItemsPerPaginationEnum',
|
||||
);
|
||||
if (Cache::get($cacheKey) !== $pagination) {
|
||||
Cache::put($cacheKey, $pagination);
|
||||
}
|
||||
$query = $query->paginate($pagination);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bootstrap theme or light (default).
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
protected function setTheme(Request $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
$theme = ToolboxHelper::getValidatedEnum(
|
||||
$request->theme ?: Cache::get('theme', BootstrapThemeEnum::light->value()),
|
||||
'theme',
|
||||
'\App\Http\Controllers\BootstrapThemeEnum',
|
||||
);
|
||||
if (Cache::get("theme") !== $theme) {
|
||||
Cache::put("theme", $theme);
|
||||
}
|
||||
return redirect()->back()->with('success', __('crud.messages.theme_updated'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
return view('fo.pages.home');
|
||||
}
|
||||
}
|
||||
62
app/Http/Controllers/Fo/NewsController.php
Normal file
62
app/Http/Controllers/Fo/NewsController.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Enums\Sections\PageSectionEnum;
|
||||
use App\Enums\StaticPageType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\News;
|
||||
use App\Models\Section;
|
||||
use App\Models\StaticPage;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_move)->first();
|
||||
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
|
||||
$newsModels = News::query()->where('published', true)->orderBy('publish_at', 'DESC')->simplePaginate(4);
|
||||
$lifeSection = $sectionModels->where('section', PageSectionEnum::move_life)->first();
|
||||
$commitmentSection = $sectionModels->where('section', PageSectionEnum::move_commitments)->first();
|
||||
|
||||
return view('fo.pages.news.index', \compact(
|
||||
'staticPageModel',
|
||||
'sectionModels',
|
||||
'newsModels',
|
||||
'lifeSection',
|
||||
'commitmentSection'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a news articles
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show(News $news): \Illuminate\Contracts\View\View
|
||||
{
|
||||
// Get only id from published news.
|
||||
// @phpcs:disabled
|
||||
// @phpstan-ignore-next-line
|
||||
$publishedNews = News::query()->where('published', true)->orderBy('publish_at', 'DESC')->get()->pluck('id');
|
||||
// @phpcs:enable
|
||||
// Search the position of the current news id.
|
||||
$positionId = \array_search($news->id, $publishedNews->toArray());
|
||||
// Check if it's the last position.
|
||||
$nextPositionId = ($positionId === count($publishedNews) - 1) ? 0 : intval($positionId) + 1;
|
||||
// Find the next news from the id.
|
||||
$nextNews = News::query()->where('id', $publishedNews[$nextPositionId])->firstOrFail();
|
||||
// Check if it's the first position.
|
||||
$prevPositionId = ($positionId === 0) ? count($publishedNews) - 1 : intval($positionId) - 1;
|
||||
// Find the next news from the id.
|
||||
$prevNews = News::query()->where('id', $publishedNews[$prevPositionId])->firstOrFail();
|
||||
|
||||
return view('fo.pages.news.show', \compact('news', 'nextNews', 'prevNews'));
|
||||
}
|
||||
}
|
||||
299
app/Http/Controllers/Fo/StaticPageController.php
Normal file
299
app/Http/Controllers/Fo/StaticPageController.php
Normal file
|
|
@ -0,0 +1,299 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Enums\Listen\ObjectEnum;
|
||||
use App\Enums\Sections\PageSectionEnum;
|
||||
use App\Enums\Slides\SliderTypeEnum;
|
||||
use App\Enums\StaticPageType;
|
||||
use App\Enums\Testimonials\TypeEnum;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Fo\ListenFormRequest;
|
||||
use App\Mail\SendConfirmationMail;
|
||||
use App\Mail\SendContactMail;
|
||||
use App\Models\HistoricalMilestone;
|
||||
use App\Models\JobVideo;
|
||||
use App\Models\News;
|
||||
use App\Models\Section;
|
||||
use App\Models\Site;
|
||||
use App\Models\Slide;
|
||||
use App\Models\StaticPage;
|
||||
use App\Models\Strip;
|
||||
use App\Models\Testimonial;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class StaticPageController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::home)->first();
|
||||
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
|
||||
$stripModels = Strip::query()->where('published', true)
|
||||
->orderBy('publish_at', 'DESC')
|
||||
->limit(6)
|
||||
->with('news')
|
||||
->get();
|
||||
$newsModels = News::query()->where('published', true)
|
||||
->orderBy('publish_at', 'DESC')
|
||||
->limit(4)
|
||||
->get();
|
||||
$slideModels = Slide::query()->where('type', SliderTypeEnum::home)->get();
|
||||
$missionSection = $sectionModels->where('section', PageSectionEnum::home_missions)->first();
|
||||
$ambitionSection = $sectionModels->where('section', PageSectionEnum::home_ambition)->first();
|
||||
$teamSection = $sectionModels->where('section', PageSectionEnum::home_team)->first();
|
||||
$lifeSection = $sectionModels->where('section', PageSectionEnum::home_life)->first();
|
||||
|
||||
return view('fo.pages.home', compact(
|
||||
'staticPageModel',
|
||||
'sectionModels',
|
||||
'stripModels',
|
||||
'newsModels',
|
||||
'slideModels',
|
||||
'missionSection',
|
||||
'ambitionSection',
|
||||
'teamSection',
|
||||
'lifeSection',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the 'unveil' page.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function unveil(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::unveil)->first();
|
||||
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
|
||||
$historicalMilestoneModels = HistoricalMilestone::query()->orderBy('year', 'ASC')->get();
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Site> */
|
||||
$siteModelList = Site::query()->orderBy('order')->get();
|
||||
$keySection = $sectionModels->where('section', PageSectionEnum::unveil_pole)->first();
|
||||
$missionsSection = $sectionModels->where('section', PageSectionEnum::unveil_missions)->first();
|
||||
$localSection = $sectionModels->where('section', PageSectionEnum::unveil_local)->first();
|
||||
$siteSection = $sectionModels->where('section', PageSectionEnum::unveil_sites)->first();
|
||||
$historySection = $sectionModels->where('section', PageSectionEnum::unveil_history)->first();
|
||||
$commitmentSection = $sectionModels->where('section', PageSectionEnum::unveil_commitments)->first();
|
||||
|
||||
$viewBox = null;
|
||||
$initialZoom = null;
|
||||
// * Calcul Viewbox leaflet map ().
|
||||
// Carte page “on se dévoile” : Point central = Laval + rayon = 100 km
|
||||
/** @var \App\Models\Site|null $lavalSite */
|
||||
// @phpstan-ignore-next-line
|
||||
$lavalSite = $siteModelList->first(fn (Site $site) => Str::contains($site->name, 'Laval'));
|
||||
if ($lavalSite) {
|
||||
$viewBox = (object)[
|
||||
'lat' => $lavalSite->latitude,
|
||||
'lng' => $lavalSite->longitude
|
||||
];
|
||||
$initialZoom = 9;
|
||||
}
|
||||
|
||||
return view('fo.pages.unveil', compact(
|
||||
'viewBox',
|
||||
'initialZoom',
|
||||
'staticPageModel',
|
||||
'sectionModels',
|
||||
'historicalMilestoneModels',
|
||||
'siteModelList',
|
||||
'keySection',
|
||||
'missionsSection',
|
||||
'localSection',
|
||||
'siteSection',
|
||||
'historySection',
|
||||
'commitmentSection'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the 'commitments' page.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function commit(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_commit)->first();
|
||||
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
|
||||
$slideLifeModels = Slide::query()->where('type', SliderTypeEnum::better_life)->get();
|
||||
$slideEarthModels = Slide::query()->where('type', SliderTypeEnum::respect_earth)->get();
|
||||
$testimonialModels = Testimonial::query()
|
||||
->whereIn('type', [
|
||||
TypeEnum::breeding->value,
|
||||
TypeEnum::better_life->value,
|
||||
TypeEnum::respect_earth->value,
|
||||
TypeEnum::feed->value,
|
||||
TypeEnum::volena->value,
|
||||
])->get();
|
||||
$ambitionSection = $sectionModels->where('section', PageSectionEnum::commit_ambition)->first();
|
||||
$breedingSection = $sectionModels->where('section', PageSectionEnum::commit_breeding)->first();
|
||||
$lifeSection = $sectionModels->where('section', PageSectionEnum::commit_living)->first();
|
||||
$earthSection = $sectionModels->where('section', PageSectionEnum::commit_respect_earth)->first();
|
||||
$feedSection = $sectionModels->where('section', PageSectionEnum::commit_feed)->first();
|
||||
$testimonialsSection = $sectionModels->where('section', PageSectionEnum::commit_commitments)->first();
|
||||
|
||||
return view('fo.pages.commitments', compact(
|
||||
'staticPageModel',
|
||||
'sectionModels',
|
||||
'slideLifeModels',
|
||||
'slideEarthModels',
|
||||
'testimonialModels',
|
||||
'ambitionSection',
|
||||
'breedingSection',
|
||||
'lifeSection',
|
||||
'earthSection',
|
||||
'feedSection',
|
||||
'testimonialsSection',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the 'legals' page.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function legals(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::legals)->first();
|
||||
|
||||
return view('fo.pages.legals', compact(
|
||||
'staticPageModel',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the 'confidentiality' page.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function confidentiality(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::confidentiality)->first();
|
||||
|
||||
return view('fo.pages.legals', compact(
|
||||
'staticPageModel',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the 'we_produce' page.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function produce(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_produce)->first();
|
||||
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
|
||||
$localSection = $sectionModels->where('section', PageSectionEnum::produce_local)->first();
|
||||
$gmsSection = $sectionModels->where('section', PageSectionEnum::produce_gms)->first();
|
||||
$rhdSection = $sectionModels->where('section', PageSectionEnum::produce_rhd)->first();
|
||||
$exportSection = $sectionModels->where('section', PageSectionEnum::produce_export)->first();
|
||||
$qualitySection = $sectionModels->where('section', PageSectionEnum::produce_quality)->first();
|
||||
|
||||
return view('fo.pages.produce.show', compact(
|
||||
'staticPageModel',
|
||||
'localSection',
|
||||
'gmsSection',
|
||||
'rhdSection',
|
||||
'exportSection',
|
||||
'qualitySection'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the 'we_listen' page.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function listen(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_listen)->first();
|
||||
|
||||
return view('fo.pages.listen', compact(
|
||||
'staticPageModel',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send listen form data.
|
||||
*
|
||||
* @param \App\Http\Requests\Fo\ListenFormRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function listenForm(ListenFormRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
Mail::to(config('mail.contact.' . ObjectEnum::make(intval($request->validated()['object']))->name()))
|
||||
->send(new SendContactMail((object)$request->validated()));
|
||||
Mail::to($request->validated()['email'])->send(new SendConfirmationMail((object)$request->validated()));
|
||||
|
||||
return redirect()->route('fo.listen.show')
|
||||
->with('success', trans(
|
||||
'Bonjour, votre message a bien été transmis, nous vous en remercions. Cordialement, l’équipe :appName.',
|
||||
['appName' => config('app.name')]
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function hire(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_hire)->first();
|
||||
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
|
||||
$videoModels = JobVideo::query()->inRandomOrder()->simplePaginate(4);
|
||||
$testimonialModels = Testimonial::query()->where('type', TypeEnum::hire)->get();
|
||||
$compagnyLifeSection = $sectionModels->where('section', PageSectionEnum::hire_life)->first();
|
||||
$formationSection = $sectionModels->where('section', PageSectionEnum::hire_formation)->first();
|
||||
$testimonialSection = $sectionModels->where('section', PageSectionEnum::hire_grow)->first();
|
||||
$paritySection = $sectionModels->where('section', PageSectionEnum::hire_parity)->first();
|
||||
$findSection = $sectionModels->where('section', PageSectionEnum::hire_find)->first();
|
||||
|
||||
return view('fo.pages.hire', \compact(
|
||||
'staticPageModel',
|
||||
'sectionModels',
|
||||
'videoModels',
|
||||
'testimonialModels',
|
||||
'compagnyLifeSection',
|
||||
'formationSection',
|
||||
'testimonialSection',
|
||||
'paritySection',
|
||||
'findSection'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \App\Models\Site $site
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function site(Site $site): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Site> */
|
||||
$siteModelList = Site::query()->orderBy('order')->get();
|
||||
$siteModelList = $siteModelList->keyBy('order');
|
||||
$nextSiteModel = $siteModelList->get($site->order + 1);
|
||||
|
||||
$viewBox = (object)[
|
||||
'lat' => $site->latitude,
|
||||
'lng' => $site->longitude
|
||||
];
|
||||
$initialZoom = 10;
|
||||
|
||||
return view('fo.pages.site', [
|
||||
'siteModelList' => $siteModelList,
|
||||
'siteModel' => $site,
|
||||
'nextSiteModel' => $nextSiteModel,
|
||||
'viewBox' => $viewBox,
|
||||
'initialZoom' => $initialZoom,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -54,16 +54,16 @@ class Kernel extends HttpKernel
|
|||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $middlewareAliases = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'htmlsanitize' => \App\Http\Middleware\HtmlSanitizer::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'htmlsanitize' => \App\Http\Middleware\HtmlSanitizer::class,
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ class Authenticate extends Middleware
|
|||
}
|
||||
return route('login');
|
||||
}
|
||||
abort(401);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ namespace App\Http\Middleware;
|
|||
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class HtmlSanitizer
|
||||
{
|
||||
|
|
@ -16,8 +15,11 @@ class HtmlSanitizer
|
|||
* @param string|array ...$params
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function handle(Request $request, \Closure $next, string|array ...$params): Response
|
||||
{
|
||||
public function handle(
|
||||
Request $request,
|
||||
\Closure $next,
|
||||
string|array ...$params
|
||||
): \Symfony\Component\HttpFoundation\Response {
|
||||
$inputs = $request->all();
|
||||
/** @var callable|null */
|
||||
$cleanInput = null;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
|
|
@ -18,16 +16,16 @@ class RedirectIfAuthenticated
|
|||
* @throws \RuntimeException If guard is unhandled.
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.IncorrectTypeHint
|
||||
*/
|
||||
public function handle(Request $request, \Closure $next, ...$guards): Response
|
||||
public function handle(Request $request, \Closure $next, ...$guards): \Symfony\Component\HttpFoundation\Response
|
||||
{
|
||||
// phpcs:enable phpcs:disable
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
if (auth($guard)->check()) {
|
||||
switch ($guard) {
|
||||
case 'frontend':
|
||||
return \redirect()->route('home');
|
||||
return \redirect()->route('fo.home.show');
|
||||
case 'backend':
|
||||
if (!$request->routeIs('bo.*')) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use Illuminate\Http\Request;
|
|||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SecureHeaders
|
||||
{
|
||||
|
|
@ -31,15 +30,17 @@ class SecureHeaders
|
|||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.IncorrectTypeHint
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
public function handle(Request $request, Closure $next): \Symfony\Component\HttpFoundation\Response
|
||||
{
|
||||
// phpcs:enable
|
||||
// * For Vite DEV
|
||||
$host = \parse_url(\config('app.url'), \PHP_URL_HOST);
|
||||
View::share('nonce', $nonce = Vite::useCspNonce());
|
||||
// * For VueJS dev tool to execute
|
||||
$jsDev = config('app.debug') ? "'unsafe-eval' 'unsafe-inline'" : "'nonce-{$nonce}' 'strict-dynamic'";
|
||||
$scheme = config('app.env') === 'local' ? 'http' : 'https';
|
||||
$reportUri = Route::has('cspReportUri') ?
|
||||
\sprintf(' report-uri %s ;', \parse_url(route('cspReportUri'), \PHP_URL_PATH)) : '';
|
||||
\sprintf(' report-uri %s ;', \parse_url(route('cspReportUri'), \PHP_URL_PATH)) : '';
|
||||
$this->removeUnwantedHeaders($this->unwantedHeaderList);
|
||||
$response = $next($request);
|
||||
$response->headers->set('Referrer-Policy', 'no-referrer-when-downgrade');
|
||||
|
|
@ -51,20 +52,29 @@ class SecureHeaders
|
|||
"default-src 'none';",
|
||||
"manifest-src 'self';",
|
||||
// * CKEDITOR Specific https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/csp.html
|
||||
'connect-src ' . implode(" ", [
|
||||
'\'self\'',
|
||||
'https://yl.s-web.fr',
|
||||
'blob:'
|
||||
"connect-src 'self' blob: " . implode(' ', [
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "wss://{$host}:4443" : '',
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
'https://yl.s-web.fr'
|
||||
]) . ';',
|
||||
"img-src * data: blob:;",
|
||||
'frame-src ' . implode(' ', [
|
||||
"img-src 'self' data: blob: " . implode(' ', [
|
||||
// * Leaftlet With OpenStreetmaps
|
||||
'https://tile.openstreetmap.org',
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
]) . ';',
|
||||
"object-src 'self' " . implode(' ', []) . ';',
|
||||
"frame-src 'self' " . implode(' ', [
|
||||
'https://www.google.com/recaptcha/',
|
||||
'https://recaptcha.google.com/recaptcha/',
|
||||
'https://www.google.com/maps/',
|
||||
'https://www.youtube-nocookie.com/',
|
||||
'https://www.youtube.com/embed/'
|
||||
'https://www.youtube.com',
|
||||
]) . ';',
|
||||
"font-src 'self' data: " . \implode(' ', [
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
'https://fonts.gstatic.com;'
|
||||
]) . ';',
|
||||
"font-src 'self' data: https://fonts.gstatic.com;",
|
||||
// ! Using CKEditor will must have unsafe-inline style
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
"style-src 'self' 'unsafe-inline' " . \implode(' ', [
|
||||
|
|
@ -73,7 +83,9 @@ class SecureHeaders
|
|||
'https://fonts.googleapis.com',
|
||||
'https://cdn.jsdelivr.net',
|
||||
'https://use.fontawesome.com',
|
||||
'https://fonts.googleapis.com'
|
||||
'https://fonts.googleapis.com',
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
]) . ';',
|
||||
// ! If you dont use ckeditor use this
|
||||
// "style-src 'self' 'nonce-$nonce';",
|
||||
|
|
@ -83,6 +95,8 @@ class SecureHeaders
|
|||
'https://www.googletagmanager.com',
|
||||
'https://cdnjs.cloudflare.com',
|
||||
"$scheme://www.google-analytics.com",
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
]) . ';'
|
||||
];
|
||||
|
||||
|
|
@ -100,7 +114,7 @@ class SecureHeaders
|
|||
* @param array $headerList
|
||||
* @return void
|
||||
*/
|
||||
private function removeUnwantedHeaders(array $headerList)
|
||||
private function removeUnwantedHeaders(array $headerList): void
|
||||
{
|
||||
foreach ($headerList as $header) {
|
||||
header_remove($header);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class TrustHosts extends Middleware
|
|||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts()
|
||||
public function hosts(): array
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ class TrustProxies extends Middleware
|
|||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* ! Added * as tmp Fix for #13
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
protected $proxies = '*';
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
|
|
@ -20,7 +22,7 @@ class TrustProxies extends Middleware
|
|||
* @var integer
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\HistoricalMilestones;
|
||||
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreHistoricalMilestoneRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'button_status' => $this->boolean('button_status'),
|
||||
'button_new_tab' => $this->boolean('button_new_tab')
|
||||
]);
|
||||
$this->mergePicture('picture');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'year' => 'required|integer|min:1900|max:2100',
|
||||
'title' => 'required|string|between:3,255',
|
||||
'text' => 'required|string|between:3,255',
|
||||
'picture_alt' => 'required|string|between:3,255',
|
||||
'picture_title' => 'required|string|between:3,255',
|
||||
'button_label' => 'required_if:button_status,true|nullable|string|between:3,35',
|
||||
'button_url' => 'required_if:button_status,true|nullable|string|between:3,255',
|
||||
'button_status' => 'required|boolean',
|
||||
'button_new_tab' => 'required|boolean',
|
||||
];
|
||||
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 606, 800, 606, 800, false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'year' => trans('validation.attributes.year'),
|
||||
'title' => trans('validation.attributes.title'),
|
||||
'text' => trans('validation.custom.text'),
|
||||
'picture_alt' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.alt_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture'),
|
||||
]),
|
||||
'picture_title' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.title_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture'),
|
||||
]),
|
||||
'button_label' => trans('validation.custom.button_label'),
|
||||
'button_url' => trans('validation.custom.button_url'),
|
||||
'button_status' => trans('validation.custom.button_status'),
|
||||
'button_new_tab' => trans('validation.custom.button_new_tab'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\HistoricalMilestones;
|
||||
|
||||
class UpdateHistoricalMilestoneRequest extends StoreHistoricalMilestoneRequest
|
||||
{
|
||||
}
|
||||
49
app/Http/Requests/Bo/JobVideos/StoreJobVideoRequest.php
Normal file
49
app/Http/Requests/Bo/JobVideos/StoreJobVideoRequest.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\JobVideos;
|
||||
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreJobVideoRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|between:3,255',
|
||||
'place' => 'required|string|between:3,255',
|
||||
'video_id' => 'required|string|regex:%([^"&?\/\s]{11})%i',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'title' => trans('validation.attributes.title'),
|
||||
'place' => trans('validation.custom.place'),
|
||||
'video_id' => trans('validation.custom.video_id'),
|
||||
];
|
||||
}
|
||||
}
|
||||
7
app/Http/Requests/Bo/JobVideos/UpdateJobVideoRequest.php
Normal file
7
app/Http/Requests/Bo/JobVideos/UpdateJobVideoRequest.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\JobVideos;
|
||||
|
||||
class UpdateJobVideoRequest extends StoreJobVideoRequest
|
||||
{
|
||||
}
|
||||
71
app/Http/Requests/Bo/Logos/StoreLogoRequest.php
Normal file
71
app/Http/Requests/Bo/Logos/StoreLogoRequest.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Logos;
|
||||
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreLogoRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->mergePicture('picture');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'label' => 'required|string|between:3,255',
|
||||
'picture_alt' => 'required|string|between:3,255',
|
||||
'picture_title' => 'required|string|between:3,255',
|
||||
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 450, 450, 450, 450, false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'picture_alt' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.alt_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture'),
|
||||
]),
|
||||
'picture_title' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.title_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture'),
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
7
app/Http/Requests/Bo/Logos/UpdateLogoRequest.php
Normal file
7
app/Http/Requests/Bo/Logos/UpdateLogoRequest.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Logos;
|
||||
|
||||
class UpdateLogoRequest extends StoreLogoRequest
|
||||
{
|
||||
}
|
||||
89
app/Http/Requests/Bo/News/StoreNewsRequest.php
Normal file
89
app/Http/Requests/Bo/News/StoreNewsRequest.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\News;
|
||||
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreNewsRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'published' => $this->boolean('published')
|
||||
]);
|
||||
$this->mergePicture('picture');
|
||||
$this->mergePicture('thumbnail');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'seo_title' => 'required|between:45,70',
|
||||
'seo_description' => 'required|between:50,160',
|
||||
'title' => 'required|string|between:3,100',
|
||||
'picture_alt' => 'required|string|between:3,255',
|
||||
'picture_title' => 'required|string|between:3,255',
|
||||
'thumbnail_alt' => 'required|string|between:3,255',
|
||||
'thumbnail_title' => 'required|string|between:3,255',
|
||||
'introduction' => 'required|string|min:15',
|
||||
'content' => 'nullable|string|min:15',
|
||||
'linkedin_url' => 'nullable|url',
|
||||
'published' => 'required|boolean',
|
||||
'publish_at' => 'nullable|date',
|
||||
'unpublish_at' => 'nullable|date|after:publish_at',
|
||||
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 500, 450, 500, 450, true),
|
||||
$this->pictureRules('thumbnail', 300, 200, 300, 200, true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'seo_title' => trans('validation.custom.seo_title'),
|
||||
'seo_description' => trans('validation.custom.seo_description'),
|
||||
'title' => trans('validation.attributes.title'),
|
||||
'introduction' => trans('validation.attributes.content'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
'linkedin_url' => trans('validation.attributes.content'),
|
||||
'picture_alt' => trans('validation.custom.picture_alt'),
|
||||
'picture_title' => trans('validation.custom.picture_title'),
|
||||
'thumbnail_alt' => trans('validation.custom.thumbnail_alt'),
|
||||
'thumbnail_title' => trans('validation.custom.thumbnail_title'),
|
||||
'published' => trans('validation.custom.activated'),
|
||||
'publish_at' => trans('validation.custom.publish_at'),
|
||||
'unpublish_at' => trans('validation.custom.unpublish_at'),
|
||||
];
|
||||
}
|
||||
}
|
||||
7
app/Http/Requests/Bo/News/UpdateNewsRequest.php
Normal file
7
app/Http/Requests/Bo/News/UpdateNewsRequest.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\News;
|
||||
|
||||
class UpdateNewsRequest extends StoreNewsRequest
|
||||
{
|
||||
}
|
||||
68
app/Http/Requests/Bo/Sections/UpdateSectionRequest.php
Normal file
68
app/Http/Requests/Bo/Sections/UpdateSectionRequest.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Sections;
|
||||
|
||||
use App\Http\Requests\Bo\UpdateMiniCrudRequest;
|
||||
|
||||
class UpdateSectionRequest extends UpdateMiniCrudRequest
|
||||
{
|
||||
/**
|
||||
* The model parameter name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $modelName = 'section';
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'h2_title' => 'required|between:3,255',
|
||||
];
|
||||
/** @var \App\Models\Section|null $section */
|
||||
$section = $this->route('section');
|
||||
if ($section) {
|
||||
if ($section->section !== \App\Enums\Sections\PageSectionEnum::hire_grow) {
|
||||
$rules = \array_merge($rules, [
|
||||
'text' => 'present',
|
||||
]);
|
||||
}
|
||||
if ($section->section->containsData()) {
|
||||
$rules = \array_merge($rules, [
|
||||
'data' => 'present|array',
|
||||
'data.*' => 'required|array',
|
||||
]);
|
||||
}
|
||||
}
|
||||
return \array_merge(parent::rules(), $rules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'h2_title' => trans('validation.custom.h2_title'),
|
||||
'text' => trans('validation.attributes.content'),
|
||||
'data' => trans('Valeurs du contenu spécifique'),
|
||||
'data.*.value' => trans('Valeur du contenu spécifique'),
|
||||
];
|
||||
}
|
||||
}
|
||||
162
app/Http/Requests/Bo/Sites/StoreSiteRequest.php
Normal file
162
app/Http/Requests/Bo/Sites/StoreSiteRequest.php
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Sites;
|
||||
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class StoreSiteRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'published' => $this->boolean('published'),
|
||||
'pictos' => \collect($this->input('pictos'))->all(),
|
||||
]);
|
||||
$this->mergePicture('logo');
|
||||
$this->mergePicture('picture_1');
|
||||
$this->mergePicture('picture_2');
|
||||
$this->mergePicture('picture_3');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'seo_title' => 'required|between:45,70',
|
||||
'seo_description' => 'required|between:50,160',
|
||||
'name' => 'required|string|between:3,100',
|
||||
'description' => 'required|string|between:3,255',
|
||||
'description_2' => 'nullable|string|between:3,255',
|
||||
'employees' => 'required|numeric|min:0',
|
||||
'pictos' => 'present|array',
|
||||
'pictos.*' => 'required|integer',
|
||||
'address' => 'required|string|between:3,255',
|
||||
'phone_number' => 'required|string|between:10,20',
|
||||
'access_line' => 'present|array',
|
||||
'access_line.*' => 'nullable|string|between:3,255',
|
||||
'director_name' => 'nullable|string|between:3,255',
|
||||
'director_speach' => 'required|string|min:15',
|
||||
'employee_name' => 'nullable|string|between:3,255',
|
||||
'employee_function' => 'nullable|string|between:3,255',
|
||||
'employee_speach' => 'nullable|string|min:15',
|
||||
'highlights' => 'nullable|string|min:15',
|
||||
'latitude' => 'required|numeric|between:-90,90',
|
||||
'longitude' => 'required|numeric|between:-180,180',
|
||||
'logo_alt' => 'required|string|between:3,255',
|
||||
'logo_title' => 'required|string|between:3,255',
|
||||
'picture_1_alt' => 'required|string|between:3,255',
|
||||
'picture_1_title' => 'required|string|between:3,255',
|
||||
'picture_2_alt' => 'required_with:picture_2|nullable|string|between:3,255',
|
||||
'picture_2_title' => 'required_with:picture_2|nullable|string|between:3,255',
|
||||
'picture_3_alt' => 'required_with:picture_3|nullable|string|between:3,255',
|
||||
'picture_3_title' => 'required_with:picture_3|nullable|string|between:3,255',
|
||||
'logos' => 'nullable|array',
|
||||
'logos.*.id' => 'required|exists:logos,id',
|
||||
|
||||
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('logo', 1000, 727, 1000, 727, false),
|
||||
$this->pictureRules('picture_1', 1000, 562, 1000, 562, false),
|
||||
$this->pictureRules('picture_2', 1000, 562, 1000, 562, true),
|
||||
$this->pictureRules('picture_3', 1000, 562, 1000, 562, true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'seo_title' => trans('validation.custom.seo_title'),
|
||||
'seo_description' => trans('validation.custom.seo_description'),
|
||||
'name' => trans('validation.attributes.name'),
|
||||
'description' => trans('validation.custom.description'),
|
||||
'description_2' => trans('validation.custom.description_2'),
|
||||
'employees' => trans('validation.custom.employees_count'),
|
||||
'pictos' => Str::plural(trans('validation.custom.picto')),
|
||||
'pictos.*' => trans('validation.custom.picto'),
|
||||
'address' => trans('validation.attributes.address'),
|
||||
'phone_number' => trans('validation.attributes.phone'),
|
||||
'access_line' => trans('validation.custom.access_line'),
|
||||
'access_line.*' => trans('ligne d\'accès au site'),
|
||||
'director_name' => trans('validation.custom.director_name'),
|
||||
'director_speach' => trans('validation.custom.director_speach'),
|
||||
'employee_name' => trans('validation.custom.employee_name'),
|
||||
'employee_function' => trans('validation.custom.employee_function'),
|
||||
'employee_speach' => trans('validation.custom.employee_speach'),
|
||||
'highlights' => Str::plural(trans('validation.custom.highlight')),
|
||||
'latitude' => trans('validation.custom.latitude'),
|
||||
'longitude' => trans('validation.custom.longitude'),
|
||||
'logos' => Str::plural(trans('models.classes.logo')),
|
||||
'logos.*' => trans('models.classes.logo'),
|
||||
'logo_alt' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.alt_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.male'),
|
||||
'model' => trans('validation.custom.logo'),
|
||||
]),
|
||||
'logo_title' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.title_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.male'),
|
||||
'model' => trans('validation.custom.logo'),
|
||||
]),
|
||||
'picture_1_alt' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.alt_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture_1'),
|
||||
]),
|
||||
'picture_1_title' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.title_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture_1'),
|
||||
]),
|
||||
'picture_2_alt' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.alt_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture_2'),
|
||||
]),
|
||||
'picture_2_title' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.title_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture_2'),
|
||||
]),
|
||||
'picture_3_alt' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.alt_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture_3'),
|
||||
]),
|
||||
'picture_3_title' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.title_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture_3'),
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
7
app/Http/Requests/Bo/Sites/UpdateSiteRequest.php
Normal file
7
app/Http/Requests/Bo/Sites/UpdateSiteRequest.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Sites;
|
||||
|
||||
class UpdateSiteRequest extends StoreSiteRequest
|
||||
{
|
||||
}
|
||||
123
app/Http/Requests/Bo/Slides/StoreSlideRequest.php
Normal file
123
app/Http/Requests/Bo/Slides/StoreSlideRequest.php
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Slides;
|
||||
|
||||
use App\Enums\Slides\SliderTypeEnum;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class StoreSlideRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'button_status' => $this->boolean('button_status'),
|
||||
'button_new_tab' => $this->boolean('button_new_tab')
|
||||
]);
|
||||
$this->mergePicture('picture');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'type' => [
|
||||
'required',
|
||||
new Enum(SliderTypeEnum::class)
|
||||
],
|
||||
'title' => [
|
||||
'required_unless:type,' . SliderTypeEnum::home->value(),
|
||||
'nullable',
|
||||
'string',
|
||||
'between:3,255'
|
||||
],
|
||||
'content' => [
|
||||
'required_if:type,' . SliderTypeEnum::home->value(),
|
||||
'nullable',
|
||||
'string',
|
||||
'between:3,255'
|
||||
],
|
||||
'video_id' => 'nullable|string|regex:%([^"&?\/\s]{11})%i',
|
||||
'picture_alt' => 'required|string|between:3,255',
|
||||
'picture_title' => 'required|string|between:3,255',
|
||||
'button_label' => 'required_if:button_status,true|nullable|string|between:3,35',
|
||||
'button_url' => 'required_if:button_status,true|nullable|string|between:3,255',
|
||||
'button_status' => [
|
||||
'required_unless:type,' . SliderTypeEnum::home->value(),
|
||||
'nullable', 'boolean'
|
||||
],
|
||||
'button_new_tab' => 'required|boolean',
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 1920, 1080, 1920, 1080, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'type' => trans('validation.custom.type'),
|
||||
'title' => trans('validation.attributes.title'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
'video_id' => trans('validation.custom.video_id'),
|
||||
'picture' => trans('validation.custom.picture'),
|
||||
'picture_alt' => trans('validation.custom.picture_alt'),
|
||||
'picture_title' => trans('validation.custom.picture_title'),
|
||||
'button_label' => trans('validation.custom.button_label'),
|
||||
'button_url' => trans('validation.custom.button_url'),
|
||||
'button_status' => trans('validation.custom.button_status'),
|
||||
'button_new_tab' => trans('validation.custom.button_new_tab'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validaton messages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'title' => [
|
||||
'required_unless' => __('Le champ :attribute est obligatoire si le slider n\'est pas :name.', [
|
||||
'attribute' => trans('validation.attributes.title'),
|
||||
'name' => SliderTypeEnum::home->label()
|
||||
]),
|
||||
],
|
||||
'content' => [
|
||||
'required_unless' => __('Le champ :attribute est obligatoire si le slider n\'est pas :name.', [
|
||||
'attribute' => trans('validation.attributes.content'),
|
||||
'name' => SliderTypeEnum::home->label()
|
||||
]),
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
7
app/Http/Requests/Bo/Slides/UpdateSlideRequest.php
Normal file
7
app/Http/Requests/Bo/Slides/UpdateSlideRequest.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Slides;
|
||||
|
||||
class UpdateSlideRequest extends StoreSlideRequest
|
||||
{
|
||||
}
|
||||
68
app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php
Normal file
68
app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\StaticPages;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UpdateStaticPageRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Gate::check('update', $this->route('static_page'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'content' => (empty(Str::of($this->input('content'))->value())) ?
|
||||
null :
|
||||
Str::of($this->input('content'))->value()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'seo_title' => 'required|min:45|max:70',
|
||||
'seo_description' => 'required|min:50|max:160',
|
||||
'title' => 'required|min:3|max:255',
|
||||
'content' => 'sometimes|nullable',
|
||||
];
|
||||
if (request()->route()->parameters()['static_page']->type->containsContent()) {
|
||||
$rules = array_merge($rules, ['content' => 'required|string|min:15']);
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'seo_title' => trans('validation.custom.seo_title'),
|
||||
'seo_description' => trans('validation.custom.seo_description'),
|
||||
'title' => trans('validation.attributes.title'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
];
|
||||
}
|
||||
}
|
||||
85
app/Http/Requests/Bo/Strips/StoreStripRequest.php
Normal file
85
app/Http/Requests/Bo/Strips/StoreStripRequest.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Strips;
|
||||
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class StoreStripRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'published' => $this->boolean('published'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'picto' => [
|
||||
'required',
|
||||
new Enum(\App\Enums\Strips\PictoEnum::class)
|
||||
],
|
||||
'text' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:3',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function (string $attribute, mixed $value, \Closure $fail) {
|
||||
if (Str::wordCount(\strip_tags($value)) > 255) {
|
||||
$fail(trans('validation.max_words', [
|
||||
'attribute' => trans('validation.attributes.text'),
|
||||
'count' => '255'
|
||||
]));
|
||||
}
|
||||
}
|
||||
],
|
||||
'news_id' => 'nullable|exists:news,id',
|
||||
'published' => 'required|boolean',
|
||||
'publish_at' => 'nullable|date',
|
||||
'unpublish_at' => 'nullable|date|after:publish_at',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'picto' => trans('validation.custom.picto'),
|
||||
'text' => trans('validation.attributes.content'),
|
||||
'news_id' => trans('models.classes.news'),
|
||||
'published' => trans('validation.custom.activated'),
|
||||
'publish_at' => trans('validation.custom.publish_at'),
|
||||
'unpublish_at' => trans('validation.custom.unpublish_at'),
|
||||
];
|
||||
}
|
||||
}
|
||||
7
app/Http/Requests/Bo/Strips/UpdateStripRequest.php
Normal file
7
app/Http/Requests/Bo/Strips/UpdateStripRequest.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Strips;
|
||||
|
||||
class UpdateStripRequest extends StoreStripRequest
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Testimonials;
|
||||
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class StoreTestimonialRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->mergePicture('picture');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'type' => [
|
||||
'required',
|
||||
new Enum(\App\Enums\Testimonials\TypeEnum::class)
|
||||
],
|
||||
'name' => 'required|string|between:3,255',
|
||||
'job' => 'required|string|between:3,255',
|
||||
'content' => 'required|string|min:3',
|
||||
'picture_alt' => 'required|string|between:3,255',
|
||||
'picture_title' => 'required|string|between:3,255',
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 100, 100, 100, 100, false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'type' => trans('validation.custom.type'),
|
||||
'name' => trans('validation.attributes.name'),
|
||||
'job' => trans('validation.custom.job'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
'picture_alt' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.alt_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture'),
|
||||
]),
|
||||
'picture_title' => trans(':field :inter:model', [
|
||||
'field' => trans('validation.custom.title_attribute'),
|
||||
'inter' => trans('validation.custom.of_the.vowel'),
|
||||
'model' => trans('validation.custom.picture'),
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Testimonials;
|
||||
|
||||
class UpdateTestimonialRequest extends StoreTestimonialRequest
|
||||
{
|
||||
}
|
||||
42
app/Http/Requests/Bo/UpdateChangeOrderRequest.php
Normal file
42
app/Http/Requests/Bo/UpdateChangeOrderRequest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateChangeOrderRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'direction' => $this->route('direction') === 'up' ? true : false
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'direction' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ use Illuminate\Validation\ValidationException;
|
|||
abstract class UpdateMiniCrudRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* The model parameter name
|
||||
* The model parameter name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -21,7 +21,7 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
* @phpcs:disable Generic.Metrics.NestingLevel.TooHigh
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
// phpcs:enable
|
||||
$rules = [];
|
||||
|
|
@ -45,6 +45,23 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
"data.$iptName.value" => $this->compileValidate('required|numeric', $input)
|
||||
]);
|
||||
break;
|
||||
case InputType::videoYoutube->value:
|
||||
$rules = array_merge($rules, [
|
||||
"data.$iptName.value" => $this->compileValidate('regex:%([^"&?\/\s]{11})%i', $input)
|
||||
]);
|
||||
break;
|
||||
case InputType::videoVimeo->value:
|
||||
$rules = array_merge($rules, [
|
||||
"data.$iptName.value" => $this->compileValidate('regex:%([0-9]{8,10})%i', $input)
|
||||
]);
|
||||
break;
|
||||
case InputType::video->value:
|
||||
$rules = array_merge($rules, [
|
||||
"data.$iptName.value" => $this->compileValidate([
|
||||
'regex:%([0-9]{8,10}|[^"&?\/\s]{11})%i'
|
||||
], $input)
|
||||
]);
|
||||
break;
|
||||
case InputType::string->value:
|
||||
$rules = array_merge($rules, [
|
||||
"data.$iptName.value" => $this->compileValidate('required|string|min:3', $input)
|
||||
|
|
@ -52,7 +69,7 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
break;
|
||||
case InputType::text->value:
|
||||
$mergeRules = $this->compileValidate('required|string|min:15', $input);
|
||||
$mergeRules = collect(\explode('|', $mergeRules))
|
||||
$mergeRules = collect($mergeRules)
|
||||
->map(function ($rule) {
|
||||
if (\strpos($rule, 'max:') !== false) {
|
||||
$max = \intval(str_replace('max:', '', $rule));
|
||||
|
|
@ -65,13 +82,14 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
return $rule;
|
||||
});
|
||||
$rules = array_merge($rules, [
|
||||
"data.$iptName.text" => $mergeRules
|
||||
"data.$iptName.value" => $mergeRules
|
||||
]);
|
||||
break;
|
||||
case InputType::image->value:
|
||||
$ipt = $this->data[$iptName];
|
||||
$max = isset($ipt['dimensionsMax']);
|
||||
$dim = \is_string($input['dimensions']) ? collect(explode(
|
||||
$required = $this->isUpdate() ? 'sometimes' : 'required';
|
||||
$ipt = $this->data[$iptName];
|
||||
$max = isset($ipt['dimensionsMax']);
|
||||
$dim = \is_string($input['dimensions']) ? collect(explode(
|
||||
',',
|
||||
(isset($ipt['dimensionsMax']) and is_string($ipt['dimensionsMax'])) ?
|
||||
$ipt['dimensionsMax'] : $input['dimensions']
|
||||
|
|
@ -79,10 +97,23 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
$v = explode(' ', $v);
|
||||
return [$v[0] => $v[1]];
|
||||
}) : $input['dimensions'];
|
||||
|
||||
// * Adapt dimensions
|
||||
$sizes = (object)[
|
||||
'minHeight' => $dim['height'],
|
||||
'maxHeight' => $dim['height'],
|
||||
'minWidth' => $dim['width'],
|
||||
'maxWidth' => $dim['width'],
|
||||
];
|
||||
$rules = array_merge($rules, [
|
||||
"data.$iptName.value" => $this->compileValidate(
|
||||
"data.$iptName.value" => [
|
||||
function (string $attribute, $value, callable $fail) use ($sizes) {
|
||||
ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||
}
|
||||
],
|
||||
$this->compileValidate(
|
||||
implode('|', [
|
||||
'required',
|
||||
$required,
|
||||
'image',
|
||||
'mimes:png,jpg,jpeg',
|
||||
sprintf(
|
||||
|
|
@ -95,8 +126,8 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
]),
|
||||
$input
|
||||
),
|
||||
"data.$iptName.alt" => $this->compileValidate('required|string|min:5', $input),
|
||||
"data.$iptName.title" => $this->compileValidate('required|string|min:5', $input)
|
||||
"data.$iptName.alt" => $this->compileValidate("$required|string|min:5", $input),
|
||||
"data.$iptName.title" => $this->compileValidate("$required|string|min:5", $input)
|
||||
]);
|
||||
break;
|
||||
case InputType::url->value:
|
||||
|
|
@ -121,7 +152,7 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
"data.$iptName.value",
|
||||
$this->input("data.$iptName.value") ? true : false
|
||||
);
|
||||
$all = array_merge_recursive_distinct($all, $nested);
|
||||
$all = ToolboxHelper::arrayMergeRecursiveDistinct($all, $nested);
|
||||
$this->merge($all);
|
||||
$rules = array_merge($rules, [
|
||||
"data.$iptName.value" => 'boolean'
|
||||
|
|
@ -135,23 +166,63 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $inputTypeValidate
|
||||
* @param array $input
|
||||
* @return string
|
||||
* @param string|array $inputTypeValidate
|
||||
* @param array $input
|
||||
* @return array
|
||||
*/
|
||||
public function compileValidate(string $inputTypeValidate, array $input): string
|
||||
public function compileValidate(string|array $inputTypeValidate, array $input): array
|
||||
{
|
||||
if (!isset($input['validate']) or !\is_string($input['validate'])) {
|
||||
return $inputTypeValidate;
|
||||
if (\is_string($inputTypeValidate)) {
|
||||
$inputTypeValidate = explode('|', $inputTypeValidate);
|
||||
}
|
||||
/** @var array */
|
||||
$inputValidate = explode('|', $input['validate']);
|
||||
$out = explode('|', $inputTypeValidate);
|
||||
/** @var array|string */
|
||||
$inputValidate = \collect($input)->get('validate', $input);
|
||||
$inputValidate = \is_string($inputValidate) ? explode('|', $inputValidate) : $inputValidate;
|
||||
foreach ($inputValidate as $validate) {
|
||||
if (!\in_array($validate, $out)) {
|
||||
$out[] = $validate;
|
||||
if (!\in_array($validate, $inputTypeValidate)) {
|
||||
$inputTypeValidate[] = $validate;
|
||||
}
|
||||
}
|
||||
return \implode('|', $out);
|
||||
|
||||
$test = \collect($inputTypeValidate)->all();
|
||||
$test = \collect($inputTypeValidate)->sort(function ($valueA, $valueB) {
|
||||
$valueA = $this->ruleHasToComeFirst($valueA) ? 0 : 2;
|
||||
$valueB = $this->ruleHasToComeFirst($valueB) ? 1 : 2;
|
||||
return $valueA - $valueB;
|
||||
})->unique()->all();
|
||||
|
||||
return \collect($inputTypeValidate)->unique()->sort(function ($valueA, $valueB) {
|
||||
$valueA = $this->ruleHasToComeFirst($valueA) ? 0 : 2;
|
||||
$valueB = $this->ruleHasToComeFirst($valueB) ? 1 : 2;
|
||||
return $valueA - $valueB;
|
||||
})->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the rulle need to come first ?
|
||||
*
|
||||
* @param string $rule
|
||||
* @return boolean
|
||||
*/
|
||||
private function ruleHasToComeFirst(string $rule): bool
|
||||
{
|
||||
$rule = \collect(\explode(':', $rule, 1))->filter()->first(null, '');
|
||||
return \collect([
|
||||
'nullable', 'present', 'required', 'required_if',
|
||||
'required_unless', 'required_with', 'required_with_all',
|
||||
'required_without', 'required_without_all', 'required_with_all',
|
||||
'missing', 'missing_if', 'missing_unless',
|
||||
'missing_with', 'missing_with_all',
|
||||
])->first(fn (string $firstRule) => \strpos($rule, $firstRule) === 0) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this request an update request ?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function isUpdate(): bool
|
||||
{
|
||||
return $this->isMethod('PUT');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
app/Http/Requests/Bo/UploadFileRequest.php
Normal file
30
app/Http/Requests/Bo/UploadFileRequest.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UploadFileRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check() and $this->ajax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'upload' => 'required|image|mimes:jpeg,png,jpg|max:2048'
|
||||
];
|
||||
}
|
||||
}
|
||||
76
app/Http/Requests/Bo/Users/StoreUserRequest.php
Normal file
76
app/Http/Requests/Bo/Users/StoreUserRequest.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Users;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class StoreUserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Gate::check('create', User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'published' => $this->boolean('published')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => 'required|string|min:3|max:255',
|
||||
'last_name' => 'required|string|min:3|max:255',
|
||||
'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email',
|
||||
'password' => [
|
||||
'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8)
|
||||
->letters()
|
||||
->mixedCase()
|
||||
->numbers()
|
||||
->symbols()
|
||||
->uncompromised()
|
||||
],
|
||||
'role' => ['required', new Enum(RoleEnum::class)],
|
||||
'published' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => trans('validation.attributes.first_name'),
|
||||
'last_name' => trans('validation.attributes.last_name'),
|
||||
'email' => trans('validation.attributes.email'),
|
||||
'password' => trans('validation.attributes.password'),
|
||||
'role' => trans('validation.attributes.role'),
|
||||
'published' => trans('validation.custom.publication')
|
||||
];
|
||||
}
|
||||
}
|
||||
60
app/Http/Requests/Bo/Users/UpdateUserRequest.php
Normal file
60
app/Http/Requests/Bo/Users/UpdateUserRequest.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Users;
|
||||
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class UpdateUserRequest extends StoreUserRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Gate::check('update', $this->route('user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'published' => $this->boolean('published'),
|
||||
'password' => $this->input('password') ??
|
||||
\optional($this->route('user'))->password,
|
||||
'password_confirmation' => $this->input('password_confirmation') ??
|
||||
\optional($this->route('user'))->password
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return array_merge(parent::rules(), [
|
||||
'email' => [
|
||||
'required',
|
||||
'email:rfc,strict,dns,spoof,filter',
|
||||
Rule::unique('users', 'email')->ignore(\optional($this->route('user'))->getRouteKey())
|
||||
],
|
||||
'password' => [
|
||||
'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8)
|
||||
->letters()
|
||||
->mixedCase()
|
||||
->numbers()
|
||||
->symbols()
|
||||
->uncompromised()
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
119
app/Http/Requests/Fo/ListenFormRequest.php
Normal file
119
app/Http/Requests/Fo/ListenFormRequest.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Fo;
|
||||
|
||||
use App\Enums\Country;
|
||||
use App\Enums\Listen\ObjectEnum;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class ListenFormRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'country' => $this->post('country') == null ? $this->post('country') : null,
|
||||
'accept_rules' => $this->boolean('accept_rules'),
|
||||
'send_data' => $this->boolean('send_data'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
ToolboxHelper::validateRecaptcha($this, \config('services.google.recaptcha.version'));
|
||||
$rules = [
|
||||
'first_name' => 'present|nullable|string|between:3,100',
|
||||
'last_name' => 'required|string|between:3,100',
|
||||
'society' => 'present|nullable|string|between:3,255',
|
||||
'email' => 'required|email:rfc,strict,dns,spoof,filter|max:255',
|
||||
// @phpstan-ignore-next-line
|
||||
'phone' => 'present|nullable|' . (
|
||||
Country::make(request()->country)->value === Country::france->value
|
||||
) ? 'phone:FR|max:25' : 'number|max:50',
|
||||
// @phpstan-ignore-next-line
|
||||
'postal_code' => 'present|nullable|' . (
|
||||
Country::make(request()->country)->value === Country::france->value
|
||||
) ? 'postal_code:FR|max:25' : 'number|max:50',
|
||||
'city' => 'present|nullable|string|between:3,20',
|
||||
'country' => ['present', 'nullable', new Enum(Country::class)],
|
||||
'address' => 'present|nullable|string|between:3,255',
|
||||
'object' => ['required', new Enum(ObjectEnum::class)],
|
||||
'message' => 'required|min:20|max:35656',
|
||||
'accept_rules' => 'required|boolean',
|
||||
'send_data' => 'required|boolean',
|
||||
];
|
||||
if (
|
||||
isset(request()->file) and
|
||||
(request()->file->getClientMimeType() === "image/jpeg" ||
|
||||
request()->file->getClientMimeType() === "image/png")
|
||||
) {
|
||||
$rules = \array_merge($rules, $this->pictureRules(
|
||||
'file',
|
||||
0,
|
||||
0,
|
||||
1920,
|
||||
1080,
|
||||
true,
|
||||
3000,
|
||||
));
|
||||
} elseif (isset(request()->file) and (request()->file->getClientMimeType() === "application/pdf")) {
|
||||
$rules = \array_merge($rules, [
|
||||
'file' => 'present|nullable|mimes:pdf'
|
||||
]);
|
||||
} elseif (
|
||||
isset(request()->file) and
|
||||
(request()->file->getClientMimeType() !== "application/pdf") and
|
||||
(request()->file->getClientMimeType() !== "image/jpeg") and
|
||||
(request()->file->getClientMimeType() !== "image/png")
|
||||
) {
|
||||
$rules = \array_merge($rules, [
|
||||
'file' => [
|
||||
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, $value, $fail) {
|
||||
$fail(\trans('Le format du fichier doit être .jpg, .png ou .pdf'));
|
||||
}
|
||||
],
|
||||
]);
|
||||
} //end if
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => trans('validation.attributes.first_name'),
|
||||
'last_name' => trans('validation.attributes.last_name'),
|
||||
'society' => trans('validation.attributes.society'),
|
||||
'email' => trans('validation.attributes.email'),
|
||||
'phone' => trans('validation.attributes.phone'),
|
||||
'postal_code' => trans('validation.attributes.postal_code'),
|
||||
'city' => trans('validation.attributes.city'),
|
||||
'country' => trans('validation.attributes.country'),
|
||||
'address' => trans('validation.attributes.address'),
|
||||
'object' => trans('validation.attributes.object'),
|
||||
'message' => trans('validation.attributes.message'),
|
||||
'file' => trans('validation.attributes.file'),
|
||||
'accept_rules' => trans('validation.attributes.custom.accept_rules'),
|
||||
'send_data' => trans('validation.attributes.custom.send_data'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Lib;
|
||||
namespace App\Lib\Helpers;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
|
@ -16,7 +16,7 @@ class CollectionHelper
|
|||
* @param integer $pageSize
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public static function paginate(Collection $results, int $pageSize): LengthAwarePaginator
|
||||
public static function paginate(Collection $results, int $pageSize): \Illuminate\Pagination\LengthAwarePaginator
|
||||
{
|
||||
$page = Paginator::resolveCurrentPage('page');
|
||||
|
||||
|
|
@ -31,8 +31,11 @@ class CollectionHelper
|
|||
* @param integer $page
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public static function paginateManually(Collection $results, int $pageSize, int $page = 1): LengthAwarePaginator
|
||||
{
|
||||
public static function paginateManually(
|
||||
Collection $results,
|
||||
int $pageSize,
|
||||
int $page = 1
|
||||
): \Illuminate\Pagination\LengthAwarePaginator {
|
||||
$total = $results->count();
|
||||
|
||||
return self::paginator($results->forPage($page, $pageSize), $total, $pageSize, $page, [
|
||||
|
|
@ -51,8 +54,13 @@ class CollectionHelper
|
|||
* @param array $options
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
protected static function paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options)
|
||||
{
|
||||
protected static function paginator(
|
||||
Collection $items,
|
||||
int $total,
|
||||
int $perPage,
|
||||
int $currentPage,
|
||||
array $options
|
||||
): \Illuminate\Pagination\LengthAwarePaginator {
|
||||
return Container::getInstance()->makeWith(LengthAwarePaginator::class, [
|
||||
'items' => $items,
|
||||
'total' => $total,
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@ class ExceptionsHelper
|
|||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Anonymize at least Sql queries
|
||||
*
|
||||
|
|
@ -145,7 +144,7 @@ class ExceptionsHelper
|
|||
$traceStr .= self::handleArgs($stack);
|
||||
}
|
||||
$traceStr .= ")\n";
|
||||
} elseif (isset($stack['function'])) {
|
||||
} else {
|
||||
$traceStr .= "{$stack['function']}(";
|
||||
if (isset($stack['args'])) {
|
||||
$traceStr .= self::handleArgs($stack);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,20 @@ use Illuminate\Support\Str;
|
|||
*/
|
||||
class FileStorageHelper
|
||||
{
|
||||
/**
|
||||
* Remove all files from string attribute html that are stored in public
|
||||
*
|
||||
* @param string $publicStorageFilePath The file path from public directory.
|
||||
* @return string The local storage path.
|
||||
*/
|
||||
public static function getFileFullPath(string $publicStorageFilePath): string
|
||||
{
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter */
|
||||
$disk = Storage::disk('uploads');
|
||||
$path = ToolboxHelper::mbReplace('storage/', '', \ltrim(\urldecode($publicStorageFilePath), '/'));
|
||||
return $disk->path($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the file associate with the attribute.
|
||||
*
|
||||
|
|
@ -118,7 +132,7 @@ class FileStorageHelper
|
|||
);
|
||||
|
||||
return str_replace('/private/', '', $newPath);
|
||||
}//end if
|
||||
} //end if
|
||||
if (\is_object($file) and $file instanceof \SplFileInfo) {
|
||||
/** @var \SplFileInfo $file */
|
||||
$filename = $filename ?: $file->getBaseName();
|
||||
|
|
@ -308,8 +322,7 @@ class FileStorageHelper
|
|||
$folderPath = self::getStoragePath(
|
||||
$private ? 'app/private/modelfiles' : 'app/public/modelfiles',
|
||||
$tableName,
|
||||
$filename,
|
||||
$private
|
||||
$filename
|
||||
);
|
||||
$filename = self::getFileUniqueName($folderPath, $filename);
|
||||
return "{$folderPath}/{$filename}";
|
||||
|
|
@ -404,7 +417,7 @@ class FileStorageHelper
|
|||
$filename = Str::of($filename)->ltrim('.-');
|
||||
// * Optional beautification
|
||||
if ($beautify) {
|
||||
$filename = static::beautifyFilename($filename);
|
||||
$filename = self::beautifyFilename($filename);
|
||||
}
|
||||
// * Maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
|
||||
/** @var string */
|
||||
|
|
@ -451,4 +464,22 @@ class FileStorageHelper
|
|||
$filename = trim($filename, '.-');
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all model files for the given Model.
|
||||
*
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
public static function removeModelFiles(Model $model): void
|
||||
{
|
||||
$tableName = $model::query()->getModel()->getTable();
|
||||
|
||||
if (!empty(Storage::disk('public')->allFiles("modelfiles/{$tableName}"))) {
|
||||
Storage::disk('public')->deleteDirectory("modelfiles/{$tableName}");
|
||||
}
|
||||
if (!empty(Storage::disk('private')->allFiles("modelfiles/{$tableName}"))) {
|
||||
Storage::disk('private')->deleteDirectory("modelfiles/{$tableName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,25 +2,135 @@
|
|||
|
||||
namespace App\Lib\Helpers;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
|
||||
class ToolboxHelper
|
||||
{
|
||||
/**
|
||||
* Run a terminal command and gives the output.
|
||||
*
|
||||
* @param array|string $command The command to execute on terminal.
|
||||
* @param boolean $throw Wether to throw en esception on failure or not.
|
||||
* @return string|false Return false on failure only if $throw is false.
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.EmptyThrows
|
||||
* @phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
|
||||
* @throws \Illuminate\Process\Exceptions\ProcessTimedOutException
|
||||
* @throws \Symfony\Component\Process\Exception\LogicException
|
||||
* @throws \Symfony\Component\Process\Exception\InvalidArgumentException
|
||||
* @throws \Symfony\Component\Process\Exception\RuntimeException
|
||||
* @throws \LogicException
|
||||
* @throws \RuntimeException If the command fails.
|
||||
*/
|
||||
public static function runConsoleCommand(array|string $command, bool $throw = true): string | false
|
||||
{
|
||||
// phpcs:enable
|
||||
$process = \Illuminate\Support\Facades\Process::command($command)->run();
|
||||
if ($process->failed()) {
|
||||
$code = $process->exitCode();
|
||||
$ouput = $process->errorOutput();
|
||||
if ($throw) {
|
||||
throw new \RuntimeException("Failed to run command exit code {$code} with output \n{$ouput}");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return $process->output();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string, mixed> $array1
|
||||
* @param array<int|string, mixed> $array2
|
||||
*
|
||||
* @return array<int|string, mixed>
|
||||
*/
|
||||
public static function arrayMergeRecursiveDistinct(array &$array1, array &$array2): array
|
||||
{
|
||||
$merged = $array1;
|
||||
foreach ($array2 as $key => &$value) {
|
||||
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
|
||||
$merged[$key] = self::arrayMergeRecursiveDistinct($merged[$key], $value);
|
||||
} else {
|
||||
$merged[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate recaptcha.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param boolean $isV3
|
||||
* @return void
|
||||
*/
|
||||
public static function validateRecaptcha(Request $request, bool $isV3 = true): void
|
||||
{
|
||||
Validator::validate($request->all(), [
|
||||
'g-recaptcha-response' => [
|
||||
'required', 'string',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, $value, $fail) use ($isV3) {
|
||||
try {
|
||||
$response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [
|
||||
'secret' => config('services.google.recaptcha.private'),
|
||||
'response' => \strval($value),
|
||||
'remoteip' => app('clientIp')
|
||||
]);
|
||||
if ($e = $response->toException()) {
|
||||
throw $e;
|
||||
}
|
||||
if ($isV3) {
|
||||
if (
|
||||
!$response->json('success') or
|
||||
!$response->json('challenge_ts') or
|
||||
Carbon::parse($response->json('challenge_ts'))->lessThan(\now('utc')->subMinutes(5)) or
|
||||
$response->json('hostname') !== \parse_url(config('app.url'), \PHP_URL_HOST) or
|
||||
!$response->json('score')
|
||||
) {
|
||||
throw new \RuntimeException();
|
||||
}
|
||||
if (\floatval($response->json('score')) < 0.8) {
|
||||
$fail(trans('recaptcha.not_enough_score'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!$response->json('success') or
|
||||
!$response->json('challenge_ts') or
|
||||
Carbon::parse($response->json('challenge_ts'))->lessThan(\now('utc')->subMinutes(5)) or
|
||||
$response->json('hostname') !== \parse_url(config('app.url'), \PHP_URL_HOST)
|
||||
) {
|
||||
throw new \RuntimeException();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$fail(trans('recaptcha.error'));
|
||||
} //end try
|
||||
}
|
||||
]
|
||||
], [], ['g-recaptcha-response' => 'reCaptcha']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip scheme (https) on oembed urls
|
||||
* Only embed allowed are for MP4 self hosted videos right now
|
||||
*
|
||||
* https is force by ckeditor MediaElements which natively supports
|
||||
* only cloud hosted medias (youtube, spotify etc..)
|
||||
* only cloud hosted medias (youtube, spotify etc..).
|
||||
*
|
||||
* @param string $input
|
||||
* @return string
|
||||
|
|
@ -32,7 +142,7 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Assert That no Back Office url is present on txt
|
||||
* Assert That no Back Office url is present on txt.
|
||||
*
|
||||
* @param string $field
|
||||
* @param string $text
|
||||
|
|
@ -75,7 +185,7 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Assert That only external url is present on txt
|
||||
* Assert That only external url is present on txt.
|
||||
*
|
||||
* @param string $field
|
||||
* @param string $text
|
||||
|
|
@ -95,11 +205,10 @@ class ToolboxHelper
|
|||
$url = $match;
|
||||
try {
|
||||
$request = Request::create($url);
|
||||
// If a route is match then it do not throws exception.
|
||||
if (
|
||||
\parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST) &&
|
||||
$routes->match($request)
|
||||
) {
|
||||
// Assert route matches existing routes.
|
||||
$routes->match($request);
|
||||
// ? Is url internal ?
|
||||
if (\parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST)) {
|
||||
// Removes the matched url.
|
||||
throw ValidationException::withMessages([
|
||||
$field => trans(
|
||||
|
|
@ -119,20 +228,20 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Mutltibyte string replace
|
||||
* Mutltibyte string replace.
|
||||
*
|
||||
* @param array|string $search
|
||||
* @param array|string $replace
|
||||
* @param array|string $subject
|
||||
* @param integer $count
|
||||
* @return array|string
|
||||
* @return array|string|false
|
||||
*/
|
||||
public static function mbReplace(
|
||||
array|string $search,
|
||||
array|string $replace,
|
||||
array|string $subject,
|
||||
int &$count = 0
|
||||
): array|string {
|
||||
): array|string|false {
|
||||
if (!is_array($search) && is_array($replace)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -163,7 +272,7 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Asserts that the field is unique
|
||||
* Asserts that the field is unique.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $field
|
||||
|
|
@ -179,7 +288,7 @@ class ToolboxHelper
|
|||
string|int|float|bool|null|array $value,
|
||||
?int $id = null,
|
||||
?callable $query = null
|
||||
) {
|
||||
): void {
|
||||
if (!$query) {
|
||||
Validator::make([$field => $value], [
|
||||
self::mbReplace('.', '\.', $field) => Rule::unique($table, $field)->ignore($id),
|
||||
|
|
@ -200,7 +309,7 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Get original polyfill with autotranslate behavior
|
||||
* Get original polyfill with autotranslate behavior.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $attribute
|
||||
|
|
@ -208,10 +317,17 @@ class ToolboxHelper
|
|||
*/
|
||||
public static function getOriginal(Model $model, string $attribute): mixed
|
||||
{
|
||||
if (\in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model))) {
|
||||
if (
|
||||
\in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model)) and
|
||||
// @phpstan-ignore-next-line
|
||||
$model->isTranslatableAttribute($attribute)
|
||||
) {
|
||||
// @phpstan-ignore-next-line
|
||||
return $model->getTranslation(
|
||||
$attribute,
|
||||
// @phpstan-ignore-next-line
|
||||
$model->getLocale(),
|
||||
// @phpstan-ignore-next-line
|
||||
$model->useFallbackLocale()
|
||||
);
|
||||
}
|
||||
|
|
@ -219,23 +335,23 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Dynamic model query
|
||||
* Dynamic model query.
|
||||
*
|
||||
* @param string $defaultLocale
|
||||
* @param \Illuminate\Contracts\Database\Eloquent\Builder $q
|
||||
* @param string $column
|
||||
* @param string $value
|
||||
* @return \Illuminate\Contracts\Database\Eloquent\Builder
|
||||
* @param string $defaultLocale
|
||||
* @param \Illuminate\Database\Eloquent\Builder $q
|
||||
* @param string $column
|
||||
* @param string $value
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public static function queryColumnWithLocales(
|
||||
string $defaultLocale,
|
||||
Builder $q,
|
||||
string $column,
|
||||
string $value
|
||||
): Builder {
|
||||
): \Illuminate\Database\Eloquent\Builder {
|
||||
$currentLocale = app()->currentLocale();
|
||||
$locales = collect(config('app.locales'))
|
||||
->mapWithKeys(fn (string $locale) => [$locale => $locale]);
|
||||
->mapWithKeys(fn (string $locale) => [$locale => $locale]);
|
||||
if (!$locales->has($defaultLocale)) {
|
||||
// * Remove default locale.
|
||||
$locales->pull($defaultLocale);
|
||||
|
|
@ -260,7 +376,7 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Generates an array from a dot separated string
|
||||
* Generates an array from a dot separated string.
|
||||
*
|
||||
* @param string $path
|
||||
* @param mixed $value
|
||||
|
|
@ -279,61 +395,59 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert deeply an object to array
|
||||
* Convert deeply an object to array.
|
||||
*
|
||||
* @param array|object $input
|
||||
* @param mixed $input
|
||||
* @return array
|
||||
* @throws \RuntimeException If $input var is a scalar value.
|
||||
*/
|
||||
public static function objectToArray($input): array
|
||||
public static function objectToArray(mixed $input): array
|
||||
{
|
||||
// Only process if it's an object or array being passed to the function.
|
||||
if (is_object($input) or is_array($input)) {
|
||||
$ret = (array)$input;
|
||||
foreach ($ret as &$item) {
|
||||
// Recursively process EACH element only if not scalar.
|
||||
$item = (is_object($item) or is_array($item)) ?
|
||||
self::objectToArray($item) : $item;
|
||||
}
|
||||
return $ret;
|
||||
} else {
|
||||
if (!(is_object($input) or is_array($input))) {
|
||||
throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input));
|
||||
}
|
||||
$ret = (array)$input;
|
||||
foreach ($ret as &$item) {
|
||||
// Recursively process EACH element only if not scalar.
|
||||
$item = (is_object($item) or is_array($item)) ?
|
||||
self::objectToArray($item) : $item;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert deeply an array to object
|
||||
* Convert deeply an array to object.
|
||||
*
|
||||
* @param array|object $input
|
||||
* @param mixed $input
|
||||
* @return object
|
||||
* @throws \RuntimeException If $input var is a scalar value.
|
||||
*/
|
||||
public static function arrayToObject($input): object
|
||||
public static function arrayToObject(mixed $input): object
|
||||
{
|
||||
// Only process if it's an object or array being passed to the function.
|
||||
if (is_object($input) or is_array($input)) {
|
||||
$ret = (object)$input;
|
||||
foreach ($ret as &$item) {
|
||||
// Recursively process EACH element only if not scalar.
|
||||
$item = (is_object($item) or is_array($item)) ?
|
||||
self::arrayToObject($item) : $item;
|
||||
}
|
||||
return $ret;
|
||||
} else {
|
||||
if (!(is_object($input) or is_array($input))) {
|
||||
throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input));
|
||||
}
|
||||
$ret = (object)$input;
|
||||
foreach ($ret as &$item) {
|
||||
// Recursively process EACH element only if not scalar.
|
||||
$item = (is_object($item) or is_array($item)) ?
|
||||
self::arrayToObject($item) : $item;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate picture
|
||||
* Validate picture.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string|null $value
|
||||
* @param callback $fail
|
||||
* @param callable $fail
|
||||
* @param object $sizes
|
||||
* @return void
|
||||
*/
|
||||
public static function validatePicture(string $attribute, string|null $value, callable $fail, object $sizes)
|
||||
public static function validatePicture(string $attribute, string|null $value, callable $fail, object $sizes): void
|
||||
{
|
||||
if (!($useStorage = Storage::exists($value)) and !File::exists($value)) {
|
||||
$fail(trans(':attribute n\'existe pas dans le système de fichier', [
|
||||
|
|
@ -341,7 +455,6 @@ class ToolboxHelper
|
|||
]));
|
||||
return;
|
||||
}
|
||||
/** @var string */
|
||||
$fileFullPath = self::getUploadedFileFullPath($value, $useStorage);
|
||||
if (
|
||||
!\in_array(self::getUploadedFileMimeType($value, $useStorage), [
|
||||
|
|
@ -352,7 +465,7 @@ class ToolboxHelper
|
|||
'attribute' => $attribute
|
||||
]));
|
||||
}
|
||||
if (!($dimensions = \getimagesize($fileFullPath)) or !isset($dimensions[0]) or !isset($dimensions[1])) {
|
||||
if (!($dimensions = \getimagesize($fileFullPath))) {
|
||||
$fail(trans(':attribute impossible de valider les dimensions', [
|
||||
'attribute' => $attribute
|
||||
]));
|
||||
|
|
@ -361,19 +474,19 @@ class ToolboxHelper
|
|||
$height = intval($dimensions[1]);
|
||||
|
||||
$xMessage = trans(
|
||||
":attribute la largeur doit être comprise entre {$sizes->minWith}px et {$sizes->maxWith}px"
|
||||
":attribute la largeur doit être comprise entre {$sizes->minWidth}px et {$sizes->maxWidth}px"
|
||||
);
|
||||
if ($sizes->minWith === $sizes->maxWith) {
|
||||
$xMessage = trans(":attribute la largeur doit être de {$sizes->minWith}px");
|
||||
if ($sizes->minWidth === $sizes->maxWidth) {
|
||||
$xMessage = trans(":attribute la largeur doit être de {$sizes->minWidth}px");
|
||||
}
|
||||
$yMessage = trans(
|
||||
":attribute la hauteur doit être comprise entre {$sizes->minWith}px et {$sizes->maxWith}px"
|
||||
":attribute la hauteur doit être comprise entre {$sizes->minHeight}px et {$sizes->maxHeight}px"
|
||||
);
|
||||
if ($sizes->minHeight === $sizes->maxHeight) {
|
||||
$yMessage = trans(":attribute la hauteur doit être de {$sizes->minWith}px");
|
||||
$yMessage = trans(":attribute la hauteur doit être de {$sizes->minHeight}px");
|
||||
}
|
||||
|
||||
if (($width < $sizes->minWith) or ($width > $sizes->maxWith)) {
|
||||
if (($width < $sizes->minWidth) or ($width > $sizes->maxWidth)) {
|
||||
$fail($xMessage);
|
||||
}
|
||||
if (($height < $sizes->minHeight) or ($height > $sizes->maxHeight)) {
|
||||
|
|
@ -383,7 +496,7 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the file full path
|
||||
* Get the file full path.
|
||||
*
|
||||
* @param string $value
|
||||
* @param boolean $useStorage
|
||||
|
|
@ -397,14 +510,64 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the file mimetype
|
||||
* Get the file mimetype.
|
||||
*
|
||||
* @param string $value
|
||||
* @param boolean $useStorage
|
||||
* @return string|false
|
||||
*/
|
||||
private static function getUploadedFileMimeType(string $value, bool $useStorage)
|
||||
private static function getUploadedFileMimeType(string $value, bool $useStorage): string|false
|
||||
{
|
||||
return !$useStorage ? File::mimeType($value) : Storage::mimeType($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch class list from a specific namespace.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @return array<string> An array of classe namespaces
|
||||
*/
|
||||
public static function getClassesUsingNamespace(string $namespace): array
|
||||
{
|
||||
return collect(File::files(\app_path(Str::of($namespace)->replaceFirst('\App', ''))))
|
||||
->filter(fn (SplFileInfo $splFileInfo) => $splFileInfo->getExtension() === 'php')
|
||||
->map(fn (SplFileInfo $splFileInfo) => Str::of($splFileInfo->getBasename())
|
||||
->replace('.' . $splFileInfo->getExtension(), '')->prepend("{$namespace}\\"))->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all classes from a specific namespace that implement a specific interface.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param string $interface
|
||||
* @return array<string> An array of classe namespaces
|
||||
*/
|
||||
public static function getClassesUsingInterface(string $namespace, string $interface): array
|
||||
{
|
||||
return Arr::where(
|
||||
static::getClassesUsingNamespace($namespace),
|
||||
fn (string $class_namespace) => \collect(class_implements($class_namespace, true))->filter()
|
||||
->contains(fn (string $class_interface) => $class_interface === $interface)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get validated pagination from request.
|
||||
*
|
||||
* @param integer $default
|
||||
* @param string $field
|
||||
* @param string $enumPath
|
||||
* @return integer
|
||||
*/
|
||||
public static function getValidatedEnum(int $default, string $field, string $enumPath): int
|
||||
{
|
||||
try {
|
||||
return \intval(Validator::make(
|
||||
[$field => \request()->get($field)],
|
||||
[$field => new Enum($enumPath)]
|
||||
)->validated()[$field]);
|
||||
} catch (ValidationException $e) {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
91
app/Mail/SendConfirmationMail.php
Normal file
91
app/Mail/SendConfirmationMail.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Mail\Markdown;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SendConfirmationMail extends Mailable
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var \stdClass
|
||||
*/
|
||||
private \stdClass $data;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param \stdClass $data
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(\stdClass $data)
|
||||
{
|
||||
$this->data = clone $data;
|
||||
$this->sanitizeStringInputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes user message
|
||||
*
|
||||
* ! This is not recursive !
|
||||
* * Prevent xss injection via markdown interpretation.
|
||||
*
|
||||
* La solution devrai etre de filtrer en sortie, mais il n'est pas possible de
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function sanitizeStringInputs(): void
|
||||
{
|
||||
$this->data = (object)Arr::map((array)$this->data, function ($el) {
|
||||
if (is_string($el)) {
|
||||
$el = \htmlspecialchars(\strip_tags(Blade::render(
|
||||
(string)Markdown::parse($el)
|
||||
)));
|
||||
$el = Str::of($el)->replaceMatches(
|
||||
'/[^\p{L}0-9\n\s\@\.\:\-\_\?\!\;\(\)\+\-\/\\\=]+/us',
|
||||
''
|
||||
)->trim()->wordWrap(75, "\n", true)->toString();
|
||||
}
|
||||
return $el;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): \Illuminate\Mail\Mailables\Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: sprintf(
|
||||
'%s - %s',
|
||||
trans('Confirmation d\'envoi'),
|
||||
config('app.name')
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): \Illuminate\Mail\Mailables\Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.send-confirmation-form',
|
||||
with: ['data' => $this->data],
|
||||
);
|
||||
}
|
||||
}
|
||||
110
app/Mail/SendContactMail.php
Normal file
110
app/Mail/SendContactMail.php
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Enums\Listen\ObjectEnum;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Mail\Markdown;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SendContactMail extends Mailable
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var \stdClass
|
||||
*/
|
||||
private \stdClass $data;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param \stdClass $data
|
||||
* @return void
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
*/
|
||||
public function __construct(\stdClass $data)
|
||||
{
|
||||
$this->data = clone $data;
|
||||
$this->sanitizeStringInputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes user message.
|
||||
*
|
||||
* ! This is not recursive !
|
||||
* * Prevent xss injection via markdown interpretation.
|
||||
*
|
||||
* La solution devrai etre de filtrer en sortie, mais il n'est pas possible de
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function sanitizeStringInputs(): void
|
||||
{
|
||||
$this->data = (object)Arr::map((array)$this->data, function ($el) {
|
||||
if (is_string($el)) {
|
||||
$el = \htmlspecialchars(\strip_tags(Blade::render(
|
||||
(string)Markdown::parse($el)
|
||||
)));
|
||||
$el = Str::of($el)->replaceMatches(
|
||||
'/[^\p{L}0-9\n\s\@\.\:\-\_\?\!\;\(\)\+\-\/\\\=]+/us',
|
||||
''
|
||||
)->trim()->wordWrap(75, "\n", true)->toString();
|
||||
}
|
||||
return $el;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): \Illuminate\Mail\Mailables\Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: sprintf(
|
||||
'%s - %s',
|
||||
ObjectEnum::make($this->data->object)->label(),
|
||||
config('app.name')
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): \Illuminate\Mail\Mailables\Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.send-contact-form',
|
||||
with: ['data' => $this->data],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
$attachments = [];
|
||||
if (isset($this->data->file)) {
|
||||
$attachments[] = Attachment::fromPath($this->data->file->getRealPath())
|
||||
->as($this->data->file->getClientOriginalName())
|
||||
->withMime($this->data->file->getClientMimeType());
|
||||
}
|
||||
return $attachments;
|
||||
}
|
||||
}
|
||||
177
app/Models/ActivityLog.php
Normal file
177
app/Models/ActivityLog.php
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ActivityLogs\ActivityLogsEventEnum;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property string $model Target model.
|
||||
* @property string $model_id Id of the target model.
|
||||
* @property \App\Enums\ActivityLogs\ActivityLogsEventEnum $event Event of this activity (ActivityLogsEventEnum).
|
||||
* @property array $data Changes.
|
||||
* @property \Illuminate\Support\Carbon $created_at Created date.
|
||||
*
|
||||
* @property-read \App\Models\User $user User BelongsTo relation.
|
||||
*/
|
||||
class ActivityLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'is_anonymous',
|
||||
'model_class',
|
||||
'model_id',
|
||||
'event',
|
||||
'data',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'is_anonymous' => 'bool',
|
||||
'event' => ActivityLogsEventEnum::class,
|
||||
'data' => 'json',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Add new activity to the activity logs list.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param \App\Enums\ActivityLogs\ActivityLogsEventEnum $eventEnum
|
||||
* @return void
|
||||
*/
|
||||
public static function addActivity(Model $model, ActivityLogsEventEnum $eventEnum): void
|
||||
{
|
||||
$isAnonymous = true;
|
||||
/** @var \Illuminate\Database\Eloquent\Model|null */
|
||||
$userModel = auth('backend')->user();
|
||||
if (is_object($userModel)) {
|
||||
$userModel = $userModel->getKeyForSelectQuery();
|
||||
$isAnonymous = false;
|
||||
}
|
||||
$activity = new self();
|
||||
$activity->user_id = $userModel;
|
||||
$activity->is_console = app()->runningInConsole();
|
||||
$activity->is_anonymous = $isAnonymous;
|
||||
$activity->model_class = \get_class($model);
|
||||
$activity->model_id = $model->getKey();
|
||||
$activity->event = $eventEnum;
|
||||
$activity->data = static::getChangedColumns($activity, $model, $eventEnum);
|
||||
$activity->created_at = now();
|
||||
$activity->saveOrFail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get old, new columns that has changed.
|
||||
*
|
||||
* @param self $activity
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param \App\Enums\ActivityLogs\ActivityLogsEventEnum $eventEnum
|
||||
* @return array
|
||||
*/
|
||||
public static function getChangedColumns(self $activity, Model $model, ActivityLogsEventEnum $eventEnum): array
|
||||
{
|
||||
$modelClassName = $activity->model_class;
|
||||
/** Get type of each fields of the target model */
|
||||
/** @var \Illuminate\Database\Eloquent\Model|null $targetModel */
|
||||
$targetModel = $activity->model_class::where(
|
||||
(new $modelClassName())->getRouteKeyName(),
|
||||
$activity->model_id
|
||||
)->first();
|
||||
|
||||
if (\is_null($targetModel)) {
|
||||
return [];
|
||||
}
|
||||
$targetModelTypes = collect($targetModel->toArray())
|
||||
->map(fn ($value) => self::getValueType($value))
|
||||
->toArray();
|
||||
/** Return old, new and type of values changed */
|
||||
return match ($eventEnum) {
|
||||
ActivityLogsEventEnum::created => array_intersect_key($targetModelTypes, $model->toArray()),
|
||||
ActivityLogsEventEnum::duplicated => array_intersect_key($targetModelTypes, $model->toArray()),
|
||||
ActivityLogsEventEnum::updated => array_intersect_key($targetModelTypes, $model->getChanges()),
|
||||
default => []
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a value type as a string
|
||||
* ! Use this for display purpose only.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
* @throws \RuntimeException If type is unhlanded.
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded
|
||||
*/
|
||||
private static function getValueType(mixed $value): string
|
||||
{
|
||||
// phpcs:enable
|
||||
$type = \gettype($value);
|
||||
switch ($type) {
|
||||
case 'string':
|
||||
return match (true) {
|
||||
Str::length(\strip_tags($value)) !== Str::length($value) => 'html',
|
||||
Str::startsWith($value, 'storage/modelfiles') => 'file',
|
||||
Str::isUuid($value) => 'uuid',
|
||||
Str::isUlid($value) => 'ulid',
|
||||
Str::isUrl($value) => 'url',
|
||||
Str::isMatch('/^[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]$/', $value) => 'youtube_video_id',
|
||||
\is_numeric($value) => 'numeric',
|
||||
Str::isJson($value) and
|
||||
(Str::startsWith($value, '[') or Str::startsWith($value, '{')) => 'json',
|
||||
default => 'string'
|
||||
};
|
||||
case 'NULL':
|
||||
case 'object':
|
||||
case 'array':
|
||||
case 'integer':
|
||||
case 'boolean':
|
||||
return $type;
|
||||
case 'double':
|
||||
return is_float($value) ? 'float' : 'double';
|
||||
case 'resource (closed)':
|
||||
case 'resource':
|
||||
throw new \RuntimeException('Laravel model properties should not contain resources !');
|
||||
case 'unknown type':
|
||||
default:
|
||||
throw new \RuntimeException('Unhandled Type ' . \gettype($value));
|
||||
} //end switch
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* User BelongsTo relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
93
app/Models/HistoricalMilestone.php
Normal file
93
app/Models/HistoricalMilestone.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property string $title Title.
|
||||
* @property string $text Description.
|
||||
* @property string $picture Path of the image.
|
||||
* @property string $picture_alt Alt attribute of the image.
|
||||
* @property string $picture_title Title attribute of the image.
|
||||
* @property boolean $button_status Is the button visible ?.
|
||||
* @property string $button_label Button label, max 35 characters. Required if the button is visible.
|
||||
* @property string $button_url Button URL. equired if the button is visible.
|
||||
* @property boolean $button_new_tab Does the link need to be opened in a new tab ?
|
||||
* @property integer $year Year of the historical milestone.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class HistoricalMilestone extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'text',
|
||||
'picture',
|
||||
'picture_alt',
|
||||
'picture_title',
|
||||
'button_status',
|
||||
'button_label',
|
||||
'button_url',
|
||||
'button_new_tab',
|
||||
'year',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'button_status' => 'boolean',
|
||||
'button_new_tab' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
FileStorageHelper::removeOldFile($model, 'picture');
|
||||
});
|
||||
|
||||
static::deleted(function (self $model) {
|
||||
FileStorageHelper::removeFile($model, 'picture');
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
||||
}
|
||||
}
|
||||
33
app/Models/JobVideo.php
Normal file
33
app/Models/JobVideo.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property string $title Title.
|
||||
* @property string $place Place of the video.
|
||||
* @property string $video_id Id of the Youtube video.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class JobVideo extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'place',
|
||||
'video_id',
|
||||
];
|
||||
}
|
||||
84
app/Models/Logo.php
Normal file
84
app/Models/Logo.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property string $label Label.
|
||||
* @property string $picture Path of the image.
|
||||
* @property string $picture_alt Alt attribute of the image.
|
||||
* @property string $picture_title Title attribute of the image.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\Site $sites Sites Many-to-many relationship.
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class Logo extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'label',
|
||||
'picture',
|
||||
'picture_alt',
|
||||
'picture_title',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
FileStorageHelper::removeOldFile($model, 'picture');
|
||||
});
|
||||
|
||||
static::deleted(function (self $model) {
|
||||
FileStorageHelper::removeFile($model, 'picture');
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* The sites that belong to the logo.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function sites(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Site::class);
|
||||
}
|
||||
}
|
||||
212
app/Models/News.php
Normal file
212
app/Models/News.php
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property string $seo_title SEO title.
|
||||
* @property string $seo_description SEO description.
|
||||
* @property string $title Title.
|
||||
* @property string $slug Slug of the title.
|
||||
* @property string $introduction WYSIWYG - Introduction.
|
||||
* @property string|null $content WYSIWYG - Content.
|
||||
* @property string|null $linkedin_url Url of the linkedin related post.
|
||||
* @property string $thumbnail Path of the thumbnail.
|
||||
* @property string $thumbnail_alt Thumbnail alt attribute.
|
||||
* @property string $thumbnail_title Thumbnail title attribute.
|
||||
* @property string $picture Path of the picture.
|
||||
* @property string $picture_alt Picture alt attribute..
|
||||
* @property string $picture_title Picture title attribute.
|
||||
* @property integer $order Order.
|
||||
* @property boolean $published Publication status.
|
||||
* @property \Carbon\Carbon|null $publish_at Publication date.
|
||||
* @property \Carbon\Carbon|null $unpublish_at Unpublication status update date.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class News extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'seo_title',
|
||||
'seo_description',
|
||||
'title',
|
||||
'slug',
|
||||
'introduction',
|
||||
'content',
|
||||
'linkedin_url',
|
||||
'thumbnail',
|
||||
'thumbnail_alt',
|
||||
'thumbnail_title',
|
||||
'picture',
|
||||
'picture_alt',
|
||||
'picture_title',
|
||||
'order',
|
||||
'published',
|
||||
'publish_at',
|
||||
'unpublish_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'published' => 'bool',
|
||||
'publish_at' => 'datetime',
|
||||
'unpublish_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::setOrder($model);
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
FileStorageHelper::removeOldFile($model, 'picture');
|
||||
});
|
||||
|
||||
static::deleted(function (self $model) {
|
||||
FileStorageHelper::removeFile($model, 'picture');
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
// * ASSERTIONS
|
||||
self::assertFieldIsUnique('title', $model->title, $model->id);
|
||||
self::assertFieldIsUnique('slug', Str::slug($model->title), $model->id);
|
||||
|
||||
ToolboxHelper::assertNoInternalBoUrls('introduction', $model->introduction);
|
||||
$model->introduction = clean($model->introduction);
|
||||
if ($model->content) {
|
||||
ToolboxHelper::assertNoInternalBoUrls('content', $model->content);
|
||||
$model->content = clean($model->content);
|
||||
}
|
||||
|
||||
// * TRANSFORMATIONS
|
||||
self::setSlug($model, $model->title);
|
||||
self::makeStatusSense($model);
|
||||
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
||||
$model->thumbnail = FileStorageHelper::storeFile($model, $model->thumbnail, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the slug.
|
||||
*
|
||||
* @param self $model
|
||||
* @param string $original
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function setSlug(self $model, string $original): void
|
||||
{
|
||||
$model->slug = Str::slug($original);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order after the last element of the list.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function setOrder(self $model): void
|
||||
{
|
||||
$model->order = \intval(self::query()->max('order')) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts using validation that the field is unique.
|
||||
*
|
||||
* @param string $nameField
|
||||
* @param string $valueField
|
||||
* @param integer|null $id
|
||||
* @return void
|
||||
*/
|
||||
private static function assertFieldIsUnique(string $nameField, string $valueField, ?int $id = null): void
|
||||
{
|
||||
$table = (new self())->getTable();
|
||||
ToolboxHelper::assertFieldIsUnique($table, $nameField, $valueField, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts model status using current status and publish dates.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function makeStatusSense(self $model): void
|
||||
{
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$publish_at = $model->publish_at;
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$unpublish_at = $model->unpublish_at;
|
||||
$wantedStatus = $model->published;
|
||||
if ($publish_at or $unpublish_at) {
|
||||
$model->published = $model->planificated_status;
|
||||
}
|
||||
if ($wantedStatus !== $model->published) {
|
||||
$previousMessage = session()->get('bo.info', '');
|
||||
session()->flash('bo.info', \trans(
|
||||
'La publication est modifiée en concordance avec les dates enregistrées.
|
||||
Pour modifier l\'état de publication, veuillez modifier ou enlever les dates correspondantes.'
|
||||
) . " \n{$previousMessage}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter the current status following planification dates planificated_status.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getPlanificatedStatusAttribute(): bool
|
||||
{
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$publish_at = $this->publish_at;
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$unpublish_at = $this->unpublish_at;
|
||||
if ($publish_at and $unpublish_at) {
|
||||
return $unpublish_at->greaterThanOrEqualTo(now()) and $publish_at->lessThan(now());
|
||||
}
|
||||
if ($publish_at) {
|
||||
return $publish_at->lessThan(now());
|
||||
}
|
||||
if ($unpublish_at) {
|
||||
return $unpublish_at->greaterThanOrEqualTo(now());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
279
app/Models/Section.php
Normal file
279
app/Models/Section.php
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\CkEditorConfigName;
|
||||
use App\Enums\InputType;
|
||||
use App\Enums\Sections\PageSectionEnum;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use App\Traits\Models\MiniCrudModel;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property \App\Enums\Sections\PageSectionEnum $section Slider that contains the slide.
|
||||
* @property string $h2_title Title.
|
||||
* @property string $text WYSIWYG - Content.
|
||||
* @property string $data Minicrud content.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\StaticPage $page StaticPage Belongs to relationship.
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class Section extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
use MiniCrudModel;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'section',
|
||||
'h2_title',
|
||||
'text',
|
||||
'data',
|
||||
'page_id',
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'section' => PageSectionEnum::class,
|
||||
'data' => 'object',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function () {
|
||||
throw new \RuntimeException("Creating a new section is not authorized");
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
// * ASSERTIONS
|
||||
ToolboxHelper::assertNoInternalBoUrls('text', $model->text);
|
||||
|
||||
// * TRANSFORMATIONS
|
||||
$model->text = FileStorageHelper::storeModelFilesFromHtml($model, $model->text);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
FileStorageHelper::removeOldModelFilesFromHtml(
|
||||
$model->text,
|
||||
ToolboxHelper::getOriginal($model, 'text')
|
||||
);
|
||||
});
|
||||
static::deleting(function () {
|
||||
throw new \RuntimeException('Deleting a section is not authorized');
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS.
|
||||
// * EMPTY BLOCS.
|
||||
|
||||
/**
|
||||
* Empty bloc for picture.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $img
|
||||
* @param string $imgAlt
|
||||
* @param string $imgTitle
|
||||
* @param integer $width
|
||||
* @param integer $height
|
||||
* @param boolean $required
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public static function emptyPictureBloc(
|
||||
array $data,
|
||||
string $img = '',
|
||||
string $imgAlt = '',
|
||||
string $imgTitle = '',
|
||||
int $width = 100,
|
||||
int $height = 100,
|
||||
bool $required = false,
|
||||
string $name = 'image',
|
||||
): array {
|
||||
$data[sprintf('bloc_%s', Str::of($name)->snake()->ascii()->remove(['\'', '-']))] = [
|
||||
'label' => $name,
|
||||
'dimensions' => ['width' => $width, 'height' => $height],
|
||||
'inputType' => InputType::image->value,
|
||||
'alt' => $imgAlt,
|
||||
'title' => $imgTitle,
|
||||
'value' => $img,
|
||||
'validate' => $required ? 'required' : 'nullable',
|
||||
'required' => $required
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty bloc for link.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $url
|
||||
* @param boolean $required
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public static function emptyLinkBloc(
|
||||
array $data,
|
||||
string $url = '',
|
||||
bool $required = false,
|
||||
string $name = "URL à ouvrir",
|
||||
): array {
|
||||
$data["bloc_link"] = [
|
||||
'label' => $name,
|
||||
'inputType' => InputType::url->value,
|
||||
'value' => $url,
|
||||
'validate' => 'url|' . ($required ? 'required' : 'nullable'),
|
||||
'required' => $required
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty bloc for boolean new tab link.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public static function emptyLinkNewTabBloc(
|
||||
array $data,
|
||||
string $name = 'le lien',
|
||||
): array {
|
||||
$data["bloc_link_new_tab"] = [
|
||||
'label' => "Ouvrir dans un nouvel onglet {$name}",
|
||||
'inputType' => InputType::boolean->value,
|
||||
'value' => true,
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty bloc for key numbers.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $name
|
||||
* @param integer $value
|
||||
* @param boolean $required
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function emptyKeyNumberBloc(
|
||||
array $data,
|
||||
string $name,
|
||||
int $value = 0,
|
||||
bool $required = false,
|
||||
): array {
|
||||
$data['bloc_key_' . Str::of($name)->snake()->ascii()->remove(['\'', '-'])] = [
|
||||
'label' => "Chiffre clé {$name}",
|
||||
'inputType' => InputType::number->value,
|
||||
'value' => $value,
|
||||
'validate' => $required ? 'required' : 'nullable',
|
||||
'required' => $required
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty bloc for the button boolean.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public static function emptyButtonBooleanBloc(
|
||||
array $data,
|
||||
string $name
|
||||
): array {
|
||||
$data['bloc_button_' . Str::of($name)->snake()->ascii()->remove(['\'', '-'])] = [
|
||||
'label' => "Afficher le bouton '{$name}' ?",
|
||||
'inputType' => InputType::boolean->value,
|
||||
'value' => false
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty bloc for the h3 title.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param boolean $required
|
||||
* @return array
|
||||
*/
|
||||
public static function emptyStringBloc(
|
||||
array $data,
|
||||
string $name,
|
||||
string $value = '',
|
||||
bool $required = false
|
||||
): array {
|
||||
$data['bloc_string_' . Str::of($name)->snake()->ascii()->remove(['\'', '-'])] = [
|
||||
'label' => $name,
|
||||
'inputType' => InputType::string->value,
|
||||
'validate' => 'max:255|' . ($required ? 'required' : 'nullable'),
|
||||
'value' => $value,
|
||||
'required' => $required
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty bloc for the WYSIWYG content.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param \App\Enums\CkEditorConfigName $config
|
||||
* @param boolean $required
|
||||
* @return array
|
||||
*/
|
||||
public static function emptyWysiwygBloc(
|
||||
array $data,
|
||||
string $name,
|
||||
string $value = '',
|
||||
CkEditorConfigName $config = CkEditorConfigName::base,
|
||||
bool $required = false
|
||||
): array {
|
||||
$data['bloc_' . Str::of($name)->snake()->ascii()->remove(['\'', '-']) . '_content'] = [
|
||||
'label' => "Contenu de la section {$name}",
|
||||
'inputType' => InputType::text->value,
|
||||
'validate' => $required ? 'required' : 'nullable',
|
||||
'value' => $value,
|
||||
'required' => $required,
|
||||
'config' => $config->name
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Get the page that owns the section.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function page(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StaticPage::class);
|
||||
}
|
||||
}
|
||||
206
app/Models/Site.php
Normal file
206
app/Models/Site.php
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property string $seo_title SEO title.
|
||||
* @property string $seo_description SEO description.
|
||||
* @property string $name Name.
|
||||
* @property string $slug Slug of the name.
|
||||
* @property string $description First level of description.
|
||||
* @property string $description_2 Second level of description.
|
||||
* @property integer $employees Employees count.
|
||||
* @property string $pictos JSON - SpeciesEnum Values. Between 0 and n.
|
||||
* @property string $address Address of the site.
|
||||
* @property string $phone_number Phone number of the site.
|
||||
* @property string $access_line JSON - How to go to the site. 3 entries.
|
||||
* @property string $director_name Name of the director.
|
||||
* @property string $director_speach WYSIWYG - Director speach.
|
||||
* @property string $employee_name Name of the employee.
|
||||
* @property string $employee_functi Function of the employee.
|
||||
* @property string $employee_speach WYSIWYG - Employee speach.
|
||||
* @property string $highlights WYSIWYG - Highlights part content.
|
||||
* @property double $latitude Latitude in degrees.
|
||||
* @property double $longitude Longitude in degrees.
|
||||
* @property string $logo Path of the logo.
|
||||
* @property string $logo_alt Logo alt attribute.
|
||||
* @property string $logo_title Logo title attribute.
|
||||
* @property string $picture_1 Path of the picture 1.
|
||||
* @property string $picture_1_alt Picture 1 alt attribute.
|
||||
* @property string $picture_1_title Picture 1 title attribute.
|
||||
* @property string $picture_2 Path of the picture 2.
|
||||
* @property string $picture_2_alt Picture 2 alt attribute.
|
||||
* @property string $picture_2_title Picture 2 title attribute.
|
||||
* @property string $picture_3 Path of the picture 3.
|
||||
* @property string $picture_3_alt Picture 3 alt attribute.
|
||||
* @property string $picture_3_title Picture 3 title attribute.
|
||||
* @property integer $order Order.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\Logo $logos Logos Many-to-many relationship.
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class Site extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'seo_title',
|
||||
'seo_description',
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
'description_2',
|
||||
'employees',
|
||||
'pictos',
|
||||
'address',
|
||||
'phone_number',
|
||||
'access_line',
|
||||
'director_name',
|
||||
'director_speach',
|
||||
'employee_name',
|
||||
'employee_function',
|
||||
'employee_speach',
|
||||
'highlights',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'logo',
|
||||
'logo_alt',
|
||||
'logo_title',
|
||||
'picture_1',
|
||||
'picture_1_alt',
|
||||
'picture_1_title',
|
||||
'picture_2',
|
||||
'picture_2_alt',
|
||||
'picture_2_title',
|
||||
'picture_3',
|
||||
'picture_3_alt',
|
||||
'picture_3_title',
|
||||
'order',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'pictos' => 'array',
|
||||
'access_line' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::setOrder($model);
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
FileStorageHelper::removeOldFile($model, 'logo');
|
||||
FileStorageHelper::removeOldFile($model, 'picture_1');
|
||||
FileStorageHelper::removeOldFile($model, 'picture_2');
|
||||
FileStorageHelper::removeOldFile($model, 'picture_3');
|
||||
});
|
||||
|
||||
static::deleted(function (self $model) {
|
||||
FileStorageHelper::removeFile($model, 'logo');
|
||||
FileStorageHelper::removeFile($model, 'picture_1');
|
||||
FileStorageHelper::removeFile($model, 'picture_2');
|
||||
FileStorageHelper::removeFile($model, 'picture_3');
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
// * ASSERTIONS
|
||||
self::assertFieldIsUnique('name', $model->name, $model->id);
|
||||
self::assertFieldIsUnique('slug', Str::slug($model->name), $model->id);
|
||||
|
||||
// * TRANSFORMATIONS
|
||||
self::setSlug($model, $model->name);
|
||||
$model->logo = FileStorageHelper::storeFile($model, $model->logo, true);
|
||||
$model->picture_1 = FileStorageHelper::storeFile($model, $model->picture_1, true);
|
||||
$model->picture_2 = FileStorageHelper::storeFile($model, $model->picture_2, true);
|
||||
$model->picture_3 = FileStorageHelper::storeFile($model, $model->picture_3, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the slug.
|
||||
*
|
||||
* @param self $model
|
||||
* @param string $original
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function setSlug(self $model, string $original): void
|
||||
{
|
||||
$model->slug = Str::slug($original);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order after the last element of the list.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function setOrder(self $model): void
|
||||
{
|
||||
$model->order = \intval(self::query()->max('order')) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts using validation that the field is unique.
|
||||
*
|
||||
* @param string $nameField
|
||||
* @param string $valueField
|
||||
* @param integer|null $id
|
||||
* @return void
|
||||
*/
|
||||
private static function assertFieldIsUnique(string $nameField, string $valueField, ?int $id = null): void
|
||||
{
|
||||
$table = (new self())->getTable();
|
||||
ToolboxHelper::assertFieldIsUnique($table, $nameField, $valueField, $id);
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* The logos that belong to the site.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function logos(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Logo::class);
|
||||
}
|
||||
}
|
||||
96
app/Models/Slide.php
Normal file
96
app/Models/Slide.php
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Slides\SliderTypeEnum;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property \App\Enums\Slides\SliderTypeEnum $type Slide type.
|
||||
* @property string $title Slide title.
|
||||
* @property string $content Slide content.
|
||||
* @property string $video_id Slide video id.
|
||||
* @property boolean $button_status Slide button status.
|
||||
* @property string $button_label Slide button label.
|
||||
* @property string $button_url Slide button url.
|
||||
* @property boolean $button_new_tab Open the slide button url in a new tag.
|
||||
* @property string $picture Slide picture path.
|
||||
* @property string $picture_alt Slide picture alt attribute.
|
||||
* @property string $picture_title Slide picture title attribute.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class Slide extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'type',
|
||||
'title',
|
||||
'content',
|
||||
'video_id',
|
||||
'button_status',
|
||||
'button_label',
|
||||
'button_url',
|
||||
'button_new_tab',
|
||||
'picture',
|
||||
'picture_alt',
|
||||
'picture_title',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'type' => SliderTypeEnum::class,
|
||||
'button_status' => 'boolean',
|
||||
'button_new_tab' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
FileStorageHelper::removeOldFile($model, 'picture');
|
||||
});
|
||||
static::deleted(function (self $model) {
|
||||
FileStorageHelper::removeFile($model, 'picture');
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
||||
}
|
||||
}
|
||||
113
app/Models/StaticPage.php
Normal file
113
app/Models/StaticPage.php
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\StaticPageType;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property \App\Enums\StaticPageType $type Page type (StaticPageEnum).
|
||||
* @property string $seo_title Seo title about 70 chars as recommended.
|
||||
* @property string $seo_description Seo description about 160 chars as recommended.
|
||||
* @property string $title Title for the page.
|
||||
* @property string $slug Slug of the title for the page.
|
||||
* @property string $content WYSIWYG text content using ckeditor.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class StaticPage extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'seo_title',
|
||||
'seo_description',
|
||||
'title',
|
||||
'content',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'type' => StaticPageType::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
// * ASSERTIONS
|
||||
self::assertTitleIsUnique($model->title);
|
||||
// * CHANGES
|
||||
$model->slug = Str::slug($model->title);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
// * ASSERTIONS
|
||||
self::assertTitleIsUnique($model->title, $model->id);
|
||||
// * CHANGES
|
||||
$model->slug = Str::slug($model->title);
|
||||
});
|
||||
}
|
||||
|
||||
// * ROUTABLE
|
||||
|
||||
/**
|
||||
* Get the value of the model's route key.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRouteKey(): mixed
|
||||
{
|
||||
/** @var \App\Enums\StaticPageType */
|
||||
$enum = $this->getAttribute($this->getRouteKeyName());
|
||||
return $enum->value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the route key for the model.
|
||||
*
|
||||
* ! Type is the routable parameter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'type';
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Asserts using validation that the title is unique
|
||||
*
|
||||
* @param string|null $title
|
||||
* @param integer|null $id
|
||||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException If an actu title already exists.
|
||||
*/
|
||||
private static function assertTitleIsUnique(string|null $title, ?int $id = null): void
|
||||
{
|
||||
$table = (new self())->getTable();
|
||||
ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id);
|
||||
ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id);
|
||||
}
|
||||
}
|
||||
140
app/Models/Strip.php
Normal file
140
app/Models/Strip.php
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Strips\PictoEnum;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property App\Enums\Strips\PictoEnum $picto Picto.
|
||||
* @property string $text WYSIWYG restrained (blod and underline only). Text.
|
||||
* @property boolean $published Publication status.
|
||||
* @property \Carbon\Carbon|null $publish_at Publication date.
|
||||
* @property \Carbon\Carbon|null $unpublish_at Unpublication status update date.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\News $news News Belongs to relationship.
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class Strip extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'picto',
|
||||
'text',
|
||||
'published',
|
||||
'publish_at',
|
||||
'unpublish_at',
|
||||
'news_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'picto' => PictoEnum::class,
|
||||
'published' => 'bool',
|
||||
'publish_at' => 'datetime',
|
||||
'unpublish_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
self::makeStatusSense($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts model status using current status and publish dates
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function makeStatusSense(self $model): void
|
||||
{
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$publish_at = $model->publish_at;
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$unpublish_at = $model->unpublish_at;
|
||||
$wantedStatus = $model->published;
|
||||
if ($publish_at or $unpublish_at) {
|
||||
$model->published = $model->planificated_status;
|
||||
}
|
||||
if ($wantedStatus !== $model->published) {
|
||||
$previousMessage = session()->get('bo.info', '');
|
||||
session()->flash('bo.info', \trans(
|
||||
'La publication est modifiée en concordance avec les dates enregistrées.
|
||||
Pour modifier l\'état de publication, veuillez modifier ou enlever les dates correspondantes.'
|
||||
) . " \n{$previousMessage}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter the current status following planification dates planificated_status.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getPlanificatedStatusAttribute(): bool
|
||||
{
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$publish_at = $this->publish_at;
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$unpublish_at = $this->unpublish_at;
|
||||
if ($publish_at and $unpublish_at) {
|
||||
return $unpublish_at->greaterThanOrEqualTo(now()) and $publish_at->lessThan(now());
|
||||
}
|
||||
if ($publish_at) {
|
||||
return $publish_at->lessThan(now());
|
||||
}
|
||||
if ($unpublish_at) {
|
||||
return $unpublish_at->greaterThanOrEqualTo(now());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Get the news that owns the strip.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function news(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(News::class);
|
||||
}
|
||||
}
|
||||
86
app/Models/Testimonial.php
Normal file
86
app/Models/Testimonial.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Testimonials\TypeEnum;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property string $name Name of the person.
|
||||
* @property string $job Function of the person.
|
||||
* @property string $content WYSIWYG - Content.
|
||||
* @property \App\Enums\Testimonials\TypeEnum $type Type of the testimonial.
|
||||
* @property string $picture Path of the image.
|
||||
* @property string $picture_alt Alt attribute of the image.
|
||||
* @property string $picture_title Title attribute of the image.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class Testimonial extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'job',
|
||||
'content',
|
||||
'type',
|
||||
'picture',
|
||||
'picture_alt',
|
||||
'picture_title',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'type' => TypeEnum::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
FileStorageHelper::removeOldFile($model, 'picture');
|
||||
});
|
||||
static::deleted(function (self $model) {
|
||||
FileStorageHelper::removeFile($model, 'picture');
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,13 +2,30 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
/**
|
||||
* @property string $first_name Firstname.
|
||||
* @property string $last_name Lastname.
|
||||
* @property string $email Email.
|
||||
* @property string $password Password.
|
||||
* @property \App\Enums\Users\RoleEnum $role Role.
|
||||
* @property \Illuminate\Support\Carbon $published Published status.
|
||||
* @property \Illuminate\Support\Carbon $published_at Publication status update date.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
use Notifiable;
|
||||
|
||||
|
|
@ -18,10 +35,13 @@ class User extends Authenticatable
|
|||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'firstname',
|
||||
'lastname',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'password',
|
||||
'role',
|
||||
'published',
|
||||
'published_at',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -40,7 +60,10 @@ class User extends Authenticatable
|
|||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'role' => RoleEnum::class,
|
||||
'email_verified_at' => 'datetime',
|
||||
'published' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -48,18 +71,45 @@ class User extends Authenticatable
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted()
|
||||
protected static function booted(): void
|
||||
{
|
||||
// * EVENT CLOSURES.
|
||||
static::creating(function (self $model) {
|
||||
if (Hash::needsRehash($model->password)) {
|
||||
$model->password = Hash::make($model->password);
|
||||
}
|
||||
self::updatePassword($model);
|
||||
// * Prevent user elevation privileges
|
||||
throw_if(
|
||||
auth('backend')->user() and auth('backend')->user()->role->value() > $model->role->value(),
|
||||
AuthorizationException::class
|
||||
);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
if (Hash::needsRehash($model->password)) {
|
||||
$model->password = Hash::make($model->password);
|
||||
self::updatePassword($model);
|
||||
if (optional(auth('backend')->user())->getKey() === $model->getKey()) {
|
||||
\validator(
|
||||
['published' => $model->published],
|
||||
['published' => 'required|boolean|accepted'],
|
||||
['published.accepted' => trans('crud.messages.user_unpublished')],
|
||||
)->validate();
|
||||
}
|
||||
// * Prevent user elevation privileges
|
||||
throw_if(
|
||||
auth('backend')->user() and auth('backend')->user()->role->value() > $model->role->value(),
|
||||
AuthorizationException::class
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Update password.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function updatePassword(self $model): void
|
||||
{
|
||||
if (Hash::needsRehash($model->password)) {
|
||||
$model->password = Hash::make($model->password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
54
app/Observers/ModelObserver.php
Normal file
54
app/Observers/ModelObserver.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Enums\ActivityLogs\ActivityLogsEventEnum;
|
||||
use App\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ModelObserver
|
||||
{
|
||||
/**
|
||||
* Handle the model "created" event.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
public static function created(Model $model): void
|
||||
{
|
||||
ActivityLog::addActivity($model, ActivityLogsEventEnum::created);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the model "updated" event.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
public static function updated(Model $model): void
|
||||
{
|
||||
ActivityLog::addActivity($model, ActivityLogsEventEnum::updated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the model "duplicated" event.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
public static function duplicated(Model $model): void
|
||||
{
|
||||
ActivityLog::addActivity($model, ActivityLogsEventEnum::duplicated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the model "deleted" event.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
public static function deleted(Model $model): void
|
||||
{
|
||||
ActivityLog::addActivity($model, ActivityLogsEventEnum::deleted);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue