From 480083ac6cda7b5ff6f243c690bb94308d3b26fb Mon Sep 17 00:00:00 2001 From: Yarosalv Andryushchenkov <7098013@gmail.com> Date: Fri, 13 Jun 2014 11:12:30 +0000 Subject: [PATCH] Adding metrics and elements bug fixed --- amcr/amcr.admin.inc | 56 +++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/amcr/amcr.admin.inc b/amcr/amcr.admin.inc index 28a73ce..4ec5236 100644 --- a/amcr/amcr.admin.inc +++ b/amcr/amcr.admin.inc @@ -271,17 +271,31 @@ function _amcr_elements_list(&$form_state = NULL, $report_elements) { $delta = 0; $weight = 0; - foreach ($report_elements as $item) { - $form['items'][$item->id] = _amcr_element_form($item); - $delta++; - if($item->weight > $weight) { - $weight = $item->weight; + + if(isset($form_state['values']['elements']['add'])) { + foreach ($form_state['values']['elements']['items'] as $key => $element) { + $item = new stdClass(); + $item->element_id = $element['id']; + $item->weight = $element['weight']; + $form['items'][$key] = _amcr_element_form($item); + $delta++; + if($item->weight > $weight) { + $weight = $item->weight; + } + } + } else { + foreach ($report_elements as $item) { + $form['items'][$item->id] = _amcr_element_form($item); + $delta++; + if($item->weight > $weight) { + $weight = $item->weight; + } } } - $existing_delta = $delta; + for ($delta; $delta < $elements_count; $delta++) { - $key = 'new:' . ($delta - $existing_delta); + $key = 'new:' . $delta; $weight++; $item = new stdClass(); $item->weight = $weight; @@ -342,17 +356,31 @@ function _amcr_metrics_list(&$form_state = NULL, $report_metrics) { $delta = 0; $weight = 0; - foreach ($report_metrics as $item) { - $form['items'][$item->id] = _amcr_metric_form($item); - $delta++; - if($item->weight > $weight) { - $weight = $item->weight; + if(isset($form_state['values']['metrics']['add'])) { + foreach ($form_state['values']['metrics']['items'] as $key => $metric) { + $item = new stdClass(); + $item->metric_id = $metric['id']; + $item->weight = $metric['weight']; + $form['items'][$key] = _amcr_metric_form($item); + $delta++; + if($item->weight > $weight) { + $weight = $item->weight; + } } } + else { + foreach ($report_metrics as $item) { + $form['items'][$item->id] = _amcr_metric_form($item); + $delta++; + if($item->weight > $weight) { + $weight = $item->weight; + } + } + } + - $existing_delta = $delta; for ($delta; $delta < $metrics_count; $delta++) { - $key = 'new:' . ($delta - $existing_delta); + $key = 'new:' . $delta; $weight++; $item = new stdClass(); $item->weight = $weight;