Skip to content

Commit

Permalink
Adding metrics and elements bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaroslav-Andryushchenkov committed Jun 13, 2014
1 parent 60c8839 commit 480083a
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions amcr/amcr.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 480083a

Please sign in to comment.