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 +88 -15 1.222.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 {
@@ -32,22 +30,24 @@
32 30 'created_by',
33 31 'archived_at',
34 32 ];
35 33
36 - protected $appends = ['meta'];
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) {
48 - $builder = $builder->whereNull('archived_at');
49 - $builder->where('type', '=', 'to-do')
49 + $builder = $builder->where('type', '=', 'to-do')
50 50 ->orWhere('type', '=', 'roadmap');
51 51 });
52 52 }
53 53
@@ -219,21 +219,49 @@
219 219 }
220 220
221 221 return $query->whereIn('id', $boardIds);
222 222 }
223 - 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)
224 230 {
225 - $solids = Constant::BOARD_BACKGROUND_DEFAULT_SOLID_COLORS;
226 - $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 + }
227 239
228 - return [
229 - 'id' => $solid['id'],
230 - 'is_image' => false,
231 - 'image_url' => null,
232 - 'color' => $solid['value']
233 - ];
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;
234 250 }
235 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 +
236 264 public function getUsers()
237 265 {
238 266 return (new UserService())->allFluentBoardsUsers($this->id);
239 267 }
@@ -259,8 +287,20 @@
259 287
260 288 return $formattedMeta;
261 289 }
262 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 +
263 303 public function updateMeta($key, $value)
264 304 {
265 305 $meta = Meta::where('object_id', $this->id)
266 306 ->where('object_type', Constant::OBJECT_TYPE_BOARD)
@@ -282,6 +322,39 @@
282 322 return $meta;
283 323
284 324 }
285 325
326 +
327 + public function activities()
328 + {
329 + return $this->hasMany(Activity::class, 'object_id')
330 + ->where('object_type', Constant::ACTIVITY_BOARD);
331 + }
332 +
333 + public function getisUserOnlyViewerAttribute()
334 + {
335 + $userId = get_current_user_id();
336 + if(PermissionManager::isAdmin()) {
337 + return false;
338 + }
339 + $boardPermissions = Relation::where('object_id', $this->id)
340 + ->where('foreign_id', $userId)
341 + ->where('object_type', Constant::OBJECT_TYPE_BOARD_USER)
342 + ->first();
343 +
344 + return $boardPermissions->settings['is_viewer_only'] ?? false;
345 + }
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 + }
286 359
287 360 }