silverstripe-frameworktest/code/Employee.php

95 lines
2.8 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\FrameworkTest\Model;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\TextField;
/**
* Description of Employees
*
*/
2015-12-17 21:20:49 +01:00
class Employee extends DataObject
{
2015-12-17 21:20:49 +01:00
private static $db = array(
'Name' => 'Varchar',
'Biography' => 'HTMLText'
);
2015-12-17 21:20:49 +01:00
private static $has_one = array(
'Company' => 'SilverStripe\\FrameworkTest\\Model\\Company',
'ProfileImage' => 'SilverStripe\\Assets\\Image'
2015-12-17 21:20:49 +01:00
);
2015-12-17 21:20:49 +01:00
private static $belongs_many_many = array(
'PastCompanies' => 'SilverStripe\\FrameworkTest\\Model\\Company'
2015-12-17 21:20:49 +01:00
);
2016-07-20 00:35:01 +02:00
private static $table_name = 'Employee';
2015-12-17 21:20:49 +01:00
public function getCMSFields()
{
// Use basic scaffolder (no tabs)
$fields = $this->scaffoldFormFields();
$fields->push(new NumericField('ManyMany[YearStart]', 'Year started (3.1, many-many only)'));
$fields->push(new TextField('ManyMany[Role]', 'Role (3.1, many-many only)'));
2015-12-17 21:20:49 +01:00
return $fields;
}
2015-12-17 21:20:49 +01:00
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
$employeeSet = DataObject::get('SilverStripe\\FrameworkTest\\Model\\Employee');
2015-12-17 21:20:49 +01:00
foreach ($employeeSet as $employee) {
$employee->delete();
}
2015-12-17 21:20:49 +01:00
foreach ($this->data() as $employeeName) {
$employee = new Employee();
$employee->Name = $employeeName;
$employee->write();
}
DB::alteration_message("Added default records to Employee table", "created");
}
2015-12-17 21:20:49 +01:00
public function validate()
{
$result = parent::validate();
if (!$this->Name) {
$result->error('"Name" can\'t be blank');
}
return $result;
}
2015-12-17 21:20:49 +01:00
/**
* Contains test data
*
* @return array
*/
public function data()
{
return array(
'Hayley', 'Octavius', 'Walker', 'Gary','Elton','Janna','Ursa','Lars','Moses','Lareina',
'Elmo','Cara','Shea','Duncan','Velma','Acton','Galena','Heidi','Troy','Elliott','Cara',
'Whitney','Summer','Olga','Tatum','Zeph','Jared','Hilda','Quinlan','Chaim','Xenos',
'Cara','Tatiana','Tyrone','Juliet','Chester','Hannah','Imani','Quinn','Ariel','Abel',
'Aretha','Courtney ','Shellie','Garrett','Camilla','Simon','Mohammad','Kirby','Rae',
'Xena','Noel','Omar','Shannon','Iola','Maia','Serina','Taylor','Alice','Lucy','Austin',
'Abel','Quinn','Yetta','Ulysses','Donovan','Castor','Emmanuel','Nero','Virginia',
'Gregory','Neville','Abel','Len','Knox','Gavin','Pascale','Hyatt','Alden','Emerald',
'Cherokee','Zeph','Adam','Uma','Serena','Isabelle','Kieran','Moses','Gay','Lavinia',
'Elvis','Illana','Lee','Ariana','Hilel','Juliet','Gage','Larissa','Richard','Allen'
);
}
}