2008-10-03 00:05:45 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-01 04:37:50 +02:00
|
|
|
namespace SilverStripe\FrameworkTest\Model;
|
|
|
|
|
|
|
|
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-03 00:05:45 +02:00
|
|
|
/**
|
|
|
|
* A data type that is related many-many to RelationFieldsTestPage, for testing purposes
|
|
|
|
*/
|
2015-12-17 21:20:49 +01:00
|
|
|
class TestCategory extends DataObject
|
|
|
|
{
|
2016-07-01 04:37:50 +02:00
|
|
|
private static $table_name = 'TestCategory';
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $db = array(
|
|
|
|
"Title" => "Varchar",
|
|
|
|
);
|
|
|
|
private static $belongs_many_many = array(
|
|
|
|
"RelationPages" => "RelationFieldsTestPage",
|
|
|
|
);
|
2016-07-01 04:37:50 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
/**
|
|
|
|
* Returns a dropdown map of all objects of this class
|
|
|
|
*/
|
|
|
|
public static function map()
|
|
|
|
{
|
2016-07-01 04:37:50 +02:00
|
|
|
$categories = DataObject::get('SilverStripe\\FrameworkTest\\Model\\TestCategory');
|
2015-12-17 21:20:49 +01:00
|
|
|
if ($categories) {
|
|
|
|
return $categories->map('ID', 'Title')->toArray();
|
|
|
|
} else {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
}
|
2008-10-03 00:05:45 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function requireDefaultRecords()
|
|
|
|
{
|
2017-05-18 07:11:01 +02:00
|
|
|
if (!DataObject::get_one(static::class)) {
|
2015-12-17 21:20:49 +01:00
|
|
|
foreach (array("A", "B", "C", "D") as $item) {
|
2017-05-18 07:11:01 +02:00
|
|
|
$page = new static();
|
2015-12-17 21:20:49 +01:00
|
|
|
$page->Title = "Test Category $item";
|
|
|
|
$page->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-03 00:05:45 +02:00
|
|
|
}
|