12/03/2012 5:24pm

PHP | Problem - Memory problem


class Book extends DataObject {


public static $db = array(
'Title' => 'Varchar',
'Description' => 'Text',
'Copyright' => 'Boolean'
);

public static $has_one = array(
'Thumbnail' => 'Image',
'Category' => 'BookCategory',
'StoryWorld' => 'StoryWorld'
);

public static $has_many = array(
'Images' => 'BookImage',
'Pages' => 'BookPage',
'Elements' => 'BookElement',
'Choices' => 'StoryChoice'
);

static $summary_fields = array(
'ID',
'Title',
'Description'
);

function getCMSFields() {
$fields = parent::getCMSFields();

$manager = new DataObjectManager(
$this, // Controller
'Pages', // Source name
'BookPage', // Source class
array(
'Type' => 'Type',
'UniqueID' => 'UniqueID',
'Editable' => 'Editable'
),
'getCMSFields'
);
$fields->addFieldToTab("Root.Pages", $manager);
$manager = new DataObjectManager(
$this,
'Choices',
'StoryChoice',
array(
'Label' => 'Label',
'Type' => 'Type',
),
'getCMSFields'
);
$fields->addFieldToTab("Root.Choices", $manager);

return $fields;
}

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 $default) {
$uniqueID = uniqID();
$page = new BookPage();
$page->BookID = $this->ID;
$page->Type = $default[0];
$page->Editable = $default[1];
$this->UniqueID = $uniqueID;
$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; GmbH. Alle Rechte vorbehalten.';
$copyright->BookID = $this->ID;
$copyright->PageID = $copyrightPage->ID;
$copyright->write();
$this->Copyright = True;
}
return parent::onAfterWrite();
}

...

}


==================================


class BookPage extends DataObject {

public static $db = array(
'Type' => 'Enum("cover, blank, title, copyright, back, content", "content")',
'UniqueID' => 'Varchar',
'Background' => 'Varchar',
'MotivationText' => 'HTMLText',
'Editable' => 'Boolean'
);

public static $has_one = array(
'Book' => 'Book',
'MemberBook' => 'MemberBook'
);

public static $has_many = array(
'Elements' => 'BookElement'
);

public static $default_sort = 'SortOrder ASC, Number ASC';

public static $summary_fields = array(
'Type',
'MotivationText',
'Editable',
);

function onAfterWrite() {
if (!($this->UniqueID)) {
$uniqueID = uniqID();
$this->UniqueID = $uniqueID;
$this->write();
}
}

...

}


==================================


class BookAdmin extends ModelAdmin {

public static $managed_models = array(
'Book',
'StoryWorld',
'MemberBook',
'BookCategory'
);

static $url_segment = 'books';
static $menu_title = 'Book Admin';

}


Post Comment