Backend\Modules\Location\Engine\Model::update PHP Method

update() public static method

Update an item
public static update ( array $item ) : integer
$item array The data of the record to update.
return integer
    public static function update($item)
    {
        // redefine edited on date
        $item['edited_on'] = BackendModel::getUTCDate();
        // we have an extra_id
        if (isset($item['extra_id'])) {
            // update extra
            BackendModel::updateExtra($item['extra_id'], 'data', array('id' => $item['id'], 'extra_label' => \SpoonFilter::ucfirst(BL::lbl('Location', 'core')) . ': ' . $item['title'], 'language' => $item['language'], 'edit_url' => BackendModel::createURLForAction('Edit') . '&id=' . $item['id']));
        }
        // update item
        return BackendModel::get('database')->update('location', $item, 'id = ? AND language = ?', array($item['id'], $item['language']));
    }

Usage Example

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'));
 }
All Usage Examples Of Backend\Modules\Location\Engine\Model::update