Files
gutachten_t3/packages/gutachten/Classes/Utility/Helper.php
T

171 lines
4.4 KiB
PHP

<?php
namespace HermannTelser\Gutachten\Utility;
class Helper
{
/**
* cut string at char.
*
* @param mixed $string
* @param mixed $char
*/
public static function after($string, $char)
{
if (!\is_bool(strpos($char, $string))) {
return substr($char, strpos($char, $string) + \strlen($string));
}
}
public static function number_format_de($value, $char)
{
if (is_numeric($value)) {
return number_format($value, $char, ',', '.');
} else {
return $value;
}
}
public static function before($string, $char)
{
return substr($char, 0, strpos($char, $string));
}
public static function between($string, $that, $char)
{
return self::before($that, self::after($string, $char));
}
public static function replacePlatzhalter($_platzhalter, $string)
{
foreach ($_platzhalter as $key => $value) {
$string = str_replace($value['code'], $value['txt'], $string);
}
$string = html_entity_decode($string);
return $string;
}
public static function table_row_abschluss($_row)
{
$html = '<tr>';
foreach ($_row as $key => $value) {
$html .= '<th class="abschluss cell'.$key.'">'.$value.'</th>';
}
$html .= '</tr>';
return $html;
}
public static function table_row($_row, $border = 0)
{
$html = '<tr>';
foreach ($_row as $key => $value) {
if ($border) {
$html .= '<td class="cell'.$key.'" style="border-bottom: 0.1mm solid #cbcbcb;">'.$value.'</td>';
} else {
$html .= '<td class="cell'.$key.'">'.$value.'</td>';
}
}
$html .= '</tr>';
return $html;
}
public static function make_int($arr, $_fields)
{
foreach ($arr as $key => $value) {
foreach ($_fields as $k => $field) {
if (isset($value[$field])) {
$arr[$key][$field] = (int) $value[$field];
}
}
}
return $arr;
}
public static function make_double($arr, $_fields)
{
foreach ($arr as $key => $value) {
foreach ($_fields as $k => $field) {
if (isset($value[$field])) {
$arr[$key][$field] = (float) $value[$field];
}
}
}
return $arr;
}
public static function zero_to_null($arr, $_fields)
{
foreach ($arr as $key => $value) {
foreach ($_fields as $k => $field) {
if (isset($value[$field])) {
if ((float) $value[$field] == 0) {
$arr[$key][$field] = '';
} else {
$arr[$key][$field] = self::number_format_de($value[$field], 2);
}
}
}
}
return $arr;
}
public static function format_double($arr, $_fields, $stellen)
{
foreach ($arr as $key => $value) {
foreach ($_fields as $k => $field) {
if (isset($value[$field])) {
$arr[$key][$field] = self::number_format_de($value[$field], $stellen);
}
}
}
return $arr;
}
public static function table_header_row($_row)
{
$html = '<thead><tr>';
foreach ($_row as $key => $value) {
if ($value == 'space') {
$html .= '<td class="blank">&nbsp;</td>';
} else {
$html .= '<th class="cell'.$key.'">'.$value.'</th>';
}
}
$html .= '</tr></thead>';
return $html;
}
public static function table_header_row_r($_row)
{
$html = '<thead><tr text-rotate="90deg">';
foreach ($_row as $key => $value) {
$html .= '<td style="background-color: #ecf2f9; border-bottom: 0.1mm solid #cbcbcb;">'.$value.'</td>';
}
$html .= '</tr></thead>';
return $html;
}
public static function footer($projektname)
{
$html = '<table class="footer">
<tr>
<td width="40%">{DATE j-m-Y}</td>
<td width="20%" align="center">Seite {PAGENO}/{nbpg}</td>
<td width="40%" style="text-align: right;">' . $projektname . '</td>
</tr>
</table>';
return $html;
}
}