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

120 lines
3.0 KiB
PHP
Raw Normal View History

<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
2019-05-23 16:30:49 -04:00
use Illuminate\Support\Facades\DB;
class Application extends Model
{
protected $table = "APPLICATION";
protected $primaryKey = 'APP_NUMBER';
public $incrementing = false;
// No timestamps
public $timestamps = false;
2019-06-10 15:04:14 -04:00
// Status id
const STATUS_DRAFT = 1;
const STATUS_TODO = 2;
const STATUS_COMPLETED = 3;
const STATUS_CANCELED = 4;
public function delegations()
{
return $this->hasMany(Delegation::class, 'APP_UID', 'APP_UID');
}
2020-02-17 14:09:54 -04:00
public function currentUser()
{
2020-02-17 14:09:54 -04:00
return $this->belongsTo(User::class, 'APP_CUR_USER', 'USR_UID');
}
2020-02-17 14:09:54 -04:00
public function creatorUser()
{
2020-02-17 14:09:54 -04:00
return $this->belongsTo(User::class, 'APP_INIT_USER', 'USR_UID');
}
2019-05-23 16:30:49 -04:00
/**
2020-01-06 14:30:41 -04:00
* Scope for query to get the application by APP_UID.
2020-02-17 14:09:54 -04:00
*
2020-01-06 14:30:41 -04:00
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $appUid
2020-02-17 14:09:54 -04:00
*
2020-01-06 14:30:41 -04:00
* @return \Illuminate\Database\Eloquent\Builder
2019-05-23 16:30:49 -04:00
*/
2020-01-06 14:30:41 -04:00
public function scopeAppUid($query, $appUid)
2019-05-23 16:30:49 -04:00
{
2020-01-06 14:30:41 -04:00
$result = $query->where('APP_UID', '=', $appUid);
return $result;
2019-05-23 16:30:49 -04:00
}
/**
* Scope for query to get the applications by PRO_UID.
2020-01-06 14:30:41 -04:00
*
2019-05-23 16:30:49 -04:00
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $proUid
2020-01-06 14:30:41 -04:00
*
2019-05-23 16:30:49 -04:00
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProUid($query, $proUid)
{
$result = $query->where('PRO_UID', '=', $proUid);
return $result;
}
2020-01-06 14:30:41 -04:00
/**
* Get Applications by PRO_UID, ordered by APP_NUMBER.
*
* @param string $proUid
*
* @return object
* @see ReportTables->populateTable()
*/
public static function getByProUid($proUid)
{
$query = Application::query()
->select()
->proUid($proUid)
->orderBy('APP_NUMBER', 'ASC');
return $query->get();
}
/**
* Get information related to the created case
*
* @param string $appUid
*
* @return array|bool
*/
public static function getCase($appUid)
{
$query = Application::query()->select(['APP_STATUS', 'APP_INIT_USER']);
$query->appUid($appUid);
$result = $query->get()->toArray();
$firstElement = head($result);
return $firstElement;
}
2020-02-17 14:09:54 -04:00
/**
* Update properties
*
* @param string $appUid
* @param array $fields
*
* @return array
*/
public static function updateColumns($appUid, $fields)
{
$properties = [];
$properties['APP_ROUTING_DATA'] = !empty($fields['APP_ROUTING_DATA']) ? serialize($fields['APP_ROUTING_DATA']) : serialize([]);
// This column will to update only when the thread is related to the user
if (!empty($fields['APP_CUR_USER'])) {
$properties['APP_CUR_USER'] = $fields['APP_CUR_USER'];
}
Application::query()->appUid($appUid)->update($properties);
return $properties;
}
}