FIX use sqlquery for building sort query

This commit is contained in:
Will Rossiter 2013-03-05 11:36:39 +13:00
parent c4c547321c
commit 75fb471f2c

View File

@ -182,23 +182,31 @@ class FieldEditor extends FormField {
if($parentID) {
$parentID = Convert::raw2sql($parentID);
$highestSort = DB::query("SELECT MAX(\"Sort\") FROM \"EditableFormField\" WHERE \"ParentID\" = '$parentID'");
$sqlQuery = new SQLQuery();
$sqlQuery = $sqlQuery
->setSelect('MAX(Sort)')
->setFrom("EditableFormField")
->setWhere("ParentID = $parentID");
$sort = $highestSort->value() + 1;
$sort = $sqlQuery->execute()->value() + 1;
$className = (isset($_REQUEST['Type'])) ? $_REQUEST['Type'] : '';
if(!$className) user_error('Please select a field type to created', E_USER_WARNING);
if(!$className) {
user_error('Please select a field type to created', E_USER_WARNING);
}
if(is_subclass_of($className, "EditableFormField")) {
$field = new $className();
$field->write();
$field->ParentID = $this->form->getRecord()->ID;
$field->Name = $field->class . $field->ID;
$field->Sort = $sort;
$field->write();
return $field->EditSegment();
}
}
return false;
}
@ -216,9 +224,13 @@ class FieldEditor extends FormField {
if($parent) {
$sql_parent = Convert::raw2sql($parent);
$highestSort = DB::query("SELECT MAX(\"Sort\") FROM \"EditableOption\" WHERE \"ParentID\" = '$sql_parent'");
$sqlQuery = new SQLQuery();
$sqlQuery = $sqlQuery
->setSelect('MAX(Sort)')
->setFrom("EditableOption")
->setWhere("ParentID = $sql_parent");
$sort = $highestSort->value() + 1;
$sort = $sqlQuery->execute()->value() + 1;
if($parent) {
$object = new EditableOption();
@ -227,9 +239,11 @@ class FieldEditor extends FormField {
$object->Sort = $sort;
$object->Name = 'option' . $object->ID;
$object->write();
return $object->EditSegment();
}
}
return false;
}
}