Gino Multimedia  0.1
Modulo di gestione di contenuti multimediali per Gino CMS
 Tutto Strutture dati File Funzioni Variabili Gruppi Pagine
class.multimediaGallery.php
Vai alla documentazione di questo file.
1 <?php
33 class multimediaGallery extends propertyObject {
34 
35  private $_controller;
36 
37  protected static $_extension_thumb = array('jpg', 'png');
38  public static $tbl_gallery = "multimedia_gallery";
39 
46  function __construct($id, $instance) {
47 
48  $this->_controller = $instance;
49  $this->_tbl_data = self::$tbl_gallery;
50 
51  $this->_fields_label = array(
52  'name'=>_("Nome"),
53  'slug'=>array(_("Slug"), _('utilizzato per creare un permalink alla risorsa')),
54  'description'=>_('Descrizione'),
55  'thumb'=>array(_('Thumbnail'), _('viene inserito il thumbnail del primo media contenuto se lasciato vuoto')),
56  'published'=>_('Pubblicata'),
57  'private'=>array(_('Privata'), _('le gallerie private saranno visibili solamente agli utenti iscritti al gruppo di visualizzazione di contenuti provati')),
58  'insertion_date'=>_('Data di inserimento'),
59  'last_edit_date'=>_('Data di ultima modifica'),
60  'promoted'=>array(_('Promossa'), _('La più recente galleria promossa viene inserita in testa alla vista "ultime gallerie"'))
61  );
62 
63  parent::__construct($id);
64 
65  $this->_model_label = $this->id ? $this->name : '';
66  }
67 
75  public function structure($id) {
76 
77  $structure = parent::structure($id);
78 
79  $structure['published'] = new booleanField(array(
80  'name'=>'published',
81  'required'=>true,
82  'label'=>$this->_fields_label['published'],
83  'enum'=>array(1 => _('si'), 0 => _('no')),
84  'default'=>0,
85  'value'=>$this->published
86  ));
87 
88  $structure['private'] = new booleanField(array(
89  'name'=>'private',
90  'required'=>true,
91  'label'=>$this->_fields_label['private'],
92  'enum'=>array(1 => _('si'), 0 => _('no')),
93  'default'=>0,
94  'value'=>$this->private
95  ));
96 
97  $structure['promoted'] = new booleanField(array(
98  'name'=>'promoted',
99  'required'=>true,
100  'label'=>$this->_fields_label['promoted'],
101  'enum'=>array(1 => _('si'), 0 => _('no')),
102  'default'=>0,
103  'value'=>$this->promoted
104  ));
105 
106  $structure['insertion_date'] = new datetimeField(array(
107  'name'=>'insertion_date',
108  'required'=>true,
109  'label'=>$this->_fields_label['insertion_date'],
110  'auto_now'=>false,
111  'value'=>$this->insertion_date
112  ));
113 
114  $base_path = $this->_controller->getBaseAbsPath('thumb');
115 
116  $structure['thumb'] = new multimediaImageField(array(
117  'name'=>'thumb',
118  'value'=>$this->thumb,
119  'label'=>$this->_fields_label['thumb'],
120  'lenght'=>100,
121  'extensions'=>self::$_extension_thumb,
122  'path'=>$base_path,
123  'resize'=>true,
124  'side_dimension'=>$this->_controller->getThumbDimension()
125  ));
126 
127 
128  return $structure;
129  }
130 
139  public static function getFromSlug($slug, $controller) {
140 
141  $res = null;
142 
143  $db = db::instance();
144  $rows = $db->select('id', self::$tbl_gallery, "slug='$slug'", null, array(0, 1));
145  if(count($rows)) {
146  $res = new multimediaGallery($rows[0]['id'], $controller);
147  }
148 
149  return $res;
150 
151  }
152 
160  public static function getLEPromoted($instance_obj, $options = null) {
161 
162  $res = null;
163 
164  $private = gOpt('private', $options, false);
165  $published = gOpt('published', $options, true);
166 
167  $db = db::instance();
168  $selection = 'id';
169  $table = self::$tbl_gallery;
170  $where_arr = array("instance='".$instance_obj->getInstance()."'", "promoted='1'");
171  if(!$private) {
172  $where_arr[] = "private='0'";
173  }
174  if($published) {
175  $where_arr[] = "published='1'";
176  }
177  $where = implode(' AND ', $where_arr);
178 
179  $rows = $db->select($selection, $table, $where, 'last_edit_date DESC', array(0, 1));
180  if($rows && count($rows)) {
181  $res = new multimediaGallery($rows[0]['id'], $instance_obj);
182  }
183 
184  return $res;
185 
186  }
187 
188 
196  public static function get($instance_obj, $options = null) {
197 
198  $res = array();
199 
200  $private = gOpt('private', $options, false);
201  $published = gOpt('published', $options, true);
202  $where_q = gOpt('where', $options, '');
203  $order = gOpt('order', $options, 'name');
204  $limit = gOpt('limit', $options, null);
205 
206  $db = db::instance();
207  $selection = 'id';
208  $table = self::$tbl_gallery;
209  $where_arr = array("instance='".$instance_obj->getInstance()."'");
210  if(!$private) {
211  $where_arr[] = "private='0'";
212  }
213  if($published) {
214  $where_arr[] = "published='1'";
215  }
216  if($where_q) {
217  $where_arr[] = $where_q;
218  }
219  $where = implode(' AND ', $where_arr);
220 
221  $rows = $db->select($selection, $table, $where, $order, $limit);
222  if(count($rows)) {
223  foreach($rows as $row) {
224  $res[] = new multimediaGallery($row['id'], $instance_obj);
225  }
226  }
227 
228  return $res;
229 
230  }
231 
239  public static function getCount($instance_obj, $options = null) {
240 
241  $tot = 0;
242 
243  $private = gOpt('private', $options, false);
244  $published = gOpt('published', $options, true);
245 
246  $db = db::instance();
247  $selection = 'COUNT(id) AS tot';
248  $table = self::$tbl_gallery;
249  $where_arr = array("instance='".$instance_obj->getInstance()."'");
250  if(!$private) {
251  $where_arr[] = "private='0'";
252  }
253  if($published) {
254  $where_arr[] = "published='1'";
255  }
256  $where = implode(' AND ', $where_arr);
257 
258  $rows = $db->select($selection, $table, $where, null, null);
259  if(count($rows)) {
260  $tot = $rows[0]['tot'];
261  }
262 
263  return $tot;
264 
265  }
266 
274  public function getItems($instance_obj, $options = null) {
275 
276  $res = array();
277 
278  $private = gOpt('private', $options, false);
279  $published = gOpt('published', $options, true);
280  $order = gOpt('order', $options, 'insertion_date DESC');
281  $limit = gOpt('limit', $options, null);
282  $where_c = gOpt('where', $options, false);
283 
284  $db = db::instance();
285  $selection = array('id', 'type');
286  $table = multimediaItem::$tbl_item;
287  $where_arr = array(
288  "instance='".$instance_obj->getInstance()."'",
289  "galleries REGEXP '[[:<:]]".$this->id."[[:>:]]'",
290  );
291  if(!$private) {
292  $where_arr[] = "private='0'";
293  }
294  if($published) {
295  $where_arr[] = "published='1'";
296  }
297  if($where_c) {
298  $where_arr[] = $where_c;
299  }
300  $where = implode(' AND ', $where_arr);
301 
302  $rows = $db->select($selection, $table, $where, $order, $limit);
303  if(count($rows)) {
304  foreach($rows as $row) {
305  if($row['type'] == AUDIO_CHOICE) {
306  $res[] = new multimediaAudio($row['id'], $instance_obj);
307  }
308  elseif($row['type'] == VIDEO_CHOICE) {
309  $res[] = new multimediaVideo($row['id'], $instance_obj);
310  }
311  elseif($row['type'] == IMAGE_CHOICE) {
312  $res[] = new multimediaImage($row['id'], $instance_obj);
313  }
314  }
315  }
316 
317  return $res;
318 
319  }
320 
328  public function getItemsCount($instance_obj, $options = null) {
329 
330  $tot = 0;
331 
332  $private = gOpt('private', $options, false);
333  $published = gOpt('published', $options, true);
334 
335  $db = db::instance();
336  $selection = 'COUNT(id) AS tot';
337  $table = multimediaItem::$tbl_item;
338  $where_arr = array(
339  "instance='".$instance_obj->getInstance()."'",
340  "galleries REGEXP '[[:<:]]".$this->id."[[:>:]]'"
341  );
342  if(!$private) {
343  $where_arr[] = "private='0'";
344  }
345  if($published) {
346  $where_arr[] = "published='1'";
347  }
348  $where = implode(' AND ', $where_arr);
349 
350  $rows = $db->select($selection, $table, $where, null, null);
351  if(count($rows)) {
352  $tot = $rows[0]['tot'];
353  }
354 
355  return $tot;
356 
357  }
358 
359 
366  public function thumbPath($controller) {
367 
368  if($this->thumb) {
369  return $controller->getBasePath('thumb').'/'.$this->thumb;
370  }
371  else {
372  $media = multimediaItem::get($controller, array('published'=>true, 'gallery'=>$this->id, 'order'=>'insertion_date ASC', 'limit'=>array(0, 1)));
373  if(count($media) && $media) {
374  return $media[0]->thumbPath($controller);
375  }
376  else return $controller->defaultGalleryThumbPath();
377  }
378 
379  }
380 
381 
382 }
383 
384 ?>