1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Images;
13
14 class ManageBlock extends \Icybee\Modules\Files\ManageBlock
15 {
16 static protected function add_assets(\Brickrouge\Document $document)
17 {
18 parent::add_assets($document);
19
20 $document->js->add(DIR . 'public/slimbox.js');
21 $document->css->add(DIR . 'public/slimbox.css');
22 $document->js->add('manage.js');
23 }
24
25 public function __construct(Module $module, array $attributes)
26 {
27 parent::__construct
28 (
29 $module, $attributes + array
30 (
31 self::T_COLUMNS_ORDER => array
32 (
33 'title', 'size', 'download', 'is_online', 'uid', 'surface', 'updated_at'
34 )
35 )
36 );
37 }
38
39 40 41 42 43 44
45 protected function get_available_columns()
46 {
47 return array_merge(parent::get_available_columns(), array
48 (
49 'title' => __CLASS__ . '\TitleColumn',
50 'surface' => __CLASS__ . '\SurfaceColumn'
51 ));
52 }
53 }
54
55 namespace Icybee\Modules\Images\ManageBlock;
56
57 use ICanBoogie\ActiveRecord\Query;
58
59 use Icybee\Modules\Images\ThumbnailDecorator;
60
61 62 63
64 class TitleColumn extends \Icybee\Modules\Nodes\ManageBlock\TitleColumn
65 {
66 public function render_cell($record)
67 {
68 return new ThumbnailDecorator(parent::render_cell($record), $record);
69 }
70 }
71
72 73 74 75 76
77 class SurfaceColumn extends \Icybee\ManageBlock\Column
78 {
79 public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
80 {
81 parent::__construct
82 (
83 $manager, $id, $options + array
84 (
85 'class' => 'pull-right measure',
86 'orderable' => true,
87 'filters' => array
88 (
89 'options' => array
90 (
91 '=l' => 'Large',
92 '=m' => 'Medium',
93 '=s' => 'Small'
94 )
95 )
96 )
97 );
98 }
99
100 101 102
103 public function alter_filters(array $filters, array $modifiers)
104 {
105 $filters = parent::alter_filters($filters, $modifiers);
106
107 if (isset($modifiers['surface']))
108 {
109 $value = $modifiers['surface'];
110
111 if (in_array($value, array('l', 'm', 's')))
112 {
113 $filters['surface'] = $value;
114 }
115 else
116 {
117 unset($filters['surface']);
118 }
119 }
120
121 return $filters;
122 }
123
124 125 126
127 public function alter_query_with_filter(Query $query, $filter_value)
128 {
129 if ($filter_value)
130 {
131 list($avg, $max, $min) = $query->model->select('AVG(width * height), MAX(width * height), MIN(width * height)')->similar_site->one(\PDO::FETCH_NUM);
132
133 $bounds = array
134 (
135 $min,
136 round($avg - ($avg - $min) / 3),
137 round($avg),
138 round($avg + ($max - $avg) / 3),
139 $max
140 );
141
142 switch ($filter_value)
143 {
144 case 'l': $query->where('width * height >= ?', $bounds[3]); break;
145 case 'm': $query->where('width * height >= ? AND width * height < ?', $bounds[2], $bounds[3]); break;
146 case 's': $query->where('width * height < ?', $bounds[2]); break;
147 }
148 }
149
150 return $query;
151 }
152
153 154 155
156 public function alter_query_with_order(Query $query, $order_direction)
157 {
158 return $query->order('(width * height) ' . ($order_direction < 0 ? 'DESC' : 'ASC'));
159 }
160
161 public function render_cell($record)
162 {
163 return "{$record->width}×{$record->height} px";
164 }
165 }