forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptVersion.php
More file actions
79 lines (67 loc) · 1.84 KB
/
ScriptVersion.php
File metadata and controls
79 lines (67 loc) · 1.84 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
<?php
namespace ProcessMaker\Models;
use Illuminate\Database\Eloquent\Builder;
use ProcessMaker\Contracts\ScriptInterface;
use ProcessMaker\Traits\HasCategories;
class ScriptVersion extends ProcessMakerModel implements ScriptInterface
{
use HasCategories;
const categoryClass = ScriptCategory::class;
protected $connection = 'processmaker';
/**
* Attributes that are not mass assignable.
*
* @var array
*/
protected $guarded = [
'id',
'updated_at',
];
/**
* Set multiple|single categories to the script
*
* @param string $value
*/
public function setScriptCategoryIdAttribute($value)
{
return $this->setMultipleCategories($value, 'script_category_id');
}
/**
* Get the associated script
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function parent()
{
return $this->belongsTo(Script::class, 'script_id', 'id');
}
/**
* Executes a script given a configuration and data input.
*
* @param array $data
* @param array $config
*/
public function runScript(array $data, array $config, $tokenId = '', $timeout = null)
{
$script = $this->parent->replicate();
$except = $script->getGuarded();
foreach (collect($script->getAttributes())->except($except)->keys() as $prop) {
$script->$prop = $this->$prop;
}
return $script->runScript($data, $config, $tokenId, $timeout);
}
/**
* Scope to only return draft versions.
*/
public function scopeDraft(Builder $query)
{
return $query->where('draft', true);
}
/**
* Scope to only return published versions.
*/
public function scopePublished(Builder $query)
{
return $query->where('draft', false);
}
}