2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
* Text field that automatically checks that the value entered is unique for the given
|
|
|
|
* set of fields in a given set of tables
|
2008-10-16 15:44:20 +02:00
|
|
|
* @deprecated 2.3
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-formattedinput
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class UniqueTextField extends TextField {
|
|
|
|
|
|
|
|
protected $restrictedField;
|
|
|
|
protected $restrictedTable;
|
|
|
|
protected $restrictedMessage;
|
|
|
|
|
|
|
|
function __construct($name, $restrictedField, $restrictedTable, $restrictedMessage, $title = null, $value = "", $maxLength = null ){
|
|
|
|
$this->maxLength = $maxLength;
|
|
|
|
|
|
|
|
$this->restrictedField = $restrictedField;
|
|
|
|
|
|
|
|
$this->restrictedTable = $restrictedTable;
|
|
|
|
$this->restrictedMessage = $restrictedMessage;
|
|
|
|
|
|
|
|
parent::__construct($name, $title, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Field() {
|
2009-03-10 23:08:52 +01:00
|
|
|
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
|
2009-11-21 03:31:44 +01:00
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/jquery/jquery.js");
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/UniqueFields.js");
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
$restrictedValues = array();
|
|
|
|
$restrictedInputs = array();
|
|
|
|
|
|
|
|
// if the restrictedFields and tables have been specified,
|
|
|
|
// then get the restricted values
|
|
|
|
if( !empty( $this->restrictedField ) && !empty( $this->restrictedTable ) ) {
|
2008-11-23 01:31:06 +01:00
|
|
|
$result = DB::query("SELECT \"{$this->restrictedField}\" FROM \"{$this->restrictedTable}\"");
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
$count = 1;
|
|
|
|
|
|
|
|
while( $restrictedValue = $result->nextRecord() )
|
|
|
|
$restrictedValues[$restrictedValue[$this->restrictedField]] = 1;
|
|
|
|
|
2008-11-23 01:31:06 +01:00
|
|
|
$result = DB::query("SELECT \"{$this->restrictedField}\" FROM \"{$this->restrictedTable}_Live\"");
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
while( $restrictedValue = $result->nextRecord() )
|
|
|
|
$restrictedValues[$restrictedValue[$this->restrictedField]] = 1;
|
|
|
|
|
|
|
|
// remove the initial value of this field
|
|
|
|
$restrictedValues = array_diff_assoc( $restrictedValues, array( $this->attrValue() => 1 ) );
|
|
|
|
|
|
|
|
foreach( $restrictedValues as $restrictedValue => $discard )
|
|
|
|
$restrictedInputs[] = "<input type=\"hidden\" id=\"".$this->id()."-restricted-".($count++)."\" value=\"$restrictedValue\" name=\"restricted-values[".$this->id()."]\" />";
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2007-09-16 04:00:59 +02:00
|
|
|
$fieldSize = $this->maxLength ? min( $this->maxLength, 30 ) : 30;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if($this->maxLength){
|
2007-09-16 04:00:59 +02:00
|
|
|
return /*implode("", $restrictedInputs).*/"<input class=\"".$this->class."\" type=\"text\" id=\"" . $this->id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" maxlength=\"$this->maxLength\" size=\"$fieldSize\" /><input type=\"hidden\" name=\"restricted-messages[".$this->id()."]\" id=\"".$this->id()."-restricted-message\" value=\"{$this->restrictedMessage}\" />";
|
2007-07-19 12:40:28 +02:00
|
|
|
}else{
|
2007-09-16 04:00:59 +02:00
|
|
|
return /*implode("", $restrictedInputs).*/"<input class=\"".$this->class."\" type=\"text\" id=\"" . $this->id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" size=\"30\" /><input type=\"hidden\" name=\"restricted-messages[".$this->id()."]\" id=\"".$this->id()."-restricted-message\" value=\"{$this->restrictedMessage}\" />";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|