Gino Gmaps  1.0.1
Modulo di gestione di mappe interattive per Gino CMS
 Tutto Strutture dati File Funzioni Variabili Gruppi Pagine
class.gmapsCollection.php
Vai alla documentazione di questo file.
1 <?php
35 class gmapsCollection extends propertyObject {
36 
37  private static $_tbl_collection = 'gmaps_point_collection';
38  private static $_tbl_collection_image = 'gmaps_point_collection_image';
39 
41 
45  private $_img_width = 600;
46 
50  private $_thumb_width = 100;
51 
55  private $_images;
56 
65  function __construct($id, $instance) {
66 
67  $this->_controller = $instance;
68  $this->_tbl_data = self::$_tbl_collection;
69  parent::__construct($id);
70 
71  $this->_extension_media = array('jpg', 'jpeg', 'png');
72  $this->_prefix_img = 'img_';
73  $this->_prefix_thumb = 'thumb_';
74  $this->_data_www = CONTENT_WWW.'/gmaps/'.$this->_controller->instanceName().'/point/collections';
75  $this->_data_dir = CONTENT_DIR.OS.'gmaps'.OS.$this->_controller->instanceName().OS.'point'.OS.'collections';
76 
77  $this->_images = array();
78  $query = "SELECT id FROM ".self::$_tbl_collection_image." WHERE collection_id='".$this->id."'";
79  $a = $this->_db->selectquery($query);
80  if(count($a)) {
81  foreach($a as $b) {
82  $this->_images[] = new gmapsCollectionImage($b['id'], $this->_controller);
83  }
84  }
85  }
86 
94  public function setPoint_id($value) {
95 
96  if($this->_p['point_id']!=$value && !in_array('point_id', $this->_chgP)) $this->_chgP[] = 'point_id';
97  $this->_p['point_id'] = $value;
98  return true;
99 
100  }
101 
108  public function images() {
109 
110  return $this->_images;
111 
112  }
113 
121  public function form($redirect) {
122 
123  if(isset($_POST['submit'])) {
124  $gform = new Form('form_collection', 'post', false, array('verifyToken'=>true));
125  $gform->save('dataform');
126  $req_error = $gform->arequired();
127  if(!$req_error) {
128  $this->name = cleanVar($_POST, 'name', 'string', '');
129  $this->description = cleanVar($_POST, 'description', 'string', '');
130 
131  $this->updateDbData();
132 
133  $old_image = cleanVar($_POST, 'old_image', 'string', '');
134 
135  $res = $gform->manageFile('image', $old_image, true, $this->_extension_media, $this->_data_dir.OS, preg_replace("#action=insert#", 'action=modify&id='.$this->id, $_SERVER['QUERY_STRING']), $this->_tbl_data, 'image', 'id', $this->id, array('prefix_file'=>$this->_prefix_img, 'prefix_thumb'=>$this->_prefix_thumb, 'width'=>$this->_img_width, 'thumb_width'=>$this->_thumb_width));
136 
137  header("Location: ".$redirect);
138  exit();
139  }
140  else {
141  error::errorMessage(array('error'=>1), $_SERVER['QUERY_STRING']);
142  exit();
143  }
144  }
145 
146  if($this->id) {
147  $title = _("Modifica collezione");
148  $submit = _("modifica");
149  }
150  else {
151  $title = _("Nuova collezione");
152  $submit= _("inserisci");
153  }
154  $htmlsection = new htmlSection(array('class'=>'admin', 'headerTag'=>'header', 'headerLabel'=>$title));
155 
156  $gform = new Form('form_collection', 'post', true, array('trnsl_table'=>$this->_tbl_data, 'trnsl_id'=>$this->id));
157  $gform->load('dataform');
158  $buffer = $gform->form('', true, 'name', array('generateToken'=>true));
159  $buffer .= $gform->hidden('id', $this->id);
160 
161  $buffer .= $gform->cinput('name', 'text', $gform->retvar('name', htmlInput($this->name)), _("Nome"), array('required'=>true, 'maxlength'=>200, 'size'=>40, 'trnsl'=>true, 'field'=>'name'));
162  $buffer .= $gform->ctextarea('description', $gform->retvar('description', htmlInput($this->description)), _("Descrizione"), array('cols'=>40, 'rows'=>4, 'trnsl'=>true, 'field'=>'description'));
163 
164  $buffer .= $gform->cfile('image', $this->image, _("Immagine"), array("required"=>false, "extensions"=>$this->_extension_media, "del_check"=>true, "preview"=>true, "previewSrc"=>$this->_data_www.'/'.$this->_prefix_img.$this->image));
165  $buffer .= $gform->cinput('submit', 'submit', $submit, '', array('classField'=>'submit'));
166 
167  $buffer .= $gform->cform();
168 
169  $htmlsection->content = $buffer;
170 
171  return $htmlsection->render();
172  }
173 
180  public function thumb($css_class) {
181 
182  return "<img class=\"".$css_class."\" src=\"".$this->_data_www."/".$this->_prefix_thumb.$this->image."\" alt=\"".preg_replace("#\"#", "'", htmlChars($this->ml('name')))."\" />";
183 
184  }
185 
192  public function img($css_class = '', $title = null, $description=null) {
193 
194  return "<img class=\"".$css_class."\" src=\"".$this->_data_www."/".$this->_prefix_img.$this->image."\" alt=\"".preg_replace("#\"#", "'", htmlChars($this->ml('name')))."\" />";
195 
196  }
197 
204  public function thumbPath() {
205 
206  return $this->_data_www."/".$this->_prefix_thumb.$this->image;
207 
208  }
209 
216  public function path() {
217 
218  return $this->_data_www."/".$this->_prefix_img.$this->image;
219 
220  }
221 
229  public function delete() {
230 
231  // delete images
232  foreach($this->_images as $image) {
233  $image->delete();
234  }
235 
236  @unlink($this->_data_dir.OS.$this->_prefix_img.$this->image);
237  @unlink($this->_data_dir.OS.$this->_prefix_thumb.$this->image);
238 
239  return $this->deleteDbData();
240 
241  }
242 
243 
244 }
245 
246 ?>