25/05/2012 7:41pm

PHP | Problem - onAfterWrite example


    function onAfterWrite() {

// Create a standard set of pages
if(!$this->Pages()->Count()) {
$defaultPages = array(
array('cover','1'),
array('blank','0'),
array('title','1'),
array('copyright','0'),
array('content','1'),
array('content','1'),
array('content','1'),
array('content','1'),
array('content','1'),
array('content','1')
);
foreach ($defaultPages as $i => $default) {
$uniqueID = uniqID();
$page = new BookPage();
$page->BookID = $this->ID;
$page->Type = $default[0];
$page->Editable = $default[1];
$page->UniqueID = $uniqueID;
$page->SortOrder = $i + 1;
$page->write();
}
}
// Create copyright page
$copyrightPage = Dataobject::get_one('BookPage', "BookID = " . $this->ID . " and Type = 'Copyright'");
if ($copyrightPage && !$this->Copyright) {
$copyright = new BookElement;
$copyright->Type = 'text';
$copyright->UniqueID = uniqid();
$copyright->PosX = 0;
$copyright->PosY = 494;
$copyright->Width = 380;
$copyright->Height = 19;
$copyright->FontSize = 8;
$copyright->FontColor = 'rgb(0, 0, 0)';
$copyright->LineHeight = '9px';
$copyright->FontFamily = 'LiberationSansRegular';
$copyright->FontAlign = 'left';
$copyright->ZIndex = 'auto';
$copyright->Content = 'Text und Bilder des Autors Copyright &copy; %author%. Alle Rechte vorbehalten.<br /> Buchvorlage, Gestaltung, sonstige Inhalte Copyright &copy; ukibu GmbH. Alle Rechte vorbehalten.';
$copyright->BookID = $this->ID;
$copyright->PageID = $copyrightPage->ID;
$copyright->write();
$this->Copyright = True;
}
return parent::onAfterWrite();
}


Post Comment