- Remove external JS and CSS dependencies - Use Vuejs runtime - Add xss sanitizer - Normalize Laravel mix + add cleaner - Update npm deps - Upgrade bootswatch theme
146 lines
5.1 KiB
PHP
146 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Lib;
|
|
|
|
use App\Enums\LoadLevel;
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
class Utils
|
|
{
|
|
/**
|
|
* Compute plain text to html representation.
|
|
*
|
|
* @param string $text
|
|
* @return string
|
|
*/
|
|
public static function plainToHtml(string $text): string
|
|
{
|
|
$text = e($text);
|
|
// * url replace and email replace
|
|
$text = preg_replace_callback(
|
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'/(?P<email>[^\s@]+@([^\s@.,]+\.)+[^\s@.,]{2,})|(?P<user>@\w*)|(?P<url>(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*))/',
|
|
function ($matches) {
|
|
$match = collect($matches)->first() ?? '';
|
|
if (filter_var($match, FILTER_VALIDATE_EMAIL)) {
|
|
return strlen($match) ? "<a href=\"mailto:$match\">$match</a>" : $match;
|
|
} elseif (isset($matches['user']) and strlen($matches['user'])) {
|
|
return sprintf(
|
|
'<span class="text-primary fw-bold font-weight-bold">%s</span>',
|
|
$matches['user']
|
|
);
|
|
} else {
|
|
$url = $match;
|
|
if (\strpos($url, 'http') === false and \strpos($url, 'https') === false) {
|
|
$url = sprintf(
|
|
'%s://%s',
|
|
config('app.env') !== 'local' ? 'https' : 'http',
|
|
$url
|
|
);
|
|
}
|
|
$fsligthbox = self::isImageFile($url) ? 'data-fslightbox="gallery"' : '';
|
|
return strlen($match) ? "<a $fsligthbox href=\"$url\" target=\"_blank\">$match</a>" : $match;
|
|
}
|
|
},
|
|
$text
|
|
);
|
|
return nl2br($text);
|
|
}
|
|
|
|
/**
|
|
* Check uri points to image file
|
|
*
|
|
* @param string $url
|
|
* @return boolean
|
|
*/
|
|
public static function isImageFile(string $url): bool
|
|
{
|
|
$m = [];
|
|
return \preg_match('/(\.png|\.jpg|\.jpeg|\.gif)$/', $url, $m) === 1;
|
|
}
|
|
|
|
/**
|
|
* delais 7 jours 168h
|
|
* travaillé 5 jours 37h
|
|
* temps tickets 1 jours 7.4h
|
|
*
|
|
* personnes 4 (TpP) 3.7h / semaine * prs
|
|
*
|
|
* délais moyen ticket (Dmt) 0.75h
|
|
*
|
|
* délais max attente pour 1 ticket (Dam) 7jours
|
|
*
|
|
* niveaux de charge 4: - faible
|
|
* - stable
|
|
* - élevée
|
|
* - saturation
|
|
*
|
|
* états tickets(Et) : - nouveaux (non traités)
|
|
* - en attente (charge pendante)
|
|
* - traités
|
|
*
|
|
* Algo : linéaire
|
|
*
|
|
* TpP : 3.7h
|
|
* P : 4
|
|
*
|
|
* Et(nvx) * Dam
|
|
*
|
|
* Nv Charge = (P * TpP) / (Et(nvx) * Dam) - (P * TpP) / (Et(nvx) * DmT) - (Et(att) * DmT)
|
|
*
|
|
*
|
|
* Si nv Charge < 0 => saturation
|
|
*
|
|
* @return \App\Enums\LoadLevel
|
|
*/
|
|
public static function computeWorkload(): LoadLevel
|
|
{
|
|
$Tnew = View::shared('ticketsNew');
|
|
$Tprogress = View::shared('ticketsInProgress');
|
|
$Twaiting = View::shared('ticketsWaiting');
|
|
|
|
$worked = config('tickets.workedHoursInAWeek');
|
|
$workedDays = config('tickets.workedDaysInAWeek');
|
|
// * in hours
|
|
$morningWorkTime = ($worked / $workedDays / 2);
|
|
// * Devs handlings tickets per week
|
|
$workingDevsPerWeek = config('tickets.workingDevsPerWeek');
|
|
// * Worktime per week to handle tickets
|
|
$timePerWeekDev = $workingDevsPerWeek * $morningWorkTime;
|
|
// * 45min for a ticket
|
|
$avgTimeForTicket = config('tickets.avgTimeForTicket');
|
|
// * The time needed to handle new ticket (average)
|
|
$todoListDelay = $Tnew * $avgTimeForTicket;
|
|
// * The time needed to handle new ticket (average)
|
|
$waitingListDelay = $Twaiting * $avgTimeForTicket;
|
|
// * The time needed to handle new ticket (average)
|
|
$progressListDelay = $Tprogress * $avgTimeForTicket;
|
|
$totalTicketsDelay = $todoListDelay + $progressListDelay + $waitingListDelay;
|
|
// * in weeks
|
|
$ETAForAnewTicket = $totalTicketsDelay / $timePerWeekDev;
|
|
switch ((int)round($ETAForAnewTicket)) {
|
|
case LoadLevel::weak()->value:
|
|
case LoadLevel::stable()->value:
|
|
case LoadLevel::high()->value:
|
|
return LoadLevel::make((int)round($ETAForAnewTicket));
|
|
default:
|
|
return LoadLevel::overload();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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..)
|
|
*
|
|
* @param string $input
|
|
* @return string
|
|
*/
|
|
public static function stripCkEditorSchemesOnMediaInputs(string $input): string
|
|
{
|
|
$input = \preg_replace('/(?<=<oembed url=")(https:\/\/)(?=.*?">)/m', '', $input);
|
|
return $input;
|
|
}
|
|
}
|