PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.1.0
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.1.0
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
← All changes | app/Services/LabelService.php +106 -20 1.95.22.1.0 View file →
@@ -16,26 +16,48 @@
16 16 }
17 17
18 18 public function getLabelsByBoardUsedInTasks($boardId)
19 19 {
20 - $boardLabel = Label::where('board_id', $boardId)->where('type', 'label')->orderBy('created_at', 'ASC')->get();
20 + $boardLabels = Label::where('board_id', $boardId)
21 + ->where('type', 'label')
22 + ->orderBy('created_at', 'ASC')
23 + ->get();
24 +
25 + if ($boardLabels->isEmpty()) {
26 + return [];
27 + }
28 +
29 + // One relation query for the whole board rather than an exists() per label.
30 + $usedIds = Relation::where('object_type', Constant::OBJECT_TYPE_TASK_LABEL)
31 + ->whereIn('foreign_id', $boardLabels->pluck('id')->all())
32 + ->distinct()
33 + ->pluck('foreign_id')
34 + ->all();
35 +
36 + $usedIds = array_map('intval', $usedIds);
37 +
21 38 $usedLabel = [];
22 - foreach ($boardLabel as $label) {
23 - $exist = Relation::where('foreign_id', $label->id)->where('object_type', 'task_label')->exists();
24 - if ($exist) {
39 + foreach ($boardLabels as $label) {
40 + if (in_array((int) $label->id, $usedIds, true)) {
25 41 $usedLabel[] = $label;
26 42 }
27 43 }
44 +
28 45 return $usedLabel;
29 46 }
30 47
31 48 public function createLabel($labelData, $boardId)
32 49 {
50 + $labelData = $this->normalizeLabelColorData($labelData);
51 +
33 52 $label = new Label();
34 53 $label->board_id = $boardId;
35 - $label->title = $labelData['label'];
36 - $label->bg_color = $labelData['bg_color'];
37 - $label->color = $labelData['color'];
54 + $label->title = $labelData['label'] ?? '';
55 + $label->bg_color = $labelData['bg_color'] ?? '';
56 + $label->color = $labelData['color'] ?? '';
57 + if (isset($labelData['settings'])) {
58 + $label->settings = $labelData['settings'];
59 + }
38 60 $label->save();
39 61
40 62 return $label;
41 63 }
@@ -41,26 +63,26 @@
41 63 }
42 64
43 65 public function createDefaultLabel($boardId)
44 66 {
45 - $defaultColors = [
46 - "green" => "#4bce97",
47 - "yellow" => "#f5cd47",
48 - "orange" => "#fea362",
49 - "red" => "#f87168",
50 - "purple" => "#9f8fef"
51 - ];
67 + $defaultColors = ['green-bold', 'yellow-bold', 'orange-bold', 'red-bold', 'purple-bold'];
52 68
53 69 $data = [];
54 70
55 - foreach ($defaultColors as $index => $bg_color)
71 + foreach ($defaultColors as $presetId)
56 72 {
73 + $preset = Constant::getLabelColorPreset($presetId);
74 + $colorName = strtok($presetId, '-');
57 75 $data[] = [
58 76 'board_id' => $boardId,
59 - 'slug' => $index,
77 + // Titles match the create-board modal defaults, otherwise boards created
78 + // outside that modal end up with colour chips carrying no text.
79 + 'title' => ucfirst($colorName),
80 + 'slug' => $colorName,
60 81 'type' => 'label',
61 - 'bg_color' => $bg_color,
62 - 'color' => Constant::TEXT_COLOR_MAP[$index],
82 + 'bg_color' => $preset['light_bg_color'],
83 + 'color' => $preset['light_text_color'],
84 + 'settings' => maybe_serialize([Constant::LABEL_COLOR_PRESET_SETTING => $presetId]),
63 85 'created_at' => current_time('mysql'),
64 86 'updated_at' => current_time('mysql')
65 87 ];
66 88 }
@@ -112,13 +134,29 @@
112 134
113 135 public function editLabelofBoard($labelData, $id, $boardId = null)
114 136 {
115 137 $label = $boardId ? $this->findLabelOnBoard($id, $boardId) : Label::findOrFail($id);
116 - $label->title = $labelData['label'];
117 - if ($label->bg_color != $labelData['bg_color']) {
138 + $labelData = $this->normalizeLabelColorData($labelData, $label);
139 + $label->title = $labelData['label'] ?? $label->title;
140 +
141 + // Background and text colour move independently: coupling them dropped a
142 + // text-colour-only change on the floor while still reporting success.
143 + if (isset($labelData['bg_color']) && $labelData['bg_color'] !== '') {
118 144 $label->bg_color = $labelData['bg_color'];
145 + }
146 +
147 + if (isset($labelData['color']) && $labelData['color'] !== '') {
119 148 $label->color = $labelData['color'];
120 149 }
150 +
151 + if (array_key_exists('settings', $labelData)) {
152 + if (array_key_exists('color_preset', $labelData) && $labelData['color_preset'] === '') {
153 + $label->replaceSettings($labelData['settings']);
154 + } else {
155 + $label->settings = $labelData['settings'];
156 + }
157 + }
158 +
121 159 $label->save();
122 160 return $label;
123 161 }
124 162
@@ -159,13 +197,61 @@
159 197 $labelToSave['type'] = 'label';
160 198 $labelToSave['position'] = 0;
161 199 $labelToSave['color'] = $label->color;
162 200 $labelToSave['bg_color'] = $label->bg_color;
201 + $settings = (array) $label->settings;
202 + $presetId = $settings[Constant::LABEL_COLOR_PRESET_SETTING] ?? '';
203 + if (Constant::getLabelColorPreset($presetId)) {
204 + $labelToSave['settings'] = [Constant::LABEL_COLOR_PRESET_SETTING => $presetId];
205 + }
163 206 $copiedLabel = Label::create($labelToSave);
164 207
165 208 $labelMap[$label['id']] = $copiedLabel->id;
166 209 }
167 210 return $labelMap;
211 + }
212 +
213 + /**
214 + * Converts a selected preset into stable light-mode fallback colors.
215 + *
216 + * @param array $labelData
217 + * @param Label|null $label
218 + * @return array
219 + * @throws \Exception
220 + */
221 + private function normalizeLabelColorData($labelData, $label = null)
222 + {
223 + if (!array_key_exists('color_preset', $labelData)) {
224 + return $labelData;
225 + }
226 +
227 + $presetId = $labelData['color_preset'];
228 + $settings = $label ? (array) $label->settings : [];
229 +
230 + // Framework request extraction can represent an omitted optional field
231 + // as null. That must preserve an existing preset rather than reject it.
232 + if ($presetId === null) {
233 + unset($labelData['color_preset']);
234 + return $labelData;
235 + }
236 +
237 + if ($presetId === '') {
238 + unset($settings[Constant::LABEL_COLOR_PRESET_SETTING]);
239 + $labelData['settings'] = $settings;
240 + return $labelData;
241 + }
242 +
243 + $preset = Constant::getLabelColorPreset($presetId);
244 + if (!$preset) {
245 + throw new \Exception(esc_html__('Invalid label color preset', 'fluent-boards'));
246 + }
247 +
248 + $settings[Constant::LABEL_COLOR_PRESET_SETTING] = $preset['id'];
249 + $labelData['settings'] = $settings;
250 + $labelData['bg_color'] = $preset['light_bg_color'];
251 + $labelData['color'] = $preset['light_text_color'];
252 +
253 + return $labelData;
168 254 }
169 255 public function getLastOneMinuteUpdatedLabels($boardId, $lastUpdated = null, $includeArchived = true)
170 256 {
171 257 if (!$lastUpdated) {