2008-08-11 01:17:51 +02:00
|
|
|
<?php
|
2015-08-27 23:07:55 +02:00
|
|
|
|
2015-08-30 07:02:55 +02:00
|
|
|
namespace SilverStripe\Model\FieldType;
|
|
|
|
|
|
|
|
use DataList;
|
|
|
|
use DropdownField;
|
|
|
|
use DB;
|
|
|
|
use DataObject;
|
2015-08-27 23:07:55 +02:00
|
|
|
|
2008-08-11 01:17:51 +02:00
|
|
|
/**
|
|
|
|
* A special type Int field used for primary keys.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-08-11 01:17:51 +02:00
|
|
|
* @todo Allow for custom limiting/filtering of scaffoldFormField dropdown
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-03-22 23:59:14 +01:00
|
|
|
* @subpackage model
|
2008-08-11 01:17:51 +02:00
|
|
|
*/
|
2015-08-30 07:02:55 +02:00
|
|
|
class DBPrimaryKey extends DBInt {
|
2008-08-11 01:17:51 +02:00
|
|
|
/**
|
2014-08-15 08:53:05 +02:00
|
|
|
* @var DataObject
|
2008-08-11 01:17:51 +02:00
|
|
|
*/
|
|
|
|
protected $object;
|
2008-08-11 01:29:30 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $default_search_filter_class = 'ExactMatchFilter';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2015-09-10 05:46:23 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $autoIncrement = true;
|
|
|
|
|
|
|
|
public function setAutoIncrement($autoIncrement) {
|
|
|
|
$this->autoIncrement = $autoIncrement;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAutoIncrement() {
|
|
|
|
return $this->autoIncrement;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requireField() {
|
|
|
|
$spec = DB::get_schema()->IdColumn(false, $this->getAutoIncrement());
|
|
|
|
DB::require_field($this->getTable(), $this->getName(), $spec);
|
|
|
|
}
|
|
|
|
|
2009-03-22 23:59:14 +01:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param DataOject $object The object that this is primary key for (should have a relation with $name)
|
|
|
|
*/
|
2015-09-04 05:49:22 +02:00
|
|
|
public function __construct($name, $object = null) {
|
2008-08-11 01:17:51 +02:00
|
|
|
$this->object = $object;
|
|
|
|
parent::__construct($name);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-10-14 00:20:41 +02:00
|
|
|
public function scaffoldFormField($title = null, $params = null) {
|
2015-09-10 05:46:23 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scaffoldSearchField($title = null) {
|
|
|
|
parent::scaffoldFormField($title);
|
2008-08-11 01:17:51 +02:00
|
|
|
}
|
|
|
|
|
2015-09-04 05:49:22 +02:00
|
|
|
public function setValue($value, $record = null, $markChanged = true) {
|
|
|
|
parent::setValue($value, $record, $markChanged);
|
|
|
|
|
|
|
|
if($record instanceof DataObject) {
|
|
|
|
$this->object = $record;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|