Gino Multimedia  0.1
Modulo di gestione di contenuti multimediali per Gino CMS
 Tutto Strutture dati File Funzioni Variabili Gruppi Pagine
class.multimediaItem.php
Vai alla documentazione di questo file.
1 <?php
41 class multimediaItem extends propertyObject {
42 
43  protected static $_extension_thumb = array('jpg', 'png');
44 
45  protected $_controller;
46  public static $tbl_item = "multimedia_item";
47  protected $_tbl_item_tag;
48 
55  function __construct($id, $instance) {
56 
57  $this->_controller = $instance;
58  $this->_tbl_data = self::$tbl_item;
59 
60  $this->_fields_label = array(
61  'type'=>_('Tipologia'),
62  'name'=>_("Nome"),
63  'galleries'=>_("Gallerie"),
64  'description'=>_('Descrizione'),
65  'tags'=>array(_("Tag"), _("inserire tag separati da virgole, utilizzare la funzione di autocompletamento quando possibile.")),
66  'credits'=>_('Credits'),
67  'license'=>_('Licenza'),
68  'lat'=>_('Latitudine'),
69  'lng'=>_('Longitudine'),
70  'thumb'=>array(_('Thumbnail'), _('viene inserito un thumbnail di default oppure il thumb dell\'immagine inserita se lasciato vuoto')),
71  'insertion_date'=>_('Data di inserimento'),
72  'last_edit_date'=>_('Data di ultima modifica'),
73  'published'=>_('Pubblicato'),
74  'private'=>array(_('Privato'), _('i media privati saranno visibili solamente agli utenti iscritti al gruppo di visualizzazione di contenuti provati')),
75  'img_filename'=>_('File'),
76  'video_code'=>_('Codice video'),
77  'video_platform'=>_('Piattaforma video'),
78  'video_width'=>_('Larghezza video'),
79  'video_height'=>_('Altezza video'),
80  'mpeg_filename'=>_('File mpeg'),
81  'ogg_filename'=>_('File ogg')
82  );
83 
84  parent::__construct($id);
85 
86  $this->_model_label = $this->id ? $this->name : '';
87  $this->_tbl_item_tag = 'multimedia_item_tag';
88  }
89 
96  public function setTags($tags) {
97 
98  $new_string_tags = array();
99 
100  foreach(explode(',', $tags) as $tag) {
101  $tag = trim($tag);
102  $new_string_tags[] = $tag;
103  }
104 
105  $this->_p['tags'] = implode(',', $new_string_tags);
106  $this->_chgP[] = 'tags';
107  }
108 
116  public function structure($id) {
117 
118  $structure = parent::structure($id);
119 
120  $structure['galleries'] = new manyToManyField(array(
121  'name'=>'galleries',
122  'value'=>explode(',', $this->galleries),
123  'label'=>$this->_fields_label['galleries'],
124  'lenght'=>255,
125  'fkey_table'=>multimediaGallery::$tbl_gallery,
126  'fkey_id'=>'id',
127  'fkey_field'=>'name',
128  'fkey_where'=>'instance=\''.$this->_controller->getInstance().'\'',
129  'fkey_order'=>'name',
130  'table'=>$this->_tbl_data
131  ));
132 
133  $structure['license'] = new foreignKeyField(array(
134  'name'=>'license',
135  'value'=>$this->license,
136  'label'=>$this->_fields_label['license'],
137  'lenght'=>11,
138  'fkey_table'=>multimediaLicense::$tbl_license,
139  'fkey_id'=>'id',
140  'fkey_field'=>'name',
141  'fkey_where'=>'instance=\''.$this->_controller->getInstance().'\'',
142  'fkey_order'=>'name'
143  ));
144 
145  $structure['published'] = new booleanField(array(
146  'name'=>'published',
147  'required'=>true,
148  'label'=>$this->_fields_label['published'],
149  'enum'=>array(1 => _('si'), 0 => _('no')),
150  'default'=>0,
151  'value'=>$this->published,
152  'table'=>$this->_tbl_data
153  ));
154 
155  $structure['private'] = new booleanField(array(
156  'name'=>'private',
157  'required'=>true,
158  'label'=>$this->_fields_label['private'],
159  'enum'=>array(1 => _('si'), 0 => _('no')),
160  'default'=>0,
161  'value'=>$this->private,
162  'table'=>$this->_tbl_data
163  ));
164 
165  $structure['insertion_date'] = new datetimeField(array(
166  'name'=>'insertion_date',
167  'required'=>true,
168  'label'=>$this->_fields_label['insertion_date'],
169  'auto_now'=>false,
170  'value'=>$this->insertion_date
171  ));
172 
173  $base_path = $this->_controller->getBaseAbsPath('thumb');
174 
175  $structure['thumb'] = new multimediaImageField(array(
176  'name'=>'thumb',
177  'value'=>$this->thumb,
178  'label'=>$this->_fields_label['thumb'],
179  'lenght'=>100,
180  'extensions'=>self::$_extension_thumb,
181  'path'=>$base_path,
182  'resize'=>true,
183  'side_dimension'=>$this->_controller->getThumbDimension()
184  ));
185 
186  return $structure;
187  }
188 
197  public static function getObject($id, $controller) {
198 
199  $item = new multimediaItem($id, $controller);
200 
201  if($item->type == AUDIO_CHOICE) {
202  return new multimediaAudio($id, $controller);
203  }
204  elseif($item->type == VIDEO_CHOICE) {
205  return new multimediaVideo($id, $controller);
206  }
207  elseif($item->type == IMAGE_CHOICE) {
208  return new multimediaImage($id, $controller);
209  }
210 
211  }
212 
220  public static function get($instance_obj, $options = null) {
221 
222  $res = array();
223 
224  $private = gOpt('private', $options, false);
225  $published = gOpt('published', $options, true);
226  $geolocalization = gOpt('geolocalization', $options, false);
227  $gallery = gOpt('gallery', $options, null);
228  $order = gOpt('order', $options, 'name');
229  $limit = gOpt('limit', $options, null);
230 
231  $db = db::instance();
232  $selection = array('id', 'type');
233  $table = self::$tbl_item;
234  $where_arr = array("instance='".$instance_obj->getInstance()."'");
235  if(!$private) {
236  $where_arr[] = "private='0'";
237  }
238  if($published) {
239  $where_arr[] = "published='1'";
240  }
241  if($gallery) {
242  $where_arr[] = "galleries REGEXP '[[:<:]]".$gallery."[[:>:]]'";
243  }
244  if($geolocalization) {
245  $where_arr[] = "lat != '' AND lng != ''";
246  }
247 
248  $where = implode(' AND ', $where_arr);
249 
250  $rows = $db->select($selection, $table, $where, $order, $limit);
251  if(count($rows)) {
252  foreach($rows as $row) {
253  if($row['type'] == IMAGE_CHOICE) {
254  $res[] = new multimediaImage($row['id'], $instance_obj);
255  }
256  elseif($row['type'] == VIDEO_CHOICE) {
257  $res[] = new multimediaVideo($row['id'], $instance_obj);
258  }
259  elseif($row['type'] == AUDIO_CHOICE) {
260  $res[] = new multimediaAudio($row['id'], $instance_obj);
261  }
262  }
263  }
264 
265  return $res;
266 
267  }
268 
275  public function saveTags($tags) {
276 
277  $db = db::instance();
278 
279  if(!count($tags)) {
280  return true;
281  }
282 
283  $query = "DELETE FROM ".$this->_tbl_item_tag." WHERE item='".$this->id."'";
284  $res = $db->actionquery($query);
285 
286  $inserts = array();
287  foreach($tags as $tag) {
288  $inserts[] = "('".$this->id."', '".$tag."')";
289  }
290 
291  $query = "INSERT INTO ".$this->_tbl_item_tag." (item, tag) VALUES ".implode(',', $inserts);
292  return $db->actionquery($query);
293 
294  }
295 
301  public function delete() {
302 
303  // delete tags
304  $db = db::instance();
305  $query = "DELETE FROM ".$this->_tbl_item_tag." WHERE item='".$this->id."'";
306 
307  $db->actionquery($query);
308 
309  return parent::delete();
310 
311  }
312 
313 }
314 
315 ?>