Commit e04ba0aa authored by lphuberdeau's avatar lphuberdeau

[MOD] Extract auto-increment handling

parent 33a01ca1
......@@ -35,5 +35,24 @@ class Tracker_Field_AutoIncrement extends Tracker_Field_Abstract
{
return $this->renderTemplate('trackerinput/autoincrement.tpl', $context);
}
function handleSave($value, $oldValue)
{
$value = false;
if ($this->getOption(3) == 'itemId') {
$value = $this->getItemId();
} elseif (is_null($oldValue)) {
$value = TikiLib::lib('trk')->get_maximum_value($this->getConfiguration('fieldId'));
if (! $value) {
$value = $this->getOption(0, 1);
} else {
$value += 1;
}
}
return array(
'value' => $value,
);
}
}
......@@ -1492,18 +1492,6 @@ class TrackerLib extends TikiLib
}
$value = isset($array["value"]) ? $array["value"] : null;
if ($array["type"] == 'q') {
if (isset($array['options_array'][3]) && $array['options_array'][3] == 'itemId') {
$value = $currentItemId;
} elseif ($itemId == false) {
$value = $this->itemFields()->fetchOne($this->itemFields()->expr('MAX(CAST(`value` as UNSIGNED))'), array('fieldId' => (int) $fieldId));
if ($value == NULL) {
$value = isset($array['options_array'][0]) ? $array['options_array'][0] : 1;
} else {
$value += 1;
}
}
}
if ($array['type']=='*') {
$this->replace_star($array['value'], $trackerId, $itemId, $ins_fields['data'][$i], $user, false);
}
......@@ -4686,6 +4674,11 @@ class TrackerLib extends TikiLib
}
}
}
public function get_maximum_value($fieldId)
{
return $this->itemFields()->fetchOne($this->itemFields()->expr('MAX(CAST(`value` as UNSIGNED))'), array('fieldId' => (int) $fieldId));
}
}
global $trklib;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment