public function move($id, $to) { try { $aDocument = Sitemap_Sample::get($id); if (empty($aDocument['document_name'])) { throw new Exception('Requested id isn`t document'); } Sitemap::updatePage($aDocument['document_name'], $aDocument['document_id'], $aDocument['name'], $aDocument['url_key'], $to); Sitemap::updateParentCount($aDocument['parent']); Sitemap::updateParentCount($to); // Если у переносимого документа есть дочерние элементы $child = Sitemap_Sample::selectChild($aDocument['id']); if (!empty($child)) { foreach ($child as $row) { Sitemap_RestoreUrl::restoreOne($row['id'], $aDocument); } } $this->addAlert('Документ перемещен'); } catch (Exception $e) { $this->addError('Ошибка при перемещении документа'); } $this->jumpBack(); }
/** * Сохраняет данные при редактировании sitemap-страницы * @param array $sitemap */ public static function updateSitemapPageFromPost($sitemap) { self::$sitemap = $sitemap; self::updateVisible($sitemap['id']); self::updateSitemapXMLFromPost($sitemap['id']); self::updateNameAndUrlkey($sitemap['id']); // Если это скрипт, то if (!empty($_POST['sitemap_url_key'])) { $name = $_POST['sitemap_name']; $parent = $sitemap['parent']; $urlKey = $_POST['sitemap_url_key']; if (isset($_POST['sitemap_move_id'])) { $sitemapMoveId = intval($_POST['sitemap_move_id']); if ($sitemapMoveId >= 0) { $parent = $sitemapMoveId; } } Sitemap::updateScript($sitemap['id'], $name, $sitemap['script'], $urlKey, $parent, $sitemap['script_admin_url'], $sitemap['script_manual_order']); if (!empty($sitemapMoveId)) { Sitemap::updateParentCount($sitemap['parent']); Sitemap::updateParentCount($sitemapMoveId); } } }
protected function updateScript($to, $name, $url_key) { $to = intval($to); try { $aDocument = Sitemap_Sample::get($this->aSitemap['id'], $to); if (!empty($aDocument['document_name'])) { throw new Exception('Requested id isn`t script'); } // Обновляем скрипт Sitemap::updateScript($this->aSitemap['id'], $name, $this->aSitemap['script'], $url_key, $to >= 0 && $to != $this->aSitemap['id'] ? $to : $this->aSitemap['parent'], $this->aSitemap['script_admin_url'], $this->aSitemap['script_manual_order']); // Обновляем количество детей у старого и нового предка Sitemap::updateParentCount($this->aSitemap['id']); Sitemap::updateParentCount($to); } catch (Exception $e) { $this->addError('Ошибка при перемещении документа. ', $e->getMessage()); } }