helpers.php ➔ formatDateTimeLong()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Arquivo de funções
5
 *
6
 * @license MIT
7
 * @package NwLaravel
8
 */
9
10
use \Carbon\Carbon;
11
use \Illuminate\Database\Eloquent\Model;
12
use \Illuminate\Support\Facades\DB;
13
14
if (! function_exists('arrayFilterClean')) {
15
16
    function arrayFilterClean(array $input)
17
    {
18
        return array_filter($input, function ($value) {
19 1
            return (!empty($value) || $value == "0");
20 1
        });
21
    }
22
}
23
24
if (! function_exists('asCurrency')) {
25
    /**
26
     * Return a timestamp as DateTime object.
27
     *
28
     * @param mixed $value Mixed Value
29
     *
30
     * @return Carbon
31
     */
32
    function asCurrency($value)
33
    {
34
        // Numeric Pt
35 41
        $matchPt = (bool) preg_match('/^[0-9]{1,3}(\.[0-9]{3})*(\,[0-9]+)?$/', $value);
36 41
        $matchNumericPt = (bool) preg_match('/^[0-9]+(\,[0-9]+)$/', $value);
37 41
        if ($matchPt || $matchNumericPt) {
38 15
            $value = str_replace('.', '', $value);
39 15
            $value = str_replace(',', '.', $value);
40 15
        }
41
42 41
        $matchEn = (bool) preg_match('/^[0-9]{1,3}(,[0-9]{3})*(\.[0-9]+)?$/', $value);
43 41
        if ($matchEn) {
44 17
            $value = str_replace(',', '', $value);
45 17
        }
46
47 41
        $matchNumeric = (bool) preg_match('/^[0-9]+(\.[0-9]+)?$/', $value);
48 41
        if ($matchNumeric) {
49 27
            return doubleval($value);
50
        }
51
52 15
        return null;
53
    }
54
}
55
56
if (! function_exists('asDateTime')) {
57
    /**
58
     * Return a timestamp as DateTime object.
59
     *
60
     * @param mixed $value Mixed Value
61
     *
62
     * @return Carbon
63
     */
64
    function asDateTime($value)
65
    {
66 17
        if (empty($value)) {
67 2
            return null;
68
        }
69
70 16
        if ($value instanceof DateTime) {
71 5
            return Carbon::instance($value);
72
        }
73
74 12
        if (is_numeric($value)) {
75 1
            return Carbon::createFromTimestamp($value);
76
        }
77
78 12
        if (is_string($value) && preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $value)) {
79 3
            return Carbon::createFromFormat('Y-m-d', $value)->startOfDay();
80
        }
81
82 10
        if (is_string($value)) {
83 8
            $formatDB = 'Y-m-d H:i:s';
84 8
            $dateFormat = config('nwlaravel.date_format');
85 8
            $formats = array_merge([$formatDB, $dateFormat], explode(" ", $dateFormat));
86 8
            foreach ($formats as $format) {
87 8
                $date = date_parse_from_format($format, $value);
88 8
                if ($date['error_count'] == 0 && $date['warning_count'] == 0) {
89 8
                    $value = Carbon::createFromFormat($format, $value);
90 8
                    if ($date['hour'] === false) {
91 7
                        $value->startOfDay();
92 7
                    }
93 8
                    return $value;
94
                }
95 7
            }
96
97 3
            if (strtotime($value) !== false) {
98 1
                return (new Carbon($value));
99
            }
100 3
        }
101
102 5
        return null;
103
    }
