Skip to content

Instantly share code, notes, and snippets.

@tedkulp
Created November 28, 2010 22:30
Show Gist options
  • Save tedkulp/719351 to your computer and use it in GitHub Desktop.
Save tedkulp/719351 to your computer and use it in GitHub Desktop.
class TestDataMapperTable extends CmsDataMapper
{
var $counter = 0;
static public $static_counter = 0;
var $_fields = array(
'id' => array(
'type' => 'int',
'primary' => true,
'serial' => true,
),
'test_field' => array(
'type' => 'string',
'length' => 255,
'required' => true,
),
'another_test_field' => array(
'type' => 'string',
'length' => 255,
),
'some_int' => array(
'type' => 'int',
),
'some_float' => array(
'type' => 'float',
),
'version' => array(
'type' => 'int',
),
'create_date' => array(
'type' => 'create_date',
),
'modified_date' => array(
'type' => 'modified_date',
),
'children' => array(
'type' => 'association',
'association' => 'has_many',
'child_object' => 'TestDataMapperTableChild',
'foreign_key' => 'parent_id',
),
);
public function setup()
{
//$this->create_has_many_association('children', 'TestDataMapperTableChild', 'parent_id');
//$this->assign_acts_as('Versioned');
}
public function validate()
{
$this->validate_not_blank('test_field');
if (strlen($this->another_test_field) == 0)
{
$this->add_validation_error('can\'t be blank');
}
$this->validate_numericality_of('some_int');
$this->validate_numericality_of('some_float');
}
protected function before_load($type, $fields)
{
self::$static_counter++;
}
public function after_load()
{
$this->counter++;
}
public function before_save()
{
$this->counter++;
}
public function after_save()
{
$this->counter++;
$this->counter++;
}
public function before_delete()
{
$this->counter++;
}
public function after_delete()
{
$this->counter++;
$this->counter++;
}
}
class TestDataMapperTableChild extends CmsDataMapper
{
var $_fields = array(
'id' => array(
'type' => 'int',
'primary' => true,
'serial' => true,
),
'parent_id' => array(
'type' => 'int',
),
'some_other_field' => array(
'type' => 'string',
'length' => 255,
),
'version' => array(
'type' => 'int',
),
'create_date' => array(
'type' => 'create_date',
),
'modified_date' => array(
'type' => 'modified_date',
),
'parent' => array(
'type' => 'association',
'association' => 'belongs_to',
'parent_object' => 'testDataMapperTable',
'foreign_key' => 'parent_id',
),
);
public function setup()
{
//$this->create_belongs_to_association('parent', 'test_data_mapper_table', 'parent_id');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment