1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\ManageBlock;
13
14 use ICanBoogie\ActiveRecord\Query;
15
16 use Brickrouge\Element;
17
18 19 20
21 class BooleanColumn extends Column
22 {
23 public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
24 {
25 parent::__construct
26 (
27 $manager, $id, $options + array
28 (
29 'title' => null,
30 'class' => 'cell-boolean',
31 'discreet' => false,
32 'filters' => array
33 (
34 'options' => array
35 (
36 '=1' => 'Yes',
37 '=0' => 'No'
38 )
39 ),
40
41 'orderable' => false,
42 'cell_renderer' => __NAMESPACE__ . '\BooleanCellRenderer'
43 )
44 );
45 }
46
47 public function add_assets(\Brickrouge\Document $document)
48 {
49 parent::add_assets($document);
50
51 $document->js->add('boolean.column.js');
52 }
53
54 public function alter_query_with_filter(Query $query, $filter_value)
55 {
56 return $query->and(array($this->id => $filter_value));
57 }
58 }
59
60 61 62
63 class BooleanCellRenderer extends CellRenderer
64 {
65 66 67 68 69
70 public function __invoke($record, $property)
71 {
72 return new Element
73 (
74 'label', array
75 (
76 Element::CHILDREN => array
77 (
78 new Element
79 (
80 Element::TYPE_CHECKBOX, array
81 (
82 'value' => $record->{ $this->column->manager->primary_key },
83 'checked' => ($record->$property != 0),
84 'data-property' => $property,
85 'data-property-type' => 'boolean'
86 )
87 )
88 ),
89
90 'class' => 'checkbox-wrapper circle'
91 )
92 );
93 }
94 }