104
}
105
106
if (! function_exists('fromDateTime')) {
107
    /**
108
     * Convert a DateTime to a storable string.
109
     *
110
     * @param mixed $value Mixed Value
111
     *
112
     * @return string
113
     */
114
    function fromDateTime($value)
115
    {
116 2
        $formatDB = 'Y-m-d H:i:s';
117
118 2
        if (is_numeric($value)) {
119 1
            $value = Carbon::createFromTimestamp($value);
120
121 2
        } elseif (is_string($value) && preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $value)) {
122 1
            $value = Carbon::createFromFormat('Y-m-d', $value)->startOfDay();
123
124 2
        } elseif (is_string($value)) {
125 2
            $dateFormat = config('nwlaravel.date_format');
126 2
            $formats = array_merge([$dateFormat], explode(" ", $dateFormat));
127 2
            $formats[] = $formatDB;
128 2
            foreach ($formats as $format) {
129 2
                $date = date_parse_from_format($format, $value);
130 2
                if ($date['error_count'] == 0 && $date['warning_count'] == 0) {
131 2
                    $value = Carbon::createFromFormat($format, $value);
132 2
                    if ($date['hour'] === false) {
133 2
                        $value->startOfDay();
134 2
                    }
135 2
                    break;
136
                }
137 2
            }
138
139 2
            if (strtotime($value) !== false) {
140 2
                $value = new Carbon($value);
141 2
            }
142 2
        }
143
144 2
        if ($value instanceof DateTime) {
145 2
            return $value->format($formatDB);
146
        }
147
148 2
        return null;
149
    }
