Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 20 additions & 47 deletions ProcessMaker/Http/Controllers/Api/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,21 @@ public function index(Request $request)
$user = Auth::user();

$orderBy = $this->getRequestSortBy($request, 'name');
if (!str_contains($orderBy[0], '.')) {
$orderBy[0] = 'processes.' . $orderBy[0];
}
$perPage = $this->getPerPage($request);
$include = $this->getRequestInclude($request);
$relationships = array_values(array_diff($include, ['events']));
$status = $request->input('status');
$pmql = $request->input('pmql', '');

$processes = Process::nonSystem()->notArchived()->with($include);
$processes = Process::nonSystem()->notArchived()->with($relationships);
if ($status === 'archived') {
$processes = Process::archived()->with($include);
$processes = Process::archived()->with($relationships);
}
if ($status === 'all') {
$processes = Process::active()->with($include);
$processes = Process::active()->with($relationships);
}

$filter = $request->input('filter', '');
Expand Down Expand Up @@ -188,60 +192,29 @@ public function index(Request $request)
// Get with launchpad
$launchpad = $request->input('launchpad', false);

$processes = $processes->with('events')
->select('processes.*')
$processes = $processes
->with('notification_settings')
->exclude(['bpmn', 'svg'])
->leftJoin(\DB::raw('(select id, uuid, name from process_categories) as category'), 'processes.process_category_id', '=', 'category.id')
->leftJoin(\DB::raw('(select id, uuid, username, lastname, firstname from users) as user'), 'processes.user_id', '=', 'user.id')
->orderBy(...$orderBy)
->get()
->collect();

foreach ($processes as $key => $process) {
// filter the start events that can be used manually (no timer start events);
// TODO: startEvents is not a real property on Process.
// Move below to $process->getManualStartEvents();
$process->startEvents = $process->events->filter(function ($event) {
$eventIsTimerStart = collect($event['eventDefinitions'])
->filter(function ($eventDefinition) {
return $eventDefinition['$type'] == 'timerEventDefinition';
})->count() > 0;

// Filter out web entry start events and email start events
$eventIsWebEntry = false;
$eventIsEmailStart = false;
if (isset($event['config'])) {
$config = json_decode($event['config'], true);
if (isset($config['web_entry']) && $config['web_entry'] !== null) {
$eventIsWebEntry = true;
} elseif (isset($config['email_start']) && $config['email_start'] !== null) {
$eventIsEmailStart = true;
}
}
->paginate($perPage);

return !$eventIsTimerStart && !$eventIsWebEntry && !$eventIsEmailStart;
})->values();
foreach ($processes as $process) {
$process->setAppends(array_values(array_diff($process->getAppends(), ['projects'])));
$process->makeHidden('notification_settings');

// Get the id bookmark related
$process->bookmark_id = Bookmark::getBookmarked($bookmark, $process->id, $user->id);
// Get the launchpad configuration
$process->launchpad = ProcessLaunchpad::getLaunchpad($launchpad, $process->id);
$process->bookmark_id = $bookmark
? Bookmark::getBookmarked($bookmark, $process->id, $user->id)
: 0;
$process->launchpad = $launchpad
? ProcessLaunchpad::getLaunchpad($launchpad, $process->id)
: null;

$process->case_retention_tier_adjustment_notice = false;
if ($user->is_administrator && config('app.case_retention_policy_enabled')) {
$process->case_retention_tier_adjustment_notice = CaseRetentionTierService::adjustmentNoticeIsActive($process);
}

// Filter all processes that have event definitions (start events like message event, conditional event, signal event, timer event)
if ($request->has('without_event_definitions') && $request->input('without_event_definitions') == 'true') {
$startEvents = $process->events->filter(function ($event) {
return collect($event['eventDefinitions'])->isEmpty();
});
}

// filter only valid executable processes
if (!$process->isValidForExecution()) {
$processes->startEvents = [];
}
}

return new ProcessCollection($processes);
Expand Down
10 changes: 4 additions & 6 deletions ProcessMaker/Models/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ public function embed()
public function getNotificationsAttribute()
{
$array = [];
$settings = $this->notification_settings->whereNull('element_id');

foreach ($this->requestNotifiableTypes as $notifiable) {
foreach ($this->requestNotificationTypes as $notification) {
$setting = $this->notification_settings()
->whereNull('element_id')
$setting = $settings
->where('notifiable_type', $notifiable)
->where('notification_type', $notification)->get();
->where('notification_type', $notification);

if ($setting->count()) {
$value = true;
Expand All @@ -372,9 +372,7 @@ public function getTaskNotificationsAttribute()
{
$array = [];

$elements = $this->notification_settings()
->whereNotNull('element_id')
->get();
$elements = $this->notification_settings->whereNotNull('element_id');

foreach ($elements->groupBy('element_id') as $group) {
$elementId = $group->first()->element_id;
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Models/ProcessMakerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function scopeExclude($query, array $columns)

$columnsToShow = array_diff($this->getTableColumns(), $columns);
$columnsToShow = array_map(function ($column) {
return $this->table . '.' . $column;
return $this->getTable() . '.' . $column;
}, $columnsToShow);

return $query->select($columnsToShow);
Expand Down
3 changes: 1 addition & 2 deletions resources/js/processes/components/ProcessMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ export default {
this.orderBy
}&order_direction=${
this.orderDirection
}&include=categories,category,user`
+ "&with=events",
}&include=categories,category,user`,
{
cancelToken: new CancelToken((c) => {
this.cancelToken = c;
Expand Down
Loading
Loading