PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / trunk
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration vtrunk
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 1.45 All 41 releases
fluent-boards / app / Models / TaskImage.php

TaskImage.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration trunk, at app/Models/TaskImage.php

63 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Models;
4
5 use FluentBoards\App\Services\Constant;
6
7 class TaskImage extends Attachment
8 {
9 public static function boot()
10 {
11 parent::boot();
12
13 static::creating(function ($model) {
14 $uid = wp_generate_uuid4();
15 $model->file_hash = md5($uid . wp_rand(0, 1000));
16 });
17 }
18
19 public function scopeWithComment($query)
20 {
21 return $query->where('object_type', 'COMMENT')->with('comment', function ($query) {
22 $query->select('id', 'board_id');
23 });
24 }
25
26 public function getSecureUrlAttribute()
27 {
28 if ($this->attachment_type === 'url') {
29 return $this->full_url;
30 }
31 return add_query_arg([
32 'fbs' => 1,
33 'fbs_comment_image' => $this->file_hash,
34 'secure_sign' => md5($this->id . gmdate('YmdH'))
35 ], site_url('/index.php'));
36 }
37
38 /**
39 * Scope a query to include tasks related to attachments and descriptions.
40 *
41 * This scope filters the query to include records where the `object_type`
42 * is either `TASK_ATTACHMENT` or `TASK_DESCRIPTION`. Additionally, it
43 * includes related task data by using the `with` method to eager load
44 * the `task` relationship, but only selects specific columns (`id`,
45 * `title`, `board_id`) for efficiency.
46 *
47 * @param \Illuminate\Database\Eloquent\Builder $query
48 * @return \Illuminate\Database\Eloquent\Builder
49 */
50 public function scopeWithTask($query)
51 {
52 return $query->where(function ($query) {
53 $query->where('object_type', Constant::TASK_DESCRIPTION);
54 })
55 ->with(['task' => function ($query) {
56 $query->select('id', 'title', 'board_id');
57 }]);
58 }
59
60
61 }
62
63