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/Models/Board.php +65 -12 1.412.1.0 View file →
@@ -1,14 +1,12 @@
1 1 <?php
2 2
3 3 namespace FluentBoards\App\Models;
4 4
5 -use FluentBoards\App\Services\BoardService;
6 5 use FluentBoards\App\Services\Constant;
7 6 use FluentBoards\App\Services\PermissionManager;
8 7 use FluentBoards\App\Services\UserService;
9 8 use FluentBoards\Framework\Database\Orm\Builder;
10 -use FluentBoards\Framework\Support\Arr;
11 9 use FluentBoardsPro\App\Models\CustomField;
12 10
13 11 class Board extends Model
14 12 {
@@ -34,14 +32,17 @@
34 32 ];
35 33
36 34 protected $appends = ['meta', 'isUserOnlyViewer'];
37 35
36 + /**
37 + * Boot board defaults while preserving empty backgrounds for newly created boards.
38 + */
38 39 public static function boot()
39 40 {
40 41 static::creating(function ($model) {
41 42 $model->created_by = $model->created_by ?: get_current_user_id();
42 43 $model->type = $model->type ?: 'to-do'; // default board type is to-do
43 - $model->background = $model->background ?: $model->randomBackground();
44 + $model->background = $model->background ?: '';
44 45 });
45 46 /* global scope for board type which means only type = to-do will be fetched from everywhere */
46 47 parent::boot();
47 48 static::addGlobalScope('type', function (Builder $builder) {
@@ -218,21 +219,49 @@
218 219 }
219 220
220 221 return $query->whereIn('id', $boardIds);
221 222 }
222 - private function randomBackground()
223 +
224 + /**
225 + * Exclude template boards (settings['is_template'] === true).
226 + * The settings column is serialized text, so both the PHP-serialized
227 + * and JSON representations of the flag are matched.
228 + */
229 + public function scopeExcludeTemplates($query)
223 230 {
224 - $solids = Constant::BOARD_BACKGROUND_DEFAULT_SOLID_COLORS;
225 - $solid = $solids[wp_rand(0, count($solids) - 1)];
231 + return $query->where(function ($query) {
232 + $query->whereNull('settings')
233 + ->orWhere(function ($subQuery) {
234 + $subQuery->where('settings', 'NOT LIKE', '%"is_template";b:1%')
235 + ->where('settings', 'NOT LIKE', '%"is_template":true%');
236 + });
237 + });
238 + }
226 239
227 - return [
228 - 'id' => $solid['id'],
229 - 'is_image' => false,
230 - 'image_url' => null,
231 - 'color' => $solid['value']
232 - ];
240 + /**
241 + * Limit boards to types supported by the currently loaded plugins.
242 + */
243 + public function scopeAvailableInCurrentInstall($query)
244 + {
245 + if (!defined('FLUENT_ROADMAP')) {
246 + return $query->where('type', 'to-do');
247 + }
248 +
249 + return $query;
233 250 }
234 251
252 + /**
253 + * Only template boards (inverse of scopeExcludeTemplates).
254 + */
255 + public function scopeOnlyTemplates($query)
256 + {
257 + return $query->whereNotNull('settings')
258 + ->where(function ($subQuery) {
259 + $subQuery->where('settings', 'LIKE', '%"is_template";b:1%')
260 + ->orWhere('settings', 'LIKE', '%"is_template":true%');
261 + });
262 + }
263 +
235 264 public function getUsers()
236 265 {
237 266 return (new UserService())->allFluentBoardsUsers($this->id);
238 267 }
@@ -258,8 +287,20 @@
258 287
259 288 return $formattedMeta;
260 289 }
261 290
291 +
292 +
293 + public function getMetaByKey($key) // get Board Meta only
294 + {
295 + $meta = Meta::where('object_id', $this->id)
296 + ->where('object_type', Constant::OBJECT_TYPE_BOARD)
297 + ->where('key', $key)
298 + ->first();
299 +
300 + return $meta->value ?? null;
301 + }
302 +
262 303 public function updateMeta($key, $value)
263 304 {
264 305 $meta = Meta::where('object_id', $this->id)
265 306 ->where('object_type', Constant::OBJECT_TYPE_BOARD)
@@ -302,6 +343,18 @@
302 343
303 344 return $boardPermissions->settings['is_viewer_only'] ?? false;
304 345 }
305 346
347 + public function removeBoardFromFolder()
348 + {
349 + $relation = Relation::where('object_type', Constant::OBJECT_TYPE_FOLDER_BOARD)
350 + ->where('foreign_id', $this->id)
351 + ->first();
352 +
353 + if (!$relation) {
354 + return;
355 + }
356 + $relation->delete();
357 +
358 + }
306 359
307 360 }