150
}
151
152
if (! function_exists('toFixed')) {
153
    /**
154
     * To Fixed
155
     *
156
     * @param int $number  Integer Number
157
     * @param int $decimal Float Decimal
158
     *
159
     * @return float
160
     */
161
    function toFixed($number, $decimal = 0)
162
    {
163 21
        $number = strval($number);
164 21
        $pos = strpos($number.'', ".");
165
166 21
        if ($pos > 0) {
167 13
            $int_str = substr($number, 0, $pos);
168 13
            $dec_str = substr($number, $pos+1);
169 13
            if (strlen($dec_str)>$decimal) {
170 11
                return floatval($int_str.($decimal>0?'.':'').substr($dec_str, 0, $decimal));
171
            } else {
172 3
                return floatval($number);
173
            }
174
        } else {
175 9
            return floatval($number);
176
        }
177
    }
178
}
179
180
if (! function_exists('numberHumans')) {
181
    /**
182
     * Number Humans
183
     *
184
     * @param float $number Number
185
     *
186
     * @return string
187
     */
188
    function numberHumans($number)
189
    {
190 1
        $sufix = '';
191 1
        if ($number >= 1000) {
192 1
            $number = $number / 1000;
193 1
            $sufix = 'K';
194 1
        }
195
196 1
        if ($number >= 1000) {
197 1
            $number = $number / 1000;
198 1
            $sufix = 'M';
199 1
        }
200
201 1
        if ($number >= 1000) {
202 1
            $number = $number / 1000;
203 1
            $sufix = 'B';
204 1
        }
205
206 1
        if ($number >= 1000) {
207 1
            $number = $number / 1000;
208 1
            $sufix = 'T';
209 1
        }
210
211 1
        return toFixed($number, 1).$sufix;
212
    }
213
}
214
215
if (! function_exists('storageFormat')) {
216
    /**
217
     * Storage Format
218
     *
219
     * @param float  $storage Integer Storage
220
     * @param string $nivel   Nivel Storage
221
     *
222
     * @return string
223
     */
224
    function storageFormat($storage, $nivel = null)
225
    {
226 22
        $storage = trim($storage);
227 22
        if (!is_numeric($storage)) {
228 2
            return $storage;
229
        }
230
231 20
        $sizes = ['KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4, 'PB' => 5];
232
233 20
        if (!is_null($nivel) && array_key_exists(strtoupper($nivel), $sizes)) {
234 5
            if ($storage < 1000) {
235 5
                return toFixed($storage, 1) . strtoupper($nivel);
236 5
            }
237 5
238 5
            for ($i = 0; $i < $sizes[strtoupper($nivel)]; $i++) {
239 5
                $storage = $storage * 1024;
240
            }
241 20
        }
242 20
243 20
        $sufix = 'B';
244 18
        foreach (array_keys($sizes) as $size) {
245 18
            if ($storage >= 1000) {
246 18
                $storage = $storage / 1000;
247 20
                $sufix = $size;
248
            }
249 20
        }
250
251
        return toFixed($storage, 1) . $sufix;
252
    }
253
}
254
255
if (! function_exists('dateFormatter')) {
256
    /**
257
     * Date Formatter
258
     *
259
     * @param DateTime $date     Date Time
260
     * @param string   $dateType String Date Type
261
     * @param string   $timeType String Time Type
262
     * @param string   $pattern  String Pattern
263
     *
264
     * @return string
265
     */
266 2
    function dateFormatter($date, $dateType, $timeType, $pattern = "")
267 2
    {
268 2
        if ($date instanceof \DateTime) {
269 2
            $fmt = new \IntlDateFormatter(
270 2
                config('app.locale'),
271 2
                $dateType,
272 2
                \IntlDateFormatter::NONE,
273
                config('app.timezone'),
274 2
                \IntlDateFormatter::GREGORIAN,
275
                $pattern
276 2
            );
277 1
278 1
            if (empty($pattern) && $dateType == \IntlDateFormatter::SHORT) {
279
                $fmt->setPattern(preg_replace("/y+/", "yyyy", $fmt->getPattern()));
280 2
            }
281
282 2
            $strTime = '';
283 1
            switch ($timeType) {
284 1
                case \IntlDateFormatter::SHORT:
285 2
                    $strTime = $date->format('H:i');
286 1
                    break;
287 1
                case \IntlDateFormatter::MEDIUM:
288
                    $strTime = $date->format('H:i:s');
289
                    break;
290 2
            }
291 2
292 2
            $newDate = clone $date;
293
            $newDate->setTime(0, 0);
294 2
            $strDate = ($dateType != \IntlDateFormatter::NONE) ? $fmt->format($newDate) : '';
295
296
            return trim(sprintf('%s %s', $strDate, $strTime));
297 1
        }
298
299
        return $date;
300
    }
301
}
302
303
if (! function_exists('formatPattern')) {
304
    /**
305
     * Format Pattern
306
     *
307
     * @param DateTime $date     Date Time
308
     * @param string   $pattern  String Pattern
309
     *
310
     * @return string
311
     */
312
    function formatPattern($date, $pattern)
313
    {
314
        if ($date instanceof \DateTime) {
315
            $fmt = new \IntlDateFormatter(
316
                config('app.locale'),
317
                IntlDateFormatter::NONE,
318
                IntlDateFormatter::NONE,
319
                config('app.timezone'),
320
                \IntlDateFormatter::GREGORIAN,
321
                $pattern
322
            );
323
324
            return $fmt->format($date);
325
        }
326
327
        return "";
328
    }
329
}
330
331
if (! function_exists('nameWeek')) {
332
    /**
333
     * Return Name Week
334
     *
335
     * @param DateTime $date Date Time
336
     *
337
     * @return string
338
     * @example : Domingo
339
     */
340
    function nameWeek($date)
341
    {
342
        return formatPattern($date, "EEEE");
343
    }
344
}
345
346
if (! function_exists('formatDateTime')) {
347
    /**
348
     * Format Date Time
349
     *
350
     * @param DateTime $date Date Time
351
     *
352
     * @return string
353
     * @example : DD/MM/YYYY HH:MIN:SS
354
     */
355 1
    function formatDateTime($date)
356
    {
357
        return dateFormatter($date, \IntlDateFormatter::SHORT, \IntlDateFormatter::MEDIUM);
358
    }
359
}
360
361
if (! function_exists('formatTimeShort')) {
362
    /**
363
     * Format Time Short
364
     *
365
     * @param DateTime $date Date Time
366
     *
367
     * @return string
368
     * @example : HH:MIN
369
     */
370 1
    function formatTimeShort($date)
371
    {
372
        return dateFormatter($date, \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT);
373
    }
374
}
375
376
if (! function_exists('formatDate')) {
377
    /**
378
     * Format Date
379
     *
380
     * @param DateTime $date Date Time
381
     *
382
     * @return string
383
     * @example : DD/MM/YYYY
384
     */
385 1
    function formatDate($date)
386
    {
387
        return dateFormatter($date, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
388
    }
389
}
390
391
if (! function_exists('formatTime')) {
392
    /**
393
     * Format Time
394
     *
395
     * @param DateTime $date Date Time
396
     *
397
     * @return string
398
     * @example : HH:MIN:SS
399
     */
400 1
    function formatTime($date)
401
    {
402
        return dateFormatter($date, \IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM);
403
    }
404
}
405
406
if (! function_exists('formatDateLong')) {
407
    /**
408
     * Format Date Long
409
     *
410
     * @param DateTime $date Date Time
411
     *
412
     * @return string
413
     * @example : [DIA] de [MES] de [ANO]
414
     */
415 1
    function formatDateLong($date)
416
    {
417
        return dateFormatter($date, \IntlDateFormatter::LONG, \IntlDateFormatter::NONE);
418
    }
419
}
420
421
if (! function_exists('formatDateTimeLong')) {
422
    /**
423
     * Format Date Time Long
424
     *
425
     * @param DateTime $date Date Time
426
     *
427
     * @return string
428
     * @example : [DIA] de [MES] de [ANO] - HH:MIN:SS
429
     */
430 1
    function formatDateTimeLong($date)
431 1
    {
432 1
        if ($date instanceof \DateTime) {
433
            $date = sprintf('%s - %s', formatDateLong($date), formatTime($date));
434 1
        }
435
436
        return $date;
437
    }
438
}
439
440
if (! function_exists('formatDateFull')) {
441
    /**
442
     * Format Date Full
443
     *
444
     * @param DateTime $date Date Time
445
     *
446
     * @return string
447
     * @example : [SEMANA], [DIA] de [MES] de [ANO]
448
     */
449 1
    function formatDateFull($date)
450
    {
451
        return dateFormatter($date, \IntlDateFormatter::FULL, \IntlDateFormatter::NONE);
452
    }
453
}
454
455
if (! function_exists('formatDateTimeFull')) {
456
    /**
457
     * Format Date Time Full
458
     *
459
     * @param DateTime $date Date Time
460
     *
461
     * @return string
462
     * @example : [SEMANA], [DIA] de [MES] de [ANO] - HH:MIN:SS
463
     */
464 1
    function formatDateTimeFull($date)
465 1
    {
466 1
        if ($date instanceof \DateTime) {
467 1
            return sprintf(
468 1
                '%s - %s',
469 1
                dateFormatter($date, \IntlDateFormatter::FULL, \IntlDateFormatter::NONE),
470
                dateFormatter($date, \IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM)
471
            );
472 1
        }
473
474
        return $date;
475
    }
476
}
477
478
if (! function_exists('formatDateTimeShort')) {
479
    /**
480
     * Format Date Time Short
481
     *
482
     * @param DateTime $date Date Time
483
     *
484
     * @return string
485
     * @example : DD/MM/YYYY HH:MIN
486
     */
487 1
    function formatDateTimeShort($date)
488
    {
489
        return dateFormatter($date, \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT);
490
    }
491
}
492
493
if (! function_exists('currencySymbol')) {
494
    /**
495
     * Return Currency Symbol
496
     *
497
     * @return string
498
     */
499 1
    function currencySymbol()
500 1
    {
501
        $fmt = new \NumberFormatter(config('app.locale'), \NumberFormatter::CURRENCY);
502
        return $fmt->getSymbol(\NumberFormatter::CURRENCY_SYMBOL);
503
    }
504
}
505
506
if (! function_exists('diffForHumans')) {
507
    /**
508
     * Diff date for Humans
509
     *
510
     * @param string|DataTime $date     String\DateTime Date
511
     * @param string|DataTime $other    String\DateTime Other
512
     * @param boolean         $absolute Boolean Absolute
513
     *
514
     * @return string
515
     * @example : 7 minutos atras
516
     */
517 1
    function diffForHumans($date, $other = null, $absolute = false)
518 1
    {
519 1
        if ($date instanceof \DateTime) {
520 1
            $date = Carbon::instance($date);
521 1
            if (!$other instanceof Carbon) {
522 1
                $other = null;
523
            }
524
            return $date->diffForHumans($other, $absolute);
0 ignored issues
show
Documentation introduced by
$absolute is of type boolean, but the function expects a integer|array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
525 1
        }
526
527
        return '';
528
    }
529
}
530
531
if (! function_exists('now')) {
532
    /**
533
     * Now Date Time
534
     *
535
     * @return Carbon
536
     */
537 2
    function now()
538
    {
539
        return Carbon::now();
540
    }
541
}
542
543
if (! function_exists('formatCurrency')) {
544
    /**
545
     * Formato moeda conforme locale
546
     *
547
     * @param float $valor Float Valor
548
     *
549
     * @return string
550
     * @example : formatCurrency(8712.335) = R$8.712,34
551
     */
552
    function formatCurrency($valor)
553
    {
554
        $fmt = new \NumberFormatter(config('app.locale'), \NumberFormatter::CURRENCY);
555
        return $fmt->format(floatval($valor));
556
    }
557
}
558
559
if (! function_exists('formatNumber')) {
560
    /**
561
     * Formato numero conforme locale
562
     *
563
     * @param float $valor
564
     * @param int   $decimal
565
     *
566
     * @return string
567
     * @example : formatNumber(8712.335) = 8.712,34
568
     */
569 1
    function formatNumber($valor, $decimal = 2)
570 1
    {
571
        $valor   = floatval($valor);
572 1
        $decimal = intval($decimal);
573
574 1
        $pattern = sprintf('#,##0.%s', str_pad('', $decimal, '0'));
575 1
576 1
        $fmt = new \NumberFormatter(config('app.locale'), \NumberFormatter::DECIMAL);
577
        $fmt->setPattern($pattern);
578
        return $fmt->format($valor);
579
    }
580
}
581
582
if (! function_exists('maskCep')) {
583
    /**
584
     * Cria a mascara do cep
585
     *
586
     * @param string $value
587
     *
588
     * @return string
589
     * @example : maskCep(12345678) = 12345-678
590
     */
591 1
    function maskCep($value)
592 1
    {
593 1
        $capture = '/^([0-9]{5})([0-9]{3})$/';
594 1
        $format = '$1-$2';
595 1
        $value = preg_replace('[^0-9]', '', $value);
596 1
        $result = preg_replace($capture, $format, $value);
597 1
        if (!is_null($result)) {
598 1
            $value = $result;
599
        }
600
        return $value;
601
    }
602
}
603
604
if (! function_exists('maskCpf')) {
605
    /**
606
     * Cria a mascara do cpf
607
     *
608
     * @param string $value
609
     *
610
     * @return string
611
     * @example : maskCpf(12345678901) = 123.456.789-01
612
     */
613 2
    function maskCpf($value)
614 2
    {
615 2
        $capture = '/^([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{2})$/';
616 2
        $format = '$1.$2.$3-$4';
617 2
        $value = preg_replace('[^0-9]', '', $value);
618 2
        $result = preg_replace($capture, $format, $value);
619 2
        if (!is_null($result)) {
620 2
            $value = $result;
621
        }
622
        return $value;
623
    }
624
}
625
626
if (! function_exists('maskCnpj')) {
627
    /**
628
     * Cria a mascara do cnpj
629
     *
630
     * @param string $value
631
     *
632
     * @return string
633
     * @example : maskCpf(00123456/0001-78) = 00.123.456/0001-78
634
     */
635 2
    function maskCnpj($value)
636 2
    {
637 2
        $capture = '/^([0-9]{2,3})([0-9]{3})([0-9]{3})([0-9]{4})([0-9]{2})$/';
638 2
        $format = '$1.$2.$3/$4-$5';
639 2
        $value = preg_replace('[^0-9]', '', $value);
640 2
        $result = preg_replace($capture, $format, $value);
641 2
        if (!is_null($result)) {
642 2
            $value = $result;
643
        }
644
        return $value;
645
    }
646
}
647
648
if (! function_exists('maskCpfOrCnpj')) {
649
    /**
650
     * Cria a mascara do cpf ou cnpj
651
     *
652
     * @param string $value
653
     *
654
     * @return string
655
     */
656 1
    function maskCpfOrCnpj($value)
657 1
    {
658 1
        $value = preg_replace('[^0-9]', '', $value);
659
        if (strlen($value)==11) {
660 1
            return maskCpf($value);
661
        } else {
662
            return maskCnpj($value);
663
        }
664
    }
665
}
666
667
if (! function_exists('numberRoman')) {
668
    /**
669
     * Number integer to Roman
670
     *
671
     * @param integer $integer
672
     *
673
     * @return string
674
     */
675
    function numberRoman($integer)
676 1
    {
677 1
        $table = array(
678 1
            'M'  =>1000,
679 1
            'CM' =>900,
680 1
            'D'  =>500,
681 1
            'CD' =>400,
682 1
            'C'  =>100,
683 1
            'XC' =>90,
684 1
            'L'  =>50,
685 1
            'XL' =>40,
686 1
            'X'  =>10,
687 1
            'IX' =>9,
688
            'V'  =>5,
689 1
            'IV' =>4,
690
            'I'  =>1
691 1
        );
692 1
693
        if ($integer < 1 || $integer > 3999) {
694
            return $integer;
695 1
        }
696 1
697 1
        $return = '';
698 1
        while ($integer > 0) {
699 1
            foreach ($table as $rom => $arb) {
700 1
                if ($integer >= $arb) {
701 1
                    $integer -= $arb;
702
                    $return .= $rom;
703 1
                    break;
704 1
                }
705
            }
706 1
        }
707
708
        return $return;
709
    }
710
}
711
712
if (! function_exists('numberLetra')) {
713
    /**
714
     * Number to Letra
715
     *
716
     * @param integer    $number
717
     * @param array|null $letras
718
     * @param integer    $nivel
719
     *
720
     * @return string
721
     */
722 1
    function numberLetra($number, array $letras = null, $nivel = -1)
723 1
    {
724 1
        $number = trim($number);
725
        if (preg_match('/[^0-9]/', $number)) {
726
            return $number;
727 1
        }
728
729
        $num = intval($number);
730 1
731 1
        $letrasOrig = array(
732 1
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
733
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
734 1
        );
735 1
736 1
        if (is_null($letras)) {
737
            $letras = $letrasOrig;
738 1
        }
739 1
740 1
        $nivel++;
741 1
        if ($num > count($letras) && array_key_exists($nivel, $letras)) {
742 1
            $letraParent = $letras[$nivel];
743 1
            foreach ($letrasOrig as $value) {
744
                $letras[] = $letraParent.$value;
745 1
            }
746
747
            return numberLetra($num, $letras, $nivel);
748 1
        }
749 1
750 1
        $index = $num-1;
751 1
        if (array_key_exists($index, $letras)) {
752 1
            $return = $letras[$index];
753
        } else {
754
            $return = $number;
755 1
        }
756
757
        return $return;
758
    }
759
}
760
761
if (! function_exists('activePattern')) {
762
    /**
763
     * Return class $active, para url pattern,
764
     * caso contrario $inactive
765
     *
766
     * @param string $path     String Path
767
     * @param string $active   String Active
768
     * @param string $inactive String Inactive
769
     *
770
     * @return string
771
     */
772 1
    function activePattern($path, $active = 'active', $inactive = '')
773 1
    {
774
        $method = '\Illuminate\Support\Facades\Request::is';
775
        return call_user_func_array($method, (array) $path) ? $active : $inactive;
776
    }
777
}
778
779
if (! function_exists('activeRoute')) {
780
    /**
781
     * Return class $active, para route currentRoute
782
     * caso contrario $inactive
783
     *
784
     * @param string $route    String Route
785
     * @param string $active   String Active
786
     * @param string $inactive String Inactive
787
     *
788
     * @return string
789
     */
790 4
    function activeRoute($route, $active = 'active', $inactive = '')
791 4
    {
792
        $method = '\Illuminate\Support\Facades\Route::currentRouteName';
793
        return call_user_func_array($method, [])==$route ? $active : $inactive;
794
    }
795
}
796
797
if (! function_exists('linkRoute')) {
798
    /**
799
     * Cria o link com currentRoute
800
     *
801
     * @param string $route String Route
802
     * @param string $label String Label
803
     * @param string $class String Class
804
     *
805
     * @return string
806
     */
807 3
    function linkRoute($route, $label, $class = '')
808
    {
809
        return sprintf('<a href="%s" class="%s">%s</a>', route($route), $class?:activeRoute($route), $label);
810
    }
811
}
812
813
if (! function_exists('activity')) {
814
    /**
815
     * Log activity
816
     *
817
     * @param string    $action
818
     * @param string    $description
819
     * @param \Eloquent $model
820
     *
821
     * @return bool
822
     */
823 1
    function activity($action, $description, $model = null)
824
    {
825
        return app('nwlaravel.activity')->log($action, $description, $model);
826
    }
827
}
828