Files
luos/workflow/engine/src/ProcessMaker/Model/ProcessVariables.php

99 lines
2.5 KiB
PHP
Raw Normal View History

2019-06-28 15:20:51 -04:00
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
2020-04-27 10:40:15 -04:00
use Illuminate\Support\Facades\DB;
2019-06-28 15:20:51 -04:00
class ProcessVariables extends Model
{
// Set our table name
protected $table = 'PROCESS_VARIABLES';
// No timestamps
public $timestamps = false;
2020-04-27 10:40:15 -04:00
// Primary key
2019-06-28 15:20:51 -04:00
protected $primaryKey = 'VAR_UID';
2020-04-27 10:40:15 -04:00
// The IDs are auto-incrementing
public $incrementing = false;
2020-04-27 10:40:15 -04:00
/**
* The model's default values for attributes.
*
* @var array
*/
protected $attributes = [
'VAR_FIELD_SIZE' => 0,
'VAR_DBCONNECTION' => '',
'VAR_SQL' => '',
'VAR_NULL' => 0,
'VAR_DEFAULT' => '',
'VAR_ACCEPTED_VALUES' => '[]',
'INP_DOC_UID' => '',
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'VAR_UID',
'PRJ_UID',
'PRO_ID',
'VAR_NAME',
'VAR_FIELD_TYPE',
'VAR_FIELD_TYPE_ID',
'VAR_FIELD_SIZE',
'VAR_LABEL',
'VAR_DBCONNECTION',
'VAR_SQL',
'VAR_NULL',
'VAR_DEFAULT',
'VAR_ACCEPTED_VALUES',
'INP_DOC_UID'
];
/**
* Scope a query to filter an specific process
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $proUid
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProcess($query, string $proUid)
{
return $query->where('PRJ_UID', $proUid);
}
2019-06-28 15:20:51 -04:00
/**
* Scope a query to filter an specific process
*
* @param \Illuminate\Database\Eloquent\Builder $query
2020-04-27 10:40:15 -04:00
* @param int $proId
2019-06-28 15:20:51 -04:00
* @return \Illuminate\Database\Eloquent\Builder
*/
2020-04-27 10:40:15 -04:00
public function scopeProcessId($query, int $proId)
2019-06-28 15:20:51 -04:00
{
2020-04-27 10:40:15 -04:00
return $query->where('PRO_ID', $proId);
}
/**
* Return the variables list
*
* @param int $proId
*
* @return array
*/
public static function getVariables(int $proId)
{
$query = ProcessVariables::query()->select();
$query->leftJoin('DB_SOURCE', function ($join) {
$join->on('DB_SOURCE.PRO_ID', '=', 'PROCESS_VARIABLES.PRO_ID');
});
$query->where('PROCESS_VARIABLES.PRO_ID', $proId);
$results = $query->get();
$variablesList = [];
$results->each(function ($item, $key) use (&$variablesList) {
$variablesList[] = $item->toArray();
});
return $variablesList;
2019-06-28 15:20:51 -04:00
}
}