1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\ManageBlock;
13
14 use Brickrouge\Element;
15
16 17 18
19 class KeyColumn extends Column
20 {
21 private $ownership;
22
23 public function __construct($manager, $id, array $options=array())
24 {
25 parent::__construct
26 (
27 $manager, $id, array
28 (
29 'title' => null,
30 'class' => 'cell-key'
31 )
32 );
33 }
34
35 public function alter_records(array $records)
36 {
37 global $core;
38
39 $key = $this->id;
40 $module = $this->manager->module;
41 $user = $core->user;
42 $ownership = array();
43
44 foreach ($records as $record)
45 {
46 $ownership[$record->$key] = $user->has_ownership($module, $record);
47 }
48
49 $this->ownership = $ownership;
50
51 return parent::alter_records($records);
52 }
53
54 public function render_cell($record)
55 {
56 global $core;
57
58 $key = $record->{ $this->id };
59
60 return new Element
61 (
62 'label', array
63 (
64 Element::CHILDREN => array
65 (
66 new Element
67 (
68 Element::TYPE_CHECKBOX, array
69 (
70 'value' => $key,
71 'disabled' => !$this->ownership[$key]
72 )
73 )
74 ),
75
76 'class' => 'checkbox-wrapper rectangle',
77 'title' => $this->t('Toggle selection for the record #:key', array(':key' => $key))
78 )
79 );
80 }
81
82 83 84 85 86 87 88
89 public function ()
90 {
91 if (!count($this->ownership))
92 {
93 return ' ';
94 }
95
96 return new Element
97 (
98 'label', array
99 (
100 Element::CHILDREN => array
101 (
102 new Element
103 (
104 Element::TYPE_CHECKBOX
105 )
106 ),
107
108 'class' => 'checkbox-wrapper rectangle',
109 'title' => $this->t('Toggle selection for the records ([alt] to toggle selection)')
110 )
111 );
112 }
113
114 public function add_assets(\BrickRouge\Document $document)
115 {
116 $document->js->add('key.column.js');
117 $document->css->add('key.column.css');
118 }
119 }