Completed
Push — master ( f96952...73a571 )
by Pavel
03:59 queued 11s
created

ImageColumn::getNoImageMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Pfilsx\DataGrid\Grid\Columns;
5
6
7
use Twig\Template;
8
9
class ImageColumn extends DataColumn
10
{
11
12
    protected $width = 25;
13
14
    protected $height = 25;
15
16
    protected $format = 'html';
17
18
    protected $alt;
19
20
    protected $emptyValue = '-';
21
22
    public function getCellContent($entity)
23
    {
24
        $value = (string)$this->getCellValue($entity);
25
        if (!empty($value)) {
26
            if ($this->format === 'html') {
27
                return $this->template->renderBlock('grid_img', [
28
                    'src' => $value,
29
                    'width' => $this->width,
30
                    'height' => $this->height,
31
                    'alt' => $this->getAlt($entity)
32
                ]);
33
            }
34
            return htmlspecialchars($value);
35
        } else {
36
            return $this->emptyValue;
37
        }
38
    }
39
40
    /**
41
     * @return int
42
     */
43
    public function getWidth(): int
44
    {
45
        return $this->width;
46
    }
47
48
    /**
49
     * @param int $width
50
     */
51
    protected function setWidth(int $width): void
52
    {
53
        $this->width = $width;
54
    }
55
56
    /**
57
     * @return int
58
     */
59
    public function getHeight(): int
60
    {
61
        return $this->height;
62
    }
63
64
    /**
65
     * @param int $height
66
     */
67
    protected function setHeight(int $height): void
68
    {
69
        $this->height = $height;
70
    }
71
72
    /**
73
     * @param $entity
74
     * @return string
75
     */
76
    public function getAlt($entity): string
77
    {
78
        return is_callable($this->alt)
79
            ? htmlspecialchars(call_user_func_array($this->alt, [$entity]))
80
            : '';
81
    }
82
83
    /**
84
     * @param callable $alt
85
     */
86
    protected function setAlt(callable $alt): void
87
    {
88
        $this->alt = $alt;
89
    }
90
}
91