Skip to content

Instantly share code, notes, and snippets.

@rbone
Created May 22, 2010 20:59
Show Gist options
  • Save rbone/410357 to your computer and use it in GitHub Desktop.
Save rbone/410357 to your computer and use it in GitHub Desktop.
<?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