update() public static method

Update an item
public static update ( array $item ) : integer
$item array The data of the record to update.
return integer
Beispiel #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'));
 }
Beispiel #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);
     }
 }
Beispiel #3
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');
             }
         }
     }
 }