diff --git a/checklistapi.pages.inc b/checklistapi.pages.inc index 9eba87a1daff2562172c3d105266a5bf35880744..6bb28953006b33b28cb635d1935b877a5301474f 100644 --- a/checklistapi.pages.inc +++ b/checklistapi.pages.inc @@ -96,7 +96,7 @@ function checklistapi_checklist_form($form, &$form_state, $id) { foreach ($item_keys as $item_key) { $item = &$group[$item_key]; // Set default value. - $saved_item = !empty($checklist->savedProgress[$group_key][$item_key]) ? $checklist->savedProgress[$group_key][$item_key] : 0; + $saved_item = !empty($checklist->savedProgress[$item_key]) ? $checklist->savedProgress[$item_key] : 0; $default_value = FALSE; if ($saved_item) { $default_value = TRUE; diff --git a/lib/Drupal/checklistapi/ChecklistapiChecklist.php b/lib/Drupal/checklistapi/ChecklistapiChecklist.php index 94b2638e85a79bbdd85bc64f6f4226f4cc2c55b6..e46dc89df13765ac0c28df4a8588a007ea7d11f3 100644 --- a/lib/Drupal/checklistapi/ChecklistapiChecklist.php +++ b/lib/Drupal/checklistapi/ChecklistapiChecklist.php @@ -140,18 +140,21 @@ class ChecklistapiChecklist { public function saveProgress(array $values) { global $user; $time = time(); - $completed_items_counter = 0; $changed_items_counter = 0; + $progress = array( + '#changed' => $time, + '#changed_by' => $user->uid, + '#completed_items' => 0, + ); // Loop through groups. foreach ($values as $group_key => $group) { // Loop through items. if (is_array($group)) { foreach ($group as $item_key => $item) { - $old_item = (!empty($this->savedProgress[$group_key][$item_key])) ? $this->savedProgress[$group_key][$item_key] : 0; - $new_item = &$values[$group_key][$item_key]; + $old_item = (!empty($this->savedProgress[$item_key])) ? $this->savedProgress[$item_key] : 0; if ($item == 1) { // Item is checked. - $completed_items_counter++; + $progress['#completed_items']++; if ($old_item) { // Item was previously checked. Use saved value. $new_item = $old_item; @@ -167,19 +170,16 @@ class ChecklistapiChecklist { } else { // Item is unchecked. + $new_item = 0; if ($old_item) { // Item was previously checked. $changed_items_counter++; } } + $progress[$item_key] = $new_item; } } } - $progress = array( - '#changed' => $time, - '#changed_by' => $user->uid, - '#completed_items' => $completed_items_counter, - ) + $values; variable_set($this->getSavedProgressVariableName(), $progress); drupal_set_message(format_plural( $changed_items_counter,