Commit 33a01ca1 authored by lphuberdeau's avatar lphuberdeau

[MOD] Extracting computed field

parent 6cabd88a
......@@ -64,4 +64,28 @@ class Tracker_Field_Computed extends Tracker_Field_Abstract
{
return $this->renderOutput($context);
}
function handleSave($value, $oldValue)
{
return array(
'value' => false,
);
}
public static function computeFields($args)
{
$trklib = TikiLib::lib('trk');
$definition = Tracker_Definition::get($args['trackerId']);
foreach ($definition->getFields() as $field) {
$fieldId = $field['fieldId'];
if ($field['type'] == 'C') {
$calc = preg_replace('/#([0-9]+)/', '$args[\'values\'][\1]', $field['options'][0]);
eval('$value = '.$calc.';');
$args['values'][$fieldId] = $value;
$trklib->modify_field($args['itemId'], $fieldId, $value);
}
}
}
}
......@@ -43,6 +43,10 @@ if ($prefs['feature_trackers'] == 'y') {
$events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'update_create_missing_pages'));
if ($prefs['tracker_field_computed'] == 'y') {
$events->bind('tiki.trackeritem.save', array('Tracker_Field_Computed', 'computeFields'));
}
$events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'update_tracker_summary'));
$events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'invalidate_item_cache'));
}
......
......@@ -1492,11 +1492,7 @@ class TrackerLib extends TikiLib
}
$value = isset($array["value"]) ? $array["value"] : null;
if ($array['type'] == 'C') {
$calc = preg_replace('/#([0-9]+)/', '$fil[\1]', $array['options']);
eval('$value = '.$calc.';');
} elseif ($array["type"] == 'q') {
if ($array["type"] == 'q') {
if (isset($array['options_array'][3]) && $array['options_array'][3] == 'itemId') {
$value = $currentItemId;
} elseif ($itemId == false) {
......@@ -1608,7 +1604,7 @@ class TrackerLib extends TikiLib
return $itemId;
}
private function modify_field($itemId, $fieldId, $value, $language = null)
function modify_field($itemId, $fieldId, $value, $language = null)
{
$conditions = array(
'itemId' => (int) $itemId,
......
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