89 lines
3.3 KiB
PHP
89 lines
3.3 KiB
PHP
<?php
|
||
|
||
namespace OCA\Gestion\Helpers;
|
||
|
||
class FileExportHelpers
|
||
{
|
||
|
||
|
||
public static function FormatTextForExport(string $text){
|
||
$textFormatted = str_replace('‘', "'", $text);
|
||
$textFormatted = utf8_decode(html_entity_decode($textFormatted));
|
||
return $textFormatted;
|
||
}
|
||
|
||
public static function GetAddressAndCityFromAddress(string $adresse){
|
||
$adresseResult = "Aucun adresse";
|
||
$cityResult = "Aucune ville";
|
||
$adresses = explode("-",$adresse);
|
||
if(isset($adresses[0])){
|
||
$adresseResult = self::RemoveSpaceFromString($adresses[0]);
|
||
}
|
||
if(isset($adresses[1])){
|
||
$cityResult = self::RemoveSpaceFromString($adresses[1]);
|
||
}
|
||
return [
|
||
"address" => $adresseResult,
|
||
"city" => $cityResult
|
||
];
|
||
}
|
||
|
||
public static function GetSexeLabel(string $sexeKey){
|
||
return $sexeKey === 'f' ? 'Mme' : 'Mr';
|
||
}
|
||
|
||
public static function RemoveSpaceFromString(string $string){
|
||
$stringWithoutSpace = trim($string);
|
||
$stringWithoutSpace = str_replace(" ",'',$stringWithoutSpace);
|
||
return $stringWithoutSpace;
|
||
}
|
||
|
||
public static function ConvertSpecialChar($str) {
|
||
$unwanted_array = array(
|
||
'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
|
||
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
|
||
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
|
||
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
|
||
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y'
|
||
);
|
||
return strtr( $str, $unwanted_array );
|
||
}
|
||
|
||
public static function GetClientsFolder($clientName,$racinePath){
|
||
return $racinePath.'CLIENTS/'.mb_strtoupper($clientName,'UTF-8').'/';
|
||
}
|
||
|
||
public static function GetDefuntsFolder($clientName,$defuntName,$racinePath){
|
||
$clientsFolder = self::GetClientsFolder($clientName,$racinePath);
|
||
return $clientsFolder.'DEFUNTS/'.mb_strtoupper($defuntName,'UTF-8').'/';
|
||
}
|
||
|
||
public static function GetBijouxOfDefuntFolder($clientName,$defuntName,$racinePath){
|
||
$defuntFolder = self::GetDefuntsFolder($clientName,$defuntName,$racinePath);
|
||
return $defuntFolder.'BIJOUX/';
|
||
}
|
||
|
||
public static function GetPacemakerPhotoFolderOfDefunt($clientName,$defuntName,$racinePath){
|
||
$defuntFolder = self::GetDefuntsFolder($clientName,$defuntName,$racinePath);
|
||
return $defuntFolder.'PACEMAKER/';
|
||
}
|
||
|
||
public static function GetLineCountForATextInAMaxWidth($pdf,$text,$maxWidth){
|
||
$words = explode(' ', $text);
|
||
$lineWidth = 0;
|
||
$lineCount = 1;
|
||
|
||
foreach ($words as $word) {
|
||
$wordWidth = $pdf->GetStringWidth($word . ' ');
|
||
if ($lineWidth + $wordWidth > $maxWidth) {
|
||
$lineCount++;
|
||
$lineWidth = $wordWidth;
|
||
} else {
|
||
$lineWidth += $wordWidth;
|
||
}
|
||
}
|
||
return $lineCount;
|
||
}
|
||
|
||
}
|