| @@ -35,8 +35,28 @@ | ||
| 35 | 35 | ->where('key', Constant::FLUENT_BOARD_ADMIN) |
| 36 | 36 | ->first(); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | + private function getDefaultGlobalNotificationSettings() | |
| 40 | + { | |
| 41 | + return [ | |
| 42 | + Constant::GLOBAL_EMAIL_NOTIFICATION_COMMENT => true, | |
| 43 | + Constant::GLOBAL_EMAIL_NOTIFICATION_STAGE_CHANGE => true, | |
| 44 | + Constant::GLOBAL_EMAIL_NOTIFICATION_TASK_ASSIGN => true, | |
| 45 | + Constant::GLOBAL_EMAIL_NOTIFICATION_DUE_DATE => true, | |
| 46 | + Constant::GLOBAL_EMAIL_NOTIFICATION_REMOVE_FROM_TASK => true, | |
| 47 | + Constant::GLOBAL_EMAIL_NOTIFICATION_TASK_ARCHIVE => true, | |
| 48 | + Constant::GLOBAL_EMAIL_NOTIFICATION_CREATING_TASK => true, | |
| 49 | + Constant::GLOBAL_EMAIL_NOTIFICATION_COMMENTING => true, | |
| 50 | + Constant::GLOBAL_EMAIL_NOTIFICATION_ASSIGNING => true | |
| 51 | + ]; | |
| 52 | + } | |
| 53 | + | |
| 54 | + private function normalizeNotificationPreferenceValue($value) | |
| 55 | + { | |
| 56 | + return true === $value || 1 === $value || '1' === $value || 'true' === $value; | |
| 57 | + } | |
| 58 | + | |
| 39 | 59 | public function updateGlobalNotificationSettings($newSettings) |
| 40 | 60 | { |
| 41 | 61 | $userId = get_current_user_id(); |
| 42 | 62 | |
| @@ -44,13 +64,17 @@ | ||
| 44 | 64 | ->where('object_type', Constant::OBJECT_TYPE_USER) |
| 45 | 65 | ->where('key', Constant::USER_GLOBAL_NOTIFICATIONS) |
| 46 | 66 | ->first(); |
| 47 | 67 | |
| 48 | - foreach ($newSettings as $index => $setting) | |
| 49 | - { | |
| 50 | - $newSettings[$index] = $setting == 'true' ? true : false; | |
| 68 | + $allowedSettings = $this->getDefaultGlobalNotificationSettings(); | |
| 69 | + $newSettings = array_intersect_key($newSettings, $allowedSettings); | |
| 70 | + $filteredSettings = []; | |
| 71 | + foreach ($newSettings as $index => $setting) { | |
| 72 | + $filteredSettings[$index] = $this->normalizeNotificationPreferenceValue($setting); | |
| 51 | 73 | } |
| 52 | 74 | |
| 75 | + $newSettings = array_merge($allowedSettings, $filteredSettings); | |
| 76 | + | |
| 53 | 77 | $globalNotification->value = $newSettings; |
| 54 | 78 | $globalNotification->save(); |
| 55 | 79 | |
| 56 | 80 | //set this settings to all board |
| @@ -70,16 +94,9 @@ | ||
| 70 | 94 | ->where('key', Constant::USER_GLOBAL_NOTIFICATIONS) |
| 71 | 95 | ->first(); |
| 72 | 96 | |
| 73 | 97 | //default notification settings |
| 74 | - $newSettingsArray = [ | |
| 75 | - Constant::GLOBAL_EMAIL_NOTIFICATION_COMMENT => true, | |
| 76 | - Constant::GLOBAL_EMAIL_NOTIFICATION_STAGE_CHANGE => true, | |
| 77 | - Constant::GLOBAL_EMAIL_NOTIFICATION_TASK_ASSIGN => true, | |
| 78 | - Constant::GLOBAL_EMAIL_NOTIFICATION_DUE_DATE => true, | |
| 79 | - Constant::GLOBAL_EMAIL_NOTIFICATION_REMOVE_FROM_TASK => true, | |
| 80 | - Constant::GLOBAL_EMAIL_NOTIFICATION_TASK_ARCHIVE => true, | |
| 81 | - ]; | |
| 98 | + $newSettingsArray = $this->getDefaultGlobalNotificationSettings(); | |
| 82 | 99 | |
| 83 | 100 | //if no settings found of this user then store default |
| 84 | 101 | if(!$globalNotification) { |
| 85 | 102 | $meta = new Meta(); |
| @@ -91,8 +108,23 @@ | ||
| 91 | 108 | |
| 92 | 109 | return $meta; |
| 93 | 110 | } |
| 94 | 111 | |
| 112 | + $storedSettings = maybe_unserialize($globalNotification->value); | |
| 113 | + if (is_array($storedSettings)) { | |
| 114 | + $filteredSettings = array_merge($newSettingsArray, array_intersect_key($storedSettings, $newSettingsArray)); | |
| 115 | + foreach ($filteredSettings as $index => $setting) { | |
| 116 | + $filteredSettings[$index] = $this->normalizeNotificationPreferenceValue($setting); | |
| 117 | + } | |
| 118 | + | |
| 119 | + if ($filteredSettings !== $storedSettings) { | |
| 120 | + $globalNotification->value = $filteredSettings; | |
| 121 | + $globalNotification->save(); | |
| 122 | + } else { | |
| 123 | + $globalNotification->value = $filteredSettings; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 95 | 127 | return $globalNotification; |
| 96 | 128 | } |
| 97 | 129 | |
| 98 | 130 | public function getDashboardViewSettings() |
| @@ -104,23 +136,13 @@ | ||
| 104 | 136 | ->first(); |
| 105 | 137 | |
| 106 | 138 | //if no settings found of this user then store default |
| 107 | 139 | if(!$dshboardViewSettings) { |
| 108 | - //default notification settings | |
| 109 | - $newSettingsArray = [ | |
| 110 | - 'dashboard_view_label' => true, | |
| 111 | - 'dashboard_view_priority' => true, | |
| 112 | - 'dashboard_view_assignee' => true, | |
| 113 | - 'dashboard_view_subtask' => true, | |
| 114 | - 'dashboard_view_due_date' => true, | |
| 115 | - 'dashboard_view_comment' => true | |
| 116 | - ]; | |
| 117 | - | |
| 118 | 140 | $meta = new Meta(); |
| 119 | 141 | $meta->object_id = $userId; |
| 120 | 142 | $meta->object_type = Constant::OBJECT_TYPE_USER; |
| 121 | 143 | $meta->key = Constant::USER_DASHBOARD_VIEW; |
| 122 | - $meta->value = $newSettingsArray; | |
| 144 | + $meta->value = Constant::DEFAULT_DASHBOARD_VIEW_PREFERENCES; | |
| 123 | 145 | $meta->save(); |
| 124 | 146 | |
| 125 | 147 | return $meta; |
| 126 | 148 | } |
| @@ -126,22 +148,74 @@ | ||
| 126 | 148 | } |
| 127 | 149 | |
| 128 | 150 | return $dshboardViewSettings; |
| 129 | 151 | } |
| 130 | - public function updateDashboardViewSettings($newSettings) | |
| 152 | + | |
| 153 | + public function getListViewPreferences() | |
| 131 | 154 | { |
| 132 | 155 | $userId = get_current_user_id(); |
| 156 | + $dshboardViewSettings = Meta::where('object_id', $userId) | |
| 157 | + ->where('object_type', Constant::OBJECT_TYPE_USER) | |
| 158 | + ->where('key', Constant::USER_LISTVIEW_PREFERENCES) | |
| 159 | + ->first(); | |
| 160 | + //if no settings found of this user then store default | |
| 161 | + if(!$dshboardViewSettings) { | |
| 162 | + $meta = new Meta(); | |
| 163 | + $meta->object_id = $userId; | |
| 164 | + $meta->object_type = Constant::OBJECT_TYPE_USER; | |
| 165 | + $meta->key = Constant::USER_LISTVIEW_PREFERENCES; | |
| 166 | + $meta->value = Constant::DEFAULT_DASHBOARD_VIEW_PREFERENCES; | |
| 167 | + $meta->save(); | |
| 133 | 168 | |
| 169 | + return $meta; | |
| 170 | + } | |
| 171 | + | |
| 172 | + return $dshboardViewSettings; | |
| 173 | + } | |
| 174 | + public function updateDashboardViewSettings($newSettings, $view) | |
| 175 | + { | |
| 176 | + $userId = get_current_user_id(); | |
| 177 | + | |
| 178 | + if ($view == 'listview') { | |
| 179 | + $viewWiseKey = Constant::USER_LISTVIEW_PREFERENCES; | |
| 180 | + } elseif ($view == 'tableview') { | |
| 181 | + $viewWiseKey = Constant::USER_TABLEVIEW_PREFERENCES; | |
| 182 | + } else { | |
| 183 | + $viewWiseKey = Constant::USER_DASHBOARD_VIEW; | |
| 184 | + } | |
| 185 | + | |
| 134 | 186 | $dshboardViewSettings = Meta::where('object_id', $userId) |
| 135 | 187 | ->where('object_type', Constant::OBJECT_TYPE_USER) |
| 136 | - ->where('key', Constant::USER_DASHBOARD_VIEW) | |
| 188 | + ->where('key', $viewWiseKey) | |
| 137 | 189 | ->first(); |
| 138 | - | |
| 190 | + | |
| 139 | 191 | foreach ($newSettings as $index => $setting) |
| 140 | 192 | { |
| 141 | 193 | $newSettings[$index] = $setting == 'true' ? true : false; |
| 142 | 194 | } |
| 143 | - | |
| 195 | + | |
| 144 | 196 | $dshboardViewSettings->value = $newSettings; |
| 145 | 197 | $dshboardViewSettings->save(); |
| 198 | + } | |
| 199 | + | |
| 200 | + // Add this new method | |
| 201 | + public function getTableViewPreferences() | |
| 202 | + { | |
| 203 | + $userId = get_current_user_id(); | |
| 204 | + $tableViewSettings = Meta::where('object_id', $userId) | |
| 205 | + ->where('object_type', Constant::OBJECT_TYPE_USER) | |
| 206 | + ->where('key', Constant::USER_TABLEVIEW_PREFERENCES) | |
| 207 | + ->first(); | |
| 208 | + if (!$tableViewSettings) { | |
| 209 | + $meta = new Meta(); | |
| 210 | + $meta->object_id = $userId; | |
| 211 | + $meta->object_type = Constant::OBJECT_TYPE_USER; | |
| 212 | + $meta->key = Constant::USER_TABLEVIEW_PREFERENCES; | |
| 213 | + $meta->value = Constant::DEFAULT_TABLEVIEW_VIEW_PREFERENCES; | |
| 214 | + $meta->save(); | |
| 215 | + | |
| 216 | + return $meta; | |
| 217 | + } | |
| 218 | + | |
| 219 | + return $tableViewSettings; | |
| 146 | 220 | } |
| 147 | 221 | } |