Skip to content

Commit 3c5f981

Browse files
Refactor Project and Project Asset relationships in Script, Processes, and Screen models for improved clarity and functionality"
1 parent 99f5e8e commit 3c5f981

6 files changed

Lines changed: 66 additions & 15 deletions

File tree

‎ProcessMaker/Http/Controllers/Process/ScreenController.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ public function index(Request $request)
6767
public function edit(Screen $screen)
6868
{
6969
$addons = $this->getPluginAddons('edit', compact(['screen']));
70+
$assignedProjects = $screen->projects;
7071

71-
return view('processes.screens.edit', compact('screen', 'addons'));
72+
return view('processes.screens.edit', compact('screen', 'addons', 'assignedProjects'));
7273
}
7374

7475
/**

‎ProcessMaker/Http/Controllers/Process/ScriptController.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ public function index(Request $request)
5656
public function edit(Script $script, User $users)
5757
{
5858
$selectedUser = $script->runAsUser;
59+
$assignedProjects = $script->projects;
5960
$scriptExecutors = ScriptExecutor::list($script->scriptExecutor->language);
6061
$addons = $this->getPluginAddons('edit', compact(['script']));
6162

62-
return view('processes.scripts.edit', compact('script', 'selectedUser', 'scriptExecutors', 'addons'));
63+
return view('processes.scripts.edit', compact('script', 'selectedUser', 'scriptExecutors', 'addons', 'assignedProjects'));
6364
}
6465

6566
public function builder(ScriptBuilderManager $manager, Request $request, Script $script, $processId = null)

‎ProcessMaker/Http/Controllers/ProcessController.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ public function edit(Process $process)
100100
$list = $this->listUsersAndGroups();
101101

102102
$process->append('notifications', 'task_notifications');
103+
$assignedProjects = $process->projects;
103104

104105
$canStart = $this->listCan('Start', $process);
105106
$canCancel = $this->listCan('Cancel', $process);
106107
$canEditData = $this->listCan('EditData', $process);
107108
$addons = $this->getPluginAddons('edit', compact(['process']));
108109

109-
return view('processes.edit', compact(['process', 'categories', 'screenRequestDetail', 'screenCancel', 'list', 'canCancel', 'canStart', 'canEditData', 'addons']));
110+
return view('processes.edit', compact(['process', 'categories', 'screenRequestDetail', 'screenCancel', 'list', 'canCancel', 'canStart', 'canEditData', 'addons', 'assignedProjects']));
110111
}
111112

112113
/**

‎ProcessMaker/Models/Process.php‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class Process extends ProcessMakerModel implements HasMedia, ProcessModelInterfa
220220

221221
protected $appends = [
222222
'has_timer_start_events',
223+
'projects',
223224
];
224225

225226
protected $casts = [
@@ -246,12 +247,31 @@ public function category()
246247
*/
247248
public function projects()
248249
{
249-
return $this->belongsTo('ProcessMaker\Package\Projects\Models\Projects',
250+
return $this->belongsToMany('ProcessMaker\Package\Projects\Models\Project',
250251
'project_assets',
252+
'asset_id',
251253
'project_id',
252-
'asset_id'
253-
)->wherePivot('asset_type', static::class)
254-
->withTimestamps();
254+
'id',
255+
'id'
256+
)->wherePivot('asset_type', static::class);
257+
}
258+
259+
// Define the relationship with the ProjectAsset model
260+
public function projectAssets()
261+
{
262+
return $this->belongsToMany('ProcessMaker\Package\Projects\Models\ProjectAsset',
263+
'project_assets', 'asset_id', 'project_id')
264+
->withPivot('asset_type')
265+
->wherePivot('asset_type', static::class)->withTimestamps();
266+
}
267+
268+
public function projectAsset()
269+
{
270+
return $this->belongsToMany('ProcessMaker\Package\Projects\Models\ProjectAsset',
271+
'project_assets',
272+
'asset_id',
273+
'project_id',
274+
)->withTimeStamps();
255275
}
256276

257277
/**

‎ProcessMaker/Models/Screen.php‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class Screen extends ProcessMakerModel implements ScreenInterface
9090
'translations' => 'array',
9191
];
9292

93+
protected $appends = [
94+
'projects',
95+
];
96+
9397
/**
9498
* The attributes that aren't mass assignable.
9599
*
@@ -162,12 +166,22 @@ public function category()
162166
*/
163167
public function projects()
164168
{
165-
return $this->belongsTo('ProcessMaker\Package\Projects\Models\Projects',
169+
return $this->belongsToMany('ProcessMaker\Package\Projects\Models\Project',
166170
'project_assets',
171+
'asset_id',
167172
'project_id',
168-
'asset_id'
169-
)->wherePivot('asset_type', static::class)
170-
->withTimestamps();
173+
'id',
174+
'id'
175+
)->wherePivot('asset_type', static::class);
176+
}
177+
178+
// Define the relationship with the ProjectAsset model
179+
public function projectAssets()
180+
{
181+
return $this->belongsToMany('ProcessMaker\Package\Projects\Models\ProjectAsset',
182+
'project_assets', 'asset_id', 'project_id')
183+
->withPivot('asset_type')
184+
->wherePivot('asset_type', static::class)->withTimestamps();
171185
}
172186

173187
public function scopeExclude($query, $value = [])

‎ProcessMaker/Models/Script.php‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class Script extends ProcessMakerModel implements ScriptInterface
8383
'retry_wait_time' => 'integer',
8484
];
8585

86+
protected $appends = [
87+
'projects',
88+
];
89+
8690
/**
8791
* Override the default boot method to allow access to lifecycle hooks
8892
*
@@ -266,12 +270,22 @@ public function runAsUser()
266270
*/
267271
public function projects()
268272
{
269-
return $this->belongsTo('ProcessMaker\Package\Projects\Models\Projects',
273+
return $this->belongsToMany('ProcessMaker\Package\Projects\Models\Project',
270274
'project_assets',
275+
'asset_id',
271276
'project_id',
272-
'asset_id'
273-
)->wherePivot('asset_type', static::class)
274-
->withTimestamps();
277+
'id',
278+
'id'
279+
)->wherePivot('asset_type', static::class);
280+
}
281+
282+
// Define the relationship with the ProjectAsset model
283+
public function projectAssets()
284+
{
285+
return $this->belongsToMany('ProcessMaker\Package\Projects\Models\ProjectAsset',
286+
'project_assets', 'asset_id', 'project_id')
287+
->withPivot('asset_type')
288+
->wherePivot('asset_type', static::class)->withTimestamps();
275289
}
276290

277291
/**

0 commit comments

Comments
 (0)