silverstripe-framework/tests/php/Dev/CsvBulkLoaderTest/Player.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2016-10-14 03:30:05 +02:00
<?php
namespace SilverStripe\Dev\Tests\CsvBulkLoaderTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
class Player extends DataObject implements TestOnly
{
private static $table_name = 'CsvBulkLoaderTest_Player';
2016-10-14 03:30:05 +02:00
private static $db = [
'FirstName' => 'Varchar(255)',
'Biography' => 'HTMLText',
'Birthday' => 'Date',
'ExternalIdentifier' => 'Varchar(255)', // used for uniqueness checks on passed property
'IsRegistered' => 'Boolean'
];
2016-10-14 03:30:05 +02:00
private static $has_one = [
'Team' => Team::class,
'Contract' => PlayerContract::class
];
2016-10-14 03:30:05 +02:00
public function getTeamByTitle($title)
{
return DataObject::get_one(
Team::class,
[
'"CsvBulkLoaderTest_Team"."Title"' => $title
]
);
}
2016-10-14 03:30:05 +02:00
/**
* Custom setter for "Birthday" property when passed/imported
* in different format.
*
* @param string $val
* @param array $record
*/
public function setUSBirthday($val, $record = null)
{
2022-04-14 03:12:59 +02:00
$this->Birthday = preg_replace('/^([0-9]{1,2})\/([0-9]{1,2})\/([0-90-9]{2,4})/', '\\3-\\1-\\2', $val ?? '');
}
2016-10-14 03:30:05 +02:00
}