-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathProcessTemplates.php
More file actions
95 lines (81 loc) · 2.89 KB
/
ProcessTemplates.php
File metadata and controls
95 lines (81 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace ProcessMaker\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Auth;
use ProcessMaker\Traits\HasCategories;
use ProcessMaker\Traits\HideSystemResources;
use ProcessMaker\Traits\ProcessTrait;
class ProcessTemplates extends Template
{
use HasFactory;
use HasCategories;
use ProcessTrait;
use HideSystemResources;
protected $table = 'process_templates';
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->updated_by = Auth::id();
});
static::updating(function ($model) {
$model->updated_by = Auth::id();
});
}
public function updatedByUser()
{
return $this->belongsTo(User::class, 'updated_by');
}
const categoryClass = ProcessCategory::class;
public $process_category_id;
/**
* Category of the process.
*
* @return BelongsTo
*/
public function category()
{
return $this->belongsTo(ProcessCategory::class, 'process_category_id')->withDefault();
}
/**
* Set multiple|single categories to the process
*
* @param string $value
*/
public function setProcessCategoryIdAttribute($value)
{
return $this->setMultipleCategories($value, 'process_category_id');
}
/**
* Get multiple|single categories of the process
*
* @param string $value
*/
public function getProcessCategoryIdAttribute($value)
{
return implode(',', $this->categories()->pluck('category_id')->toArray()) ?: $value;
}
/**
* Apply filters to the query based on the given filter string.
*/
public function scopeWithFilters(Builder $query, $filter): void
{
$query->where(function ($query) use ($filter) {
$query->where('process_templates.name', 'like', '%' . $filter . '%')
->orWhere('process_templates.description', 'like', '%' . $filter . '%')
->orWhere('user.firstname', 'like', '%' . $filter . '%')
->orWhere('user.lastname', 'like', '%' . $filter . '%')
->orWhereIn('process_templates.id', function ($qry) use ($filter) {
$qry->select('assignable_id')
->from('category_assignments')
->leftJoin('process_categories', function ($join) {
$join->on('process_categories.id', '=', 'category_assignments.category_id');
$join->where('category_assignments.category_type', '=', ProcessCategory::class);
$join->where('category_assignments.assignable_type', '=', ProcessTemplates::class);
})
->where('process_categories.name', 'like', '%' . $filter . '%');
});
});
}
}