Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $generalSettings = $this->get('fork.settings')->getForModule('Location');
     // get parameters
     $itemId = \SpoonFilter::getPostValue('id', null, null, 'int');
     $zoomLevel = trim(\SpoonFilter::getPostValue('zoom', null, 'auto'));
     $mapType = strtoupper(trim(\SpoonFilter::getPostValue('type', array('roadmap', 'satellite', 'hybrid', 'terrain', 'street_view'), 'roadmap')));
     $mapStyle = trim(\SpoonFilter::getPostValue('style', array('standard', 'custom', 'gray', 'blue'), 'standard'));
     $centerLat = \SpoonFilter::getPostValue('centerLat', null, 1, 'float');
     $centerlng = \SpoonFilter::getPostValue('centerLng', null, 1, 'float');
     $height = \SpoonFilter::getPostValue('height', null, $generalSettings['height'], 'int');
     $width = \SpoonFilter::getPostValue('width', null, $generalSettings['width'], 'int');
     $showLink = \SpoonFilter::getPostValue('link', array('true', 'false'), 'false', 'string');
     $showDirections = \SpoonFilter::getPostValue('directions', array('true', 'false'), 'false', 'string');
     $showOverview = \SpoonFilter::getPostValue('showOverview', array('true', 'false'), 'true', 'string');
     // reformat
     $center = array('lat' => $centerLat, 'lng' => $centerlng);
     $showLink = $showLink == 'true';
     $showDirections = $showDirections == 'true';
     $showOverview = $showOverview == 'true';
     // standard dimensions
     if ($width > 800) {
         $width = 800;
     }
     if ($width < 300) {
         $width = $generalSettings['width'];
     }
     if ($height < 150) {
         $height = $generalSettings['height'];
     }
     // no id given, this means we should update the main map
     BackendLocationModel::setMapSetting($itemId, 'zoom_level', (string) $zoomLevel);
     BackendLocationModel::setMapSetting($itemId, 'map_type', (string) $mapType);
     BackendLocationModel::setMapSetting($itemId, 'map_style', (string) $mapStyle);
     BackendLocationModel::setMapSetting($itemId, 'center', (array) $center);
     BackendLocationModel::setMapSetting($itemId, 'height', (int) $height);
     BackendLocationModel::setMapSetting($itemId, 'width', (int) $width);
     BackendLocationModel::setMapSetting($itemId, 'directions', $showDirections);
     BackendLocationModel::setMapSetting($itemId, 'full_url', $showLink);
     $item = array('id' => $itemId, 'language' => BL::getWorkingLanguage(), 'show_overview' => $showOverview ? 'Y' : 'N');
     BackendLocationModel::update($item);
     // output
     $this->output(self::OK, null, BL::msg('Success'));
 }
Example #2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $itemId = trim(\SpoonFilter::getPostValue('id', null, '', 'int'));
     $lat = \SpoonFilter::getPostValue('lat', null, null, 'float');
     $lng = \SpoonFilter::getPostValue('lng', null, null, 'float');
     // validate id
     if ($itemId == 0) {
         $this->output(self::BAD_REQUEST, null, BL::err('NonExisting'));
     } else {
         //update
         $updateData = array('id' => $itemId, 'lat' => $lat, 'lng' => $lng, 'language' => BL::getWorkingLanguage());
         BackendLocationModel::update($updateData);
         // output
         $this->output(self::OK);
     }
 }
Example #3
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendLocationModel::exists($this->id)) {
         parent::execute();
         // get all data for the item we want to edit
         $this->record = (array) BackendLocationModel::get($this->id);
         // delete item
         BackendLocationModel::delete($this->id);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         // user was deleted, so redirect
         $this->redirect(BackendModel::createURLForAction('Index') . '&report=deleted&var=' . urlencode($this->record['title']));
     } else {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
Example #4
0
 /**
  * Load the settings
  */
 protected function loadData()
 {
     $this->items = BackendLocationModel::getAll();
     $this->settings = BackendLocationModel::getMapSettings(0);
     $firstMarker = current($this->items);
     // if there are no markers we reset it to the birthplace of Fork
     if ($firstMarker === false) {
         $firstMarker = array('lat' => '51.052146', 'lng' => '3.720491');
     }
     // load the settings from the general settings
     if (empty($this->settings)) {
         $this->settings = $this->get('fork.settings')->getForModule('Location');
         $this->settings['center']['lat'] = $firstMarker['lat'];
         $this->settings['center']['lng'] = $firstMarker['lng'];
     }
     // no center point given yet, use the first occurrence
     if (!isset($this->settings['center'])) {
         $this->settings['center']['lat'] = $firstMarker['lat'];
         $this->settings['center']['lng'] = $firstMarker['lng'];
     }
 }
Example #5
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             // build item
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['street'] = $this->frm->getField('street')->getValue();
             $item['number'] = $this->frm->getField('number')->getValue();
             $item['zip'] = $this->frm->getField('zip')->getValue();
             $item['city'] = $this->frm->getField('city')->getValue();
             $item['country'] = $this->frm->getField('country')->getValue();
             // define coordinates
             $coordinates = BackendLocationModel::getCoordinates($item['street'], $item['number'], $item['city'], $item['zip'], $item['country']);
             // define latitude and longitude
             $item['lat'] = $coordinates['latitude'];
             $item['lng'] = $coordinates['longitude'];
             // insert the item
             $item['id'] = BackendLocationModel::insert($item);
             // everything is saved, so redirect to the overview
             if ($item['lat'] && $item['lng']) {
                 // trigger event
                 BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             }
             // redirect
             $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $item['id'] . '&report=added&var=' . urlencode($item['title']));
         }
     }
 }
Example #6
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['language'] = BL::getWorkingLanguage();
             $item['extra_id'] = $this->record['extra_id'];
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['street'] = $this->frm->getField('street')->getValue();
             $item['number'] = $this->frm->getField('number')->getValue();
             $item['zip'] = $this->frm->getField('zip')->getValue();
             $item['city'] = $this->frm->getField('city')->getValue();
             $item['country'] = $this->frm->getField('country')->getValue();
             // check if it's necessary to geocode again
             if ($this->record['lat'] === null || $this->record['lng'] === null || $item['street'] != $this->record['street'] || $item['number'] != $this->record['number'] || $item['zip'] != $this->record['zip'] || $item['city'] != $this->record['city'] || $item['country'] != $this->record['country']) {
                 // define coordinates
                 $coordinates = BackendLocationModel::getCoordinates($item['street'], $item['number'], $item['city'], $item['zip'], $item['country']);
                 // define latitude and longitude
                 $item['lat'] = $coordinates['latitude'];
                 $item['lng'] = $coordinates['longitude'];
             } else {
                 $item['lat'] = $this->record['lat'];
                 $item['lng'] = $this->record['lng'];
             }
             // insert the item
             BackendLocationModel::update($item);
             // everything is saved, so redirect to the overview
             if ($item['lat'] && $item['lng']) {
                 // trigger event
                 BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             }
             // redirect to the overview
             if ($this->frm->getField('redirect')->getValue() == 'overview') {
                 $this->redirect(BackendModel::createURLForAction('Index') . '&report=edited&var=' . rawurlencode($item['title']) . '&highlight=row-' . $item['id']);
             } else {
                 $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $item['id'] . '&report=edited');
             }
         }
     }
 }