Ich woll gerne eine Seite brauchen um neue Seiten zu machen (e.g. Vorlage). Aber ist es möglich um eine Seite zu kopieren? Ich habe nichts gefunden in der Dokumentation.
Ich woll gerne eine Seite brauchen um neue Seiten zu machen (e.g. Vorlage). Aber ist es möglich um eine Seite zu kopieren? Ich habe nichts gefunden in der Dokumentation.
Einfach auf das grüne Pluszeichen neben den Artikeln bzw. der Seitenstruktur klicken.
Ja klar, aber ich woll das ist meine eigenes Erweiterung asfuhren. Ich habe eine callback gemacht:
Code:$GLOBALS['TL_DCA']['tl_user']['config']['onsubmit_callback'][] = array('WikiContentAccess', 'onBackendUserCreated');Aber habe ich keine Ahnung wie Contao Seite duplizier code kann Wiederverwenden.Code:/** * Invoked when a new user gets added */ public function onBackendUserCreated(DataContainer $dc) { // check whether the user already owns a page, if not create the page // by duplicating the base or template page $userId = $dc->activeRecord->id; $pageRecord = $this->Database->prepare("SELECT * FROM tl_page WHERE cuser=? AND cgroup=3") ->execute($userId)->row(); // check whether a page is already owned by the user, if not duplicate the base page if ( $pageRecord === FALSE ) { $this->createDuplicateOfPage( 10 ); } } public function createDuplicateOfPage($pageId) { // duplicate the page and its contents var_dump('createDuplicateOfPage', $pageId); }
Geändert von sprog (09.03.2011 um 13:05 Uhr)
Das müsstest du wohl direkt auf DB-Ebene machen. Contao bietet keine API für solche Funktionen.
terminal42 gmbh
Wir sind Contao Premium-Partner! Für Modulwünsche oder Programmierungen kannst du uns gerne kontaktieren.
Hilfe für Isotope eCommerce kann man auch kaufen: Isotope Circle
Du musst dich am Vorbild aus der DC_Table::copyChilds langhangeln, und alle ChildRecords duplizieren und mit den neuen pid Werten belegen
von Willi Voltz aus PR 500: Henry George sagte einmal: »Kultur ist Zusammenarbeit.«
Contao-Hosting: begeisterter Uberspace-Nutzer
Schade das Contao keine API hat
Das wuerd ich so nicht sagen. Contao hat eine gute API. nur war es bisher nich notwendig, das Erweiterungen diese Aktionen durchfuehren.
Du kannst deine Programmierqualitaeten gerne nutzen, und eine normale lib programmieren, damit man eben dies auch durchfuehren kann.
An sich ja auch nicht schwer, wie ich zwei Beitrage hoeher schon geschrieben habe.
Also API ist wirklich da....
von Willi Voltz aus PR 500: Henry George sagte einmal: »Kultur ist Zusammenarbeit.«
Contao-Hosting: begeisterter Uberspace-Nutzer
Guten morgen! Ich habe eine Klasse gemacht:
PHP-Code:
/**
* Duplicates the page with the given id
*
* @param pageId the page id of the page to be duplicated
* @param title the title of the new page
* @param owner the owner of the new page
*
* @returns int, identifier of the new page
*/
public function duplicatePage($pageId, $title, $owner)
{
$pagesRecordset = $this->Database->prepare('SELECT * FROM tl_page WHERE id=?')->execute( $pageId );
if ( !$pagesRecordset->numRows )
{
return false;
}
// retrieve the data of the page to be cloned
$page = $pagesRecordset->fetchAssoc();
unset( $page['id'] ); // remove the unique identifier of the page
$page['cuser'] = $owner;
$page['tstamp'] = time();
$page['title'] = $title;
$page['pageTitle'] = $title;
$page['alias'] = $this->getAliasByPageTitle( $title );
// create the page record
$newPageId = $this->Database->prepare("INSERT INTO tl_page %s")->set($page)->execute()->insertId;
// retrieve the articles associated with the page
$articles = $this->Database->prepare('SELECT * FROM tl_article WHERE pid=?')->execute( $pageId )->fetchAllAssoc();
foreach ( $articles as $articleIndex => $article )
{
// update the article definitions so that the article is owned by the user and the parent id is the new page
$article['pid'] = $newPageId;
$article['author'] = $owner;
$article['alias'] = $this->getAliasByPageTitle( $title );
$article['published'] = '1'; // always published
$articles[$articleIndex] = $article;
}
// create all the articles for the page
foreach ( $articles as $articleIndex => $article )
{
$articleId = $article['id'];
unset( $article['id'] );
$newArticleId = $this->Database->prepare("INSERT INTO tl_article %s")->set($article)->execute()->insertId;
$elementIds = $this->duplicateContentElements( $articleId, $newArticleId );
}
return $newPageId;
}
/**
* Duplicates all the content elements of the given article
* and associate with the newly created article.
*
* @param oldArticle the old article to use for duplication
* @param newArticle the new article to use for the duplicated elements
*/
public function duplicateContentElements($oldArticle, $newArticle)
{
$result = array();
$contentElements = $this->Database->prepare('SELECT * FROM tl_content WHERE pid=?')->execute( $oldArticle )->fetchAllAssoc();
foreach ( $contentElements as $elementIndex => $contentElement )
{
$elementId = $contentElement['id'];
unset( $contentElement['id'] );
$contentElement['pid'] = $newArticle;
$newElementId = $this->Database->prepare("INSERT INTO tl_content %s")->set($contentElement)->execute()->insertId;
$result[] = $newElementId;
}
return $result;
}
public function getAliasByPageTitle($title)
{
return $title;
}
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
Lesezeichen