/** * Creates or updates a layer * @param OLayer|stdClass $layer A layer object * @return \stdClass An object containing layer, The saved layer, and layers, an array of updated layers * @throws \Exception */ public function setLayer($layer) { if (!$this->IS_AUTH) { throw $this->throwException(AuthenticationException::NO_USER_AUTH); } if (!is_numeric($layer->layerId) || !is_numeric($layer->color) || !is_numeric($layer->index)) { throw $this->throwException(ParameterException::INTEGER_EXCEPTION); } if ($layer->index < 0) { $layer->index = 'IFNULL((SELECT mi FROM (SELECT MAX(`index`)+1 as `mi` FROM `gm_layers`) as `mi`), 0)'; } $id = $layer->layerId; $page = new Page(); $langs = explode(',', AVAILABLELANG); $layer->content = (object) $layer->content; if (!isset($layer->content->title)) { throw $this->throwException(6004); } $layer->content->title = (object) $layer->content->title; foreach ($langs as $lang) { if (isset($layer->content->title->{$lang})) { $layer->label = $layer->content->title->{$lang}; break; } } $layer->label = $page->generateLabel($layer->label); if ($layer->layerId == 0) { $sql = 'INSERT INTO `gm_layers` (`index`, `label`, `color`, `modificationdate`) VALUES (' . $layer->index . ', \'' . Connection::getInstance()->escape_string($layer->label) . '\', ' . $layer->color . ', ' . time() . ')'; $id = $this->_conn->insertRow($sql); } else { $sql = 'UPDATE `gm_layers` ' . 'SET `label`=\'' . Connection::getInstance()->escape_string($layer->label) . '\', ' . '`color`=' . $layer->color . ', ' . '`index`=' . $layer->index . ', ' . '`modificationdate`= ' . time() . ' ' . 'WHERE `layerId`=' . $layer->layerId; $this->_conn->updateRow($sql); $sql = 'UPDATE `gm_markers` SET `color`=' . $layer->color . ' WHERE `uselayercolor`=1 AND `layer`=' . $layer->layerId; $this->_conn->updateRow($sql); } $this->_setContent($layer); $ret = new \stdClass(); $ret->layer = $this->getLayer($id); $ret->layers = $this->getLayers(true); return $ret; }