mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
(merged from branches/roa. use "svn log -c <changeset> -g <module-svn-path>" for detailed commit message)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60203 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
37d3aa1695
commit
e25f44604f
@ -38,8 +38,10 @@ class RestfulServer extends Controller {
|
||||
ContentNegotiator::disable();
|
||||
|
||||
$requestMethod = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
if(!isset($this->urlParams['ClassName'])) return $this->notFound();
|
||||
$className = $this->urlParams['ClassName'];
|
||||
$id = $this->urlParams['ID'];
|
||||
$id = (isset($this->urlParams['ID'])) ? $this->urlParams['ID'] : null;
|
||||
|
||||
switch($requestMethod) {
|
||||
case 'GET':
|
||||
|
@ -334,7 +334,11 @@ class ViewableData extends Object implements IteratorAggregate {
|
||||
|
||||
if($constructor) {
|
||||
$fieldObj = eval($constructor);
|
||||
$fieldObj->setVal($val);
|
||||
if($this->hasMethod('getAllFields')) {
|
||||
$fieldObj->setVal($val, $this->getAllFields());
|
||||
} else {
|
||||
$fieldObj->setVal($val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -601,12 +601,15 @@ class DataObject extends ViewableData implements DataObjectInterface {
|
||||
}
|
||||
|
||||
// Divvy up field saving into a number of database manipulations
|
||||
$manipulation = array();
|
||||
if(isset($ancestry) && is_array($ancestry)) {
|
||||
foreach($ancestry as $idx => $class) {
|
||||
$classSingleton = singleton($class);
|
||||
foreach($this->record as $fieldName => $value) {
|
||||
foreach($this->record as $fieldName => $fieldValue) {
|
||||
if(isset($this->changed[$fieldName]) && $this->changed[$fieldName] && $fieldType = $classSingleton->fieldExists($fieldName)) {
|
||||
$manipulation[$class]['fields'][$fieldName] = $value ? ("'" . addslashes($value) . "'") : singleton($fieldType)->nullValue();
|
||||
$fieldObj = $this->obj($fieldName);
|
||||
if(!isset($manipulation[$class])) $manipulation[$class] = array();
|
||||
if($fieldObj) $fieldObj->writeToManipulation($manipulation[$class]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1487,7 +1490,7 @@ class DataObject extends ViewableData implements DataObjectInterface {
|
||||
$constructor = $helperPair['castingHelper'];
|
||||
|
||||
if($obj = eval($constructor)) {
|
||||
$obj->setVal($this->$fieldName);
|
||||
$obj->setVal($this->$fieldName, $this->record);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
@ -1562,6 +1565,11 @@ class DataObject extends ViewableData implements DataObjectInterface {
|
||||
foreach($tableClasses as $tableClass) {
|
||||
$query->from[$tableClass] = "LEFT JOIN `$tableClass` ON `$tableClass`.ID = `$baseClass`.ID";
|
||||
$query->select[] = "`$tableClass`.*";
|
||||
// ask each $db field on the specific table for alterations to the query
|
||||
$uninheritedDbFields = singleton($tableClass)->uninherited('db',true);
|
||||
if($uninheritedDbFields) foreach($uninheritedDbFields as $fieldName => $fieldType) {
|
||||
singleton($tableClass)->obj($fieldName)->addToQuery($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
$query->select[] = "`$baseClass`.ID";
|
||||
|
@ -38,14 +38,62 @@ abstract class DBField extends ViewableData {
|
||||
return $dbField;
|
||||
}
|
||||
|
||||
function setVal($value) {
|
||||
function setVal($value, $record = null) {
|
||||
return $this->setValue($value);
|
||||
}
|
||||
|
||||
function setValue($value) {
|
||||
/**
|
||||
* Set the value on the field.
|
||||
* Optionally takes the whole record as an argument,
|
||||
* to pick other values.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $record
|
||||
*/
|
||||
function setValue($value, $record = null) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the field has a value which
|
||||
* is not considered to be 'null' in
|
||||
* a database context.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function hasValue() {
|
||||
return ($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the current field for usage in a
|
||||
* database-manipulation (works on a manipulation reference).
|
||||
*
|
||||
* Make value safe for insertion into
|
||||
* a SQL SET statement by applying addslashes() -
|
||||
* can also be used to apply
|
||||
* special SQL-commands to the raw value
|
||||
* (e.g. for GIS functionality).
|
||||
*
|
||||
* @param array $manipulation
|
||||
*/
|
||||
function writeToManipulation(&$manipulation) {
|
||||
$manipulation['fields'][$this->name] = $this->hasValue() ? "'" . addslashes($this->value) . "'" : $this->nullValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom query parameters for this field,
|
||||
* mostly SELECT statements for multi-value fields.
|
||||
*
|
||||
* By default, the ORM layer does a
|
||||
* SELECT <tablename>.* which
|
||||
* gets you the default representations
|
||||
* of all columns.
|
||||
*
|
||||
* @param Query $query
|
||||
*/
|
||||
function addToQuery(&$query) {}
|
||||
|
||||
function setTable($tableName) {
|
||||
$this->tableName = $tableName;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage model
|
||||
*
|
||||
*/
|
||||
class Double extends DBField {
|
||||
|
||||
|
@ -13,6 +13,10 @@ class Text extends DBField {
|
||||
DB::requireField($this->tableName, $this->name, "mediumtext character set utf8 collate utf8_general_ci");
|
||||
}
|
||||
|
||||
function hasValue() {
|
||||
return ($this->value || $this->value == '0');
|
||||
}
|
||||
|
||||
//useed for search results show only limited contents
|
||||
function LimitWordCount($numWords = 26) {
|
||||
$this->value = Convert::xml2raw($this->value);
|
||||
|
@ -5,6 +5,7 @@
|
||||
* @subpackage model
|
||||
*/
|
||||
class Varchar extends DBField {
|
||||
|
||||
protected $size;
|
||||
|
||||
function __construct($name, $size = 50) {
|
||||
@ -14,6 +15,11 @@ class Varchar extends DBField {
|
||||
function requireField() {
|
||||
DB::requireField($this->tableName, $this->name, "varchar($this->size) character set utf8 collate utf8_general_ci");
|
||||
}
|
||||
|
||||
function hasValue() {
|
||||
return ($this->value || $this->value == '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first letter of the string followed by a .
|
||||
*/
|
||||
|
@ -590,7 +590,7 @@ class Form extends ViewableData {
|
||||
if($o || !isset($object[$name . '_unchanged'])) {
|
||||
// Second check was the original check: save the value if we have one
|
||||
if(isset($val) || $loadBlanks) {
|
||||
$field->setValue($val);
|
||||
$field->setValue($val, $object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user