silverstripe-frameworktest/code/TestCategory.php

49 lines
1.1 KiB
PHP
Raw Normal View History

2008-10-03 00:05:45 +02:00
<?php
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
{
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",
);
2015-12-17 21:20:49 +01:00
/**
* Returns a dropdown map of all objects of this class
*/
public static function map()
{
$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()
{
$class = $this->class;
if (!DataObject::get_one($class)) {
foreach (array("A", "B", "C", "D") as $item) {
$page = new $class();
$page->Title = "Test Category $item";
$page->write();
}
}
}
2008-10-03 00:05:45 +02:00
}