Created
May 22, 2010 20:59
-
-
Save rbone/410357 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Attachment extends DomainObject | |
{ | |
private function configure($schema, $props, $rels) | |
{ | |
$schema | |
->table('attachment') | |
; | |
$props | |
->serial('attachmentid', array('primary'=>true)) | |
->string('title', 255, array('required'=>true)) | |
->string('path', 255, array('required'=>true)) | |
; | |
$rels | |
->hasOne('Author', 'Author', 'author_id') | |
; | |
$this->traits(new TimeTrackedTrait($props)); | |
} | |
} | |
class TimeTrackedTrait extends Trait | |
{ | |
public function __construct($props) | |
{ | |
$props | |
->timestamp('timecreated') | |
->timestamp('timemodified') | |
; | |
} | |
public function preCreate($domainObject) | |
{ | |
$time = time(); | |
$domainObject->set(array( | |
'timecreated' => $time, | |
'timemodified' => $time, | |
)); | |
} | |
public function preUpdate($domainObject) | |
{ | |
$domainObject->timemodified = time(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment