1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\ManageBlock;
13
14 use ICanBoogie\I18n;
15
16 use Brickrouge\Element;
17
18 19 20 21 22
23 class FilterDecorator
24 {
25 private $record;
26 private $property;
27 private $filtering;
28 private $label;
29 private $value;
30
31 32 33 34 35 36 37 38 39 40 41
42 public function __construct($record, $property, $filtering, $label=null, $value=null)
43 {
44 $this->record = $record;
45 $this->property = $property;
46 $this->filtering = $filtering;
47 $this->label = $label;
48 $this->value = $value;
49 }
50
51 public function render()
52 {
53 $property = $this->property;
54 $value = $this->value;
55 $label = $this->label;
56
57 if ($value === null)
58 {
59 $value = $this->record->$property;
60 }
61
62 if ($label === null)
63 {
64 $label = \ICanBoogie\escape($value);
65 }
66
67 if ($this->filtering)
68 {
69 return $label;
70 }
71
72 $title = \ICanBoogie\escape(I18n\t('Display only: :identifier', array(':identifier' => strip_tags($label))));
73 $url = \ICanBoogie\escape($property . '=') . urlencode($value);
74
75 return <<<EOT
76 <a class="filter" href="?$url" title="$title">$label</a>
77 EOT;
78 }
79
80 public function __toString()
81 {
82 try
83 {
84 return $this->render();
85 }
86 catch (\Exception $e)
87 {
88 return \Brickrouge\render_exception($e);
89 }
90 }
91 }