From 6b8065a98f1dd63d1f322c642cc20db8d30403f7 Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Thu, 25 Apr 2019 13:47:21 -0700 Subject: [PATCH 01/31] Add initial app models. Add tinker as a dependency to allow use with artisan. --- app/Models/Application.php | 10 ++ app/Models/Delegation.php | 42 +++++ app/Models/Process.php | 17 ++ app/Models/Task.php | 10 ++ app/Models/User.php | 19 +++ composer.json | 4 +- composer.lock | 315 ++++++++++++++++++++++++++++++++++++- config/app.php | 2 + 8 files changed, 416 insertions(+), 3 deletions(-) create mode 100644 app/Models/Application.php create mode 100644 app/Models/Delegation.php create mode 100644 app/Models/Process.php create mode 100644 app/Models/Task.php create mode 100644 app/Models/User.php diff --git a/app/Models/Application.php b/app/Models/Application.php new file mode 100644 index 000000000..6afa38919 --- /dev/null +++ b/app/Models/Application.php @@ -0,0 +1,10 @@ +belongsTo(Application::class, 'APP_UID', 'APP_UID'); + } + + /** + * Returns the user this delegation belongs to + */ + public function user() + { + return $this->belongsTo(User::class, 'USR_ID', 'USR_ID'); + } + + /** + * Return the process task this belongs to + */ + public function task() + { + return $this->belongsTo(Task::class, 'TAS_ID', 'TAS_ID'); + } + + /** + * Return the process this delegation belongs to + */ + public function process() + { + return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID'); + } +} diff --git a/app/Models/Process.php b/app/Models/Process.php new file mode 100644 index 000000000..e45241287 --- /dev/null +++ b/app/Models/Process.php @@ -0,0 +1,17 @@ +hasMany(Application::class, 'PRO_ID', 'PRO_ID'); + + } +} diff --git a/app/Models/Task.php b/app/Models/Task.php new file mode 100644 index 000000000..a79ef4a9c --- /dev/null +++ b/app/Models/Task.php @@ -0,0 +1,10 @@ +hasMany(Delegation::class, 'USR_ID', 'USR_ID'); + + } +} diff --git a/composer.json b/composer.json index 6e2eec268..b52a58582 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,9 @@ "ralouphie/getallheaders": "^2.0", "smarty/smarty": "2.6.30", "pdepend/pdepend": "@stable", - "chumper/zipper": "^1.0" + "chumper/zipper": "^1.0", + "nikic/php-parser": "3.1.5", + "laravel/tinker": "^1.0" }, "require-dev": { "fzaninotto/faker": "^1.7", diff --git a/composer.lock b/composer.lock index 527736ee1..510c23ba6 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3242f53453d9e9a3d7fdf3a56961ae40", + "content-hash": "a9ba65f7fb68be7c36dd45b62216b2c6", "packages": [ { "name": "bshaffer/oauth2-server-php", @@ -209,6 +209,39 @@ ], "time": "2018-03-09T06:07:41+00:00" }, + { + "name": "dnoegel/php-xdg-base-dir", + "version": "0.1", + "source": { + "type": "git", + "url": "https://github.com/dnoegel/php-xdg-base-dir.git", + "reference": "265b8593498b997dc2d31e75b89f053b5cc9621a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dnoegel/php-xdg-base-dir/zipball/265b8593498b997dc2d31e75b89f053b5cc9621a", + "reference": "265b8593498b997dc2d31e75b89f053b5cc9621a", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "@stable" + }, + "type": "project", + "autoload": { + "psr-4": { + "XdgBaseDir\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "implementation of xdg base directory specification for php", + "time": "2014-10-24T07:27:01+00:00" + }, { "name": "doctrine/inflector", "version": "v1.1.0", @@ -405,6 +438,94 @@ ], "time": "2015-10-16T22:11:08+00:00" }, + { + "name": "jakub-onderka/php-console-color", + "version": "v0.2", + "source": { + "type": "git", + "url": "https://github.com/JakubOnderka/PHP-Console-Color.git", + "reference": "d5deaecff52a0d61ccb613bb3804088da0307191" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/JakubOnderka/PHP-Console-Color/zipball/d5deaecff52a0d61ccb613bb3804088da0307191", + "reference": "d5deaecff52a0d61ccb613bb3804088da0307191", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "jakub-onderka/php-code-style": "1.0", + "jakub-onderka/php-parallel-lint": "1.0", + "jakub-onderka/php-var-dump-check": "0.*", + "phpunit/phpunit": "~4.3", + "squizlabs/php_codesniffer": "1.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "JakubOnderka\\PhpConsoleColor\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Jakub Onderka", + "email": "jakub.onderka@gmail.com" + } + ], + "time": "2018-09-29T17:23:10+00:00" + }, + { + "name": "jakub-onderka/php-console-highlighter", + "version": "v0.4", + "source": { + "type": "git", + "url": "https://github.com/JakubOnderka/PHP-Console-Highlighter.git", + "reference": "9f7a229a69d52506914b4bc61bfdb199d90c5547" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/JakubOnderka/PHP-Console-Highlighter/zipball/9f7a229a69d52506914b4bc61bfdb199d90c5547", + "reference": "9f7a229a69d52506914b4bc61bfdb199d90c5547", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "jakub-onderka/php-console-color": "~0.2", + "php": ">=5.4.0" + }, + "require-dev": { + "jakub-onderka/php-code-style": "~1.0", + "jakub-onderka/php-parallel-lint": "~1.0", + "jakub-onderka/php-var-dump-check": "~0.1", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~1.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "JakubOnderka\\PhpConsoleHighlighter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jakub Onderka", + "email": "acci@acci.cz", + "homepage": "http://www.acci.cz/" + } + ], + "description": "Highlight PHP code in terminal", + "time": "2018-09-29T18:48:56+00:00" + }, { "name": "laravel/framework", "version": "v5.4.36", @@ -534,6 +655,69 @@ ], "time": "2017-08-30T09:26:16+00:00" }, + { + "name": "laravel/tinker", + "version": "v1.0.8", + "source": { + "type": "git", + "url": "https://github.com/laravel/tinker.git", + "reference": "cafbf598a90acde68985660e79b2b03c5609a405" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/tinker/zipball/cafbf598a90acde68985660e79b2b03c5609a405", + "reference": "cafbf598a90acde68985660e79b2b03c5609a405", + "shasum": "" + }, + "require": { + "illuminate/console": "~5.1", + "illuminate/contracts": "~5.1", + "illuminate/support": "~5.1", + "php": ">=5.5.9", + "psy/psysh": "0.7.*|0.8.*|0.9.*", + "symfony/var-dumper": "~3.0|~4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0|~5.0" + }, + "suggest": { + "illuminate/database": "The Illuminate Database package (~5.1)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Tinker\\TinkerServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Tinker\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Powerful REPL for the Laravel framework.", + "keywords": [ + "REPL", + "Tinker", + "laravel", + "psysh" + ], + "time": "2018-10-12T19:39:35+00:00" + }, { "name": "league/flysystem", "version": "1.0.49", @@ -923,6 +1107,57 @@ ], "time": "2018-11-22T18:23:02+00:00" }, + { + "name": "nikic/php-parser", + "version": "v3.1.5", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "~4.0|~5.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2018-02-28T20:30:58+00:00" + }, { "name": "paragonie/random_compat", "version": "v2.0.17", @@ -1364,6 +1599,80 @@ ], "time": "2012-12-21T11:40:51+00:00" }, + { + "name": "psy/psysh", + "version": "v0.9.9", + "source": { + "type": "git", + "url": "https://github.com/bobthecow/psysh.git", + "reference": "9aaf29575bb8293206bb0420c1e1c87ff2ffa94e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bobthecow/psysh/zipball/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e", + "reference": "9aaf29575bb8293206bb0420c1e1c87ff2ffa94e", + "shasum": "" + }, + "require": { + "dnoegel/php-xdg-base-dir": "0.1", + "ext-json": "*", + "ext-tokenizer": "*", + "jakub-onderka/php-console-highlighter": "0.3.*|0.4.*", + "nikic/php-parser": "~1.3|~2.0|~3.0|~4.0", + "php": ">=5.4.0", + "symfony/console": "~2.3.10|^2.4.2|~3.0|~4.0", + "symfony/var-dumper": "~2.7|~3.0|~4.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.2", + "hoa/console": "~2.15|~3.16", + "phpunit/phpunit": "~4.8.35|~5.0|~6.0|~7.0" + }, + "suggest": { + "ext-pcntl": "Enabling the PCNTL extension makes PsySH a lot happier :)", + "ext-pdo-sqlite": "The doc command requires SQLite to work.", + "ext-posix": "If you have PCNTL, you'll want the POSIX extension as well.", + "ext-readline": "Enables support for arrow-key history navigation, and showing and manipulating command history.", + "hoa/console": "A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit." + }, + "bin": [ + "bin/psysh" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-develop": "0.9.x-dev" + } + }, + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "Psy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Justin Hileman", + "email": "justin@justinhileman.info", + "homepage": "http://justinhileman.com" + } + ], + "description": "An interactive shell for modern PHP.", + "homepage": "http://psysh.org", + "keywords": [ + "REPL", + "console", + "interactive", + "shell" + ], + "time": "2018-10-13T15:16:03+00:00" + }, { "name": "ralouphie/getallheaders", "version": "2.0.5", @@ -4883,6 +5192,7 @@ "mock", "xunit" ], + "abandoned": true, "time": "2017-06-30T09:13:00+00:00" }, { @@ -5823,6 +6133,7 @@ "phpcs", "standards" ], + "abandoned": "phpcompatibility/php-compatibility", "time": "2018-10-07T17:38:02+00:00" } ], diff --git a/config/app.php b/config/app.php index fad6a83a2..035380c52 100644 --- a/config/app.php +++ b/config/app.php @@ -22,6 +22,8 @@ return [ Illuminate\Queue\QueueServiceProvider::class, Illuminate\Translation\TranslationServiceProvider::class, + Laravel\Tinker\TinkerServiceProvider::class, + ], 'aliases' => [ From 9aec7285098b47ca01c1e7b8ee5164766c58412e Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Thu, 25 Apr 2019 13:54:39 -0700 Subject: [PATCH 02/31] Move models to proper ProcessMaker Model namespace. --- app/Models/Process.php | 17 ---------------- app/Models/Task.php | 10 ---------- .../src/ProcessMaker/Model}/Application.php | 2 +- .../src/ProcessMaker/Model}/Delegation.php | 2 +- .../engine/src/ProcessMaker/Model/Process.php | 8 ++++++++ .../engine/src/ProcessMaker/Model/Task.php | 20 +++++++++++++++++++ .../engine/src/ProcessMaker/Model}/User.php | 2 +- 7 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 app/Models/Process.php delete mode 100644 app/Models/Task.php rename {app/Models => workflow/engine/src/ProcessMaker/Model}/Application.php (80%) rename {app/Models => workflow/engine/src/ProcessMaker/Model}/Delegation.php (96%) create mode 100644 workflow/engine/src/ProcessMaker/Model/Task.php rename {app/Models => workflow/engine/src/ProcessMaker/Model}/User.php (90%) diff --git a/app/Models/Process.php b/app/Models/Process.php deleted file mode 100644 index e45241287..000000000 --- a/app/Models/Process.php +++ /dev/null @@ -1,17 +0,0 @@ -hasMany(Application::class, 'PRO_ID', 'PRO_ID'); - - } -} diff --git a/app/Models/Task.php b/app/Models/Task.php deleted file mode 100644 index a79ef4a9c..000000000 --- a/app/Models/Task.php +++ /dev/null @@ -1,10 +0,0 @@ -hasMany(Application::class, 'PRO_ID', 'PRO_ID'); + } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/Task.php b/workflow/engine/src/ProcessMaker/Model/Task.php new file mode 100644 index 000000000..ad2812698 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/Task.php @@ -0,0 +1,20 @@ +belongsTo(Process::class, 'PRO_UID', 'PRO_UID'); + } + + public function delegations() + { + return $this->hasMany(Delegation::class, 'TAS_ID', 'TAS_ID'); + } +} diff --git a/app/Models/User.php b/workflow/engine/src/ProcessMaker/Model/User.php similarity index 90% rename from app/Models/User.php rename to workflow/engine/src/ProcessMaker/Model/User.php index 2c7442d51..f8c992bc1 100644 --- a/app/Models/User.php +++ b/workflow/engine/src/ProcessMaker/Model/User.php @@ -1,6 +1,6 @@ Date: Thu, 25 Apr 2019 14:15:41 -0700 Subject: [PATCH 03/31] Update models to have more relationships and timestamp column definitions. --- .../src/ProcessMaker/Model/Application.php | 19 +++++++++++++++++++ .../src/ProcessMaker/Model/Delegation.php | 3 +++ .../engine/src/ProcessMaker/Model/Process.php | 9 +++++++-- .../engine/src/ProcessMaker/Model/Task.php | 2 ++ .../engine/src/ProcessMaker/Model/User.php | 3 +++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index d0dd1f479..2ca974844 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -7,4 +7,23 @@ use Illuminate\Database\Eloquent\Model; class Application extends Model { protected $table = "APPLICATION"; + // Our custom timestamp columns + const CREATED_AT = 'APP_CREATE_DATE'; + const UPDATED_AT = 'APP_UPDATE_DATE'; + + public function delegations() + { + return $this->hasMany(Delegation::class, 'APP_UID', 'APP_UID'); + } + + public function parent() + { + return $this->hasOne(Application::class, 'APP_PARENT', 'APP_UID'); + } + + public function currentUser() + { + return $this->hasOne(User::class, 'APP_CUR_USER', 'USR_UID'); + } + } diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index c33dd4e32..366666c1c 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -8,6 +8,9 @@ class Delegation extends Model { protected $table = "APP_DELEGATION"; + // We don't have our standard timestamp columns + protected $timestamps = false; + /** * Returns the application this delegation belongs to */ diff --git a/workflow/engine/src/ProcessMaker/Model/Process.php b/workflow/engine/src/ProcessMaker/Model/Process.php index e9b3cb972..abaac4e7a 100644 --- a/workflow/engine/src/ProcessMaker/Model/Process.php +++ b/workflow/engine/src/ProcessMaker/Model/Process.php @@ -14,9 +14,9 @@ class Process extends Model { // Set our table name protected $table = 'PROCESS'; - // We do have a created at, but we don't store an updated at + // Our custom timestamp columns const CREATED_AT = 'PRO_CREATE_DATE'; - const UPDATED_AT = null; + const UPDATED_AT = 'PRO_UPDATE_DATE'; /** * Retrieve all applications that belong to this process @@ -26,4 +26,9 @@ class Process extends Model return $this->hasMany(Application::class, 'PRO_ID', 'PRO_ID'); } + + public function creator() + { + return $this->hasOne(User::class, 'PRO_CREATE_USER', 'USR_UID'); + } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/Task.php b/workflow/engine/src/ProcessMaker/Model/Task.php index ad2812698..75c8e2fee 100644 --- a/workflow/engine/src/ProcessMaker/Model/Task.php +++ b/workflow/engine/src/ProcessMaker/Model/Task.php @@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Model; class Task extends Model { protected $table = 'TASK'; + // We do not have create/update timestamps for this table + protected $timestamps = false; public function process() { diff --git a/workflow/engine/src/ProcessMaker/Model/User.php b/workflow/engine/src/ProcessMaker/Model/User.php index f8c992bc1..40fc1be55 100644 --- a/workflow/engine/src/ProcessMaker/Model/User.php +++ b/workflow/engine/src/ProcessMaker/Model/User.php @@ -7,6 +7,9 @@ use Illuminate\Database\Eloquent\Model; class User extends Model { protected $table = "USERS"; + // Our custom timestamp columns + const CREATED_AT = 'USR_CREATE_DATE'; + const UPDATED_AT = 'USR_UPDATE_DATE'; /** * Returns the delegations this user has (all of them) From 2bf175ac85d3c46be7a65af0324f7996517892df Mon Sep 17 00:00:00 2001 From: dante Date: Thu, 25 Apr 2019 17:46:02 -0400 Subject: [PATCH 04/31] timestamps attribute visibility set to public --- workflow/engine/src/ProcessMaker/Model/Task.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/engine/src/ProcessMaker/Model/Task.php b/workflow/engine/src/ProcessMaker/Model/Task.php index 75c8e2fee..de66e26a0 100644 --- a/workflow/engine/src/ProcessMaker/Model/Task.php +++ b/workflow/engine/src/ProcessMaker/Model/Task.php @@ -8,7 +8,7 @@ class Task extends Model { protected $table = 'TASK'; // We do not have create/update timestamps for this table - protected $timestamps = false; + public $timestamps = false; public function process() { From e79503f590e27af31cd3d6fe1f5da129da7b08dd Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Thu, 25 Apr 2019 15:32:23 -0700 Subject: [PATCH 05/31] Include initial transform to transform results to desired necessity. Change proxyCaseList to utilize Delegation search. --- .../engine/methods/cases/proxyCasesList.php | 47 +++++- .../src/ProcessMaker/Model/Delegation.php | 136 +++++++++++++++++- 2 files changed, 175 insertions(+), 8 deletions(-) diff --git a/workflow/engine/methods/cases/proxyCasesList.php b/workflow/engine/methods/cases/proxyCasesList.php index bfec0df59..a5b0b7779 100644 --- a/workflow/engine/methods/cases/proxyCasesList.php +++ b/workflow/engine/methods/cases/proxyCasesList.php @@ -1,4 +1,9 @@ error = G::LoadTranslation('ID_LOGIN_AGAIN'); @@ -9,31 +14,59 @@ if (!isset($_SESSION['USER_LOGGED'])) { } +/** + * Do input filtering, although filtering should be done on the frontend rendering, not here + */ $filter = new InputFilter(); $_GET = $filter->xssFilterHard($_GET); $_REQUEST = $filter->xssFilterHard($_REQUEST); $_SESSION['USER_LOGGED'] = $filter->xssFilterHard($_SESSION['USER_LOGGED']); -//Getting the extJs parameters +// Callback in the UI to utilize $callback = isset($_REQUEST["callback"]) ? $_REQUEST["callback"] : "stcCallback1001"; -//This default value was defined in casesList.js -$dir = isset($_REQUEST["dir"]) ? $_REQUEST["dir"] : "DESC"; -//This default value was defined in casesList.js + +// Sort column $sort = isset($_REQUEST["sort"]) ? $_REQUEST["sort"] : "APP_NUMBER"; +// Sort direction +$dir = isset($_REQUEST["dir"]) ? $_REQUEST["dir"] : "DESC"; + +// Pagination control $start = !empty($_REQUEST["start"]) ? $_REQUEST["start"] : 0; $limit = !empty($_REQUEST["limit"]) ? $_REQUEST["limit"] : 25; + +// Our search filter $filter = isset($_REQUEST["filter"]) ? $_REQUEST["filter"] : ""; + +// What process $process = isset($_REQUEST["process"]) ? $_REQUEST["process"] : ""; + +// What category $category = isset($_REQUEST["category"]) ? $_REQUEST["category"] : ""; + +// What status $status = isset($_REQUEST["status"]) ? strtoupper($_REQUEST["status"]) : ""; $filterStatus = isset($_REQUEST["filterStatus"]) ? strtoupper($_REQUEST["filterStatus"]) : ""; + +// What user $user = isset($_REQUEST["user"]) ? $_REQUEST["user"] : ""; + +// What search??? $search = isset($_REQUEST["search"]) ? $_REQUEST["search"] : ""; + +// What kind of action $action = isset($_GET["action"]) ? $_GET["action"] : (isset($_REQUEST["action"]) ? $_REQUEST["action"] : "todo"); + +// What kind of search $type = isset($_GET["type"]) ? $_GET["type"] : (isset($_REQUEST["type"]) ? $_REQUEST["type"] : "extjs"); + +// Date ranges $dateFrom = isset($_REQUEST["dateFrom"]) ? substr($_REQUEST["dateFrom"], 0, 10) : ""; $dateTo = isset($_REQUEST["dateTo"]) ? substr($_REQUEST["dateTo"], 0, 10) : ""; + +// First? No idea $first = isset($_REQUEST["first"]) ? true : false; + + $openApplicationUid = (isset($_REQUEST['openApplicationUid']) && $_REQUEST['openApplicationUid'] != '') ? $_REQUEST['openApplicationUid'] : null; $search = (!is_null($openApplicationUid)) ? $openApplicationUid : $search; @@ -67,10 +100,10 @@ try { break; } - $apps = new Applications(); + //$apps = new Applications(); if ($action == 'search') { - $data = $apps->searchAll( + $data = Delegation::search( $userUid, $start, $limit, @@ -85,7 +118,7 @@ try { $columnSearch ); } else { - $data = $apps->getAll( + $data = Delegation::search( $userUid, $start, $limit, diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 366666c1c..332822c1f 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -3,13 +3,14 @@ namespace ProcessMaker\Model; use Illuminate\Database\Eloquent\Model; +use G; class Delegation extends Model { protected $table = "APP_DELEGATION"; // We don't have our standard timestamp columns - protected $timestamps = false; + public $timestamps = false; /** * Returns the application this delegation belongs to @@ -42,4 +43,137 @@ class Delegation extends Model { return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID'); } + + /** + * Searches for delegations which match certain criteria + * + * The query is related to advanced search with different filters + * We can search by process, status of case, category of process, users, delegate date from and to + * + * @param string $userUid + * @param integer $start for the pagination + * @param integer $limit for the pagination + * @param string $search + * @param integer $process the pro_id + * @param integer $status of the case + * @param string $dir if the order is DESC or ASC + * @param string $sort name of column by sort, can be: + * [APP_NUMBER, APP_TITLE, APP_PRO_TITLE, APP_TAS_TITLE, APP_CURRENT_USER, APP_UPDATE_DATE, DEL_DELEGATE_DATE, DEL_TASK_DUE_DATE, APP_STATUS_LABEL] + * @param string $category uid for the process + * @param date $dateFrom + * @param date $dateTo + * @param string $filterBy name of column for a specific search, can be: [APP_NUMBER, APP_TITLE, TAS_TITLE] + * @return array $result result of the query + */ + + public static function search( + $userUid, + $start = null, + $limit = null, + $search = null, + $process = null, + $status = null, + $dir = null, + $sort = null, + $category = null, + $dateFrom = null, + $dateTo = null, + $filterBy = 'APP_TITLE' + ) + { + // Default pagination values + $start = $start ? $start : 0; + $limit = $limit ? $limit : 25; + + // Start the query builder + $query = self::query(); + + // Add pagination to the query + $query = $query->offset($start) + ->limit($limit); + + // Fetch results and transform to a laravel collection + $results = collect($query->get()); + + // Transform with additional data + $priorities = ['1' => 'VL','2' => 'L','3' => 'N','4' => 'H','5' => 'VH']; + $results->transform(function($item, $key) use($priorities) { + // Grab related records + $application = Application::where('APP_UID', $item['APP_UID'])->first(); + if(!$application) { + // Application wasn't found, return null + return null; + } + $task = Task::where('TAS_ID', $item['TAS_ID'])->first(); + if(!$task) { + // Task not found, return null + return null; + } + $user = User::where('USR_ID', $item['USR_ID'])->first(); + if(!$user) { + // User not found, return null + return null; + } + $process = Process::where('PRO_ID', $item['PRO_ID'])->first();; + if(!$process) { + // Process not found, return null + return null; + } + + // Rewrite priority string + if($item['DEL_PRIORITY']) { + $item['DEL_PRIORITY'] = G::LoadTranslation( "ID_PRIORITY_{$priorities[$item['DEL_PRIORITY']]}" ); + } + + // Merge in desired application data + $item['APP_STATUS'] = $application->APP_STATUS; + if($item['APP_STATUS']) { + $item['APP_STATUS_LABEL'] = G::LoadTranslation( "ID_${item['APP_STATUS']}"); + } else { + $item['APP_STATUS_LABEL'] = $application->APP_STATUS; + } + $item['APP_CREATE_DATE'] = $application->APP_CREATE_DATE; + $item['APP_FINISH_DATE'] = $application->APP_FINISH_DATE; + $item['APP_UPDATE_DATE'] = $application->APP_UPDATE_DATE; + $item['APP_TITLE'] = $application->APP_TITLE; + + // Merge in desired process data + $item['APP_PRO_TITLE'] = $process->PRO_TITLE; + + // Merge in desired task data + $item['APP_TAS_TITLE'] = $task->TAS_TITLE; + $item['APP_TAS_TYPE'] = $task->TAS_TYPE; + + // Merge in desired user data + $item['USR_LASTNAME'] = $user->USR_LASTNAME; + $item['USR_FIRSTNAME'] = $user->USR_FIRSTNAME; + $item['USR_USERNAME'] = $user->USR_USERNAME; + + //@todo: this section needs to use 'User Name Display Format', currently in the extJs is defined this + $item["APP_CURRENT_USER"] = $item["USR_LASTNAME"].' '.$item["USR_FIRSTNAME"]; + + $item["APPDELCR_APP_TAS_TITLE"] = ''; + + $item["USRCR_USR_UID"] = $item["USR_UID"]; + $item["USRCR_USR_FIRSTNAME"] = $item["USR_FIRSTNAME"]; + $item["USRCR_USR_LASTNAME"] = $item["USR_LASTNAME"]; + $item["USRCR_USR_USERNAME"] = $item["USR_USERNAME"]; + $item["APP_OVERDUE_PERCENTAGE"] = ''; + + return $item; + }); + + // Remove any empty erroenous data + $results = $results->filter(); + + // Bundle into response array + $response = [ + // Fake totalCount to show pagination + 'totalCount' => $start + $limit + 1, + 'data' => $results->toArray() + ]; + + return $response; + } + } From 141e358b6b22647e78beddc25f387ba3b329a8ee Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Thu, 25 Apr 2019 15:58:26 -0700 Subject: [PATCH 06/31] Remove commented line in proxyCasesList. Add filtering support for task title and application only when requested. --- .../engine/methods/cases/proxyCasesList.php | 2 -- .../src/ProcessMaker/Model/Delegation.php | 27 ++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/workflow/engine/methods/cases/proxyCasesList.php b/workflow/engine/methods/cases/proxyCasesList.php index a5b0b7779..fbe9bd03e 100644 --- a/workflow/engine/methods/cases/proxyCasesList.php +++ b/workflow/engine/methods/cases/proxyCasesList.php @@ -100,8 +100,6 @@ try { break; } - //$apps = new Applications(); - if ($action == 'search') { $data = Delegation::search( $userUid, diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 332822c1f..0ce42fecf 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -88,6 +88,31 @@ class Delegation extends Model // Start the query builder $query = self::query(); + // Add join for task, filtering for task title if needed + // It doesn't make sense for us to search for any delegations that match tasks that are events or web entry + $query->join('TASK', function($join) use($filterBy, $search) { + $join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID') + ->whereNotIn('TASK.TAS_TYPE', [ + 'WEBENTRYEVENT', + 'END-MESSAGE-EVENT', + 'START-MESSAGE-EVENT', + 'INTERMEDIATE-THROW' + ]); + if($filterBy == 'TAS_TITLE') { + $join->where('TASK.TAS_TITLE', 'LIKE', "%${search}%"); + } + }); + + // Add join for application, but only for certain scenarios of app title search or sorting by app title + if($filterBy == 'APP_TITLE' || $sort == 'APP_TITLE') { + $query->join('APPLICATION', function($join) use($filterBy, $search) { + $join->on('APP_DELEGATION.APP_UID', '=', 'APPLICATION.APP_UID'); + if($filterBy == 'APP_TITLE') { + $join->where('APPLICATION.APP_TITLE', 'LIKE', "%${search}%"); + } + }); + } + // Add pagination to the query $query = $query->offset($start) ->limit($limit); @@ -99,7 +124,7 @@ class Delegation extends Model $priorities = ['1' => 'VL','2' => 'L','3' => 'N','4' => 'H','5' => 'VH']; $results->transform(function($item, $key) use($priorities) { // Grab related records - $application = Application::where('APP_UID', $item['APP_UID'])->first(); + $application = Application::where('APP_NUMBER', $item['APP_NUMBER'])->first(); if(!$application) { // Application wasn't found, return null return null; From c1a6bf9c77bd5616a58bd19f2ac832bebdca68de Mon Sep 17 00:00:00 2001 From: dante Date: Thu, 25 Apr 2019 19:00:41 -0400 Subject: [PATCH 07/31] Classic Processes Factory --- database/factories/ProcessFactory.php | 36 +++++++++++++++++++++++++-- database/factories/RouteFactory.php | 23 +++++++++++++++++ database/factories/TaskFactory.php | 32 ++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 database/factories/RouteFactory.php create mode 100644 database/factories/TaskFactory.php diff --git a/database/factories/ProcessFactory.php b/database/factories/ProcessFactory.php index d8a60d371..ad3f557c9 100644 --- a/database/factories/ProcessFactory.php +++ b/database/factories/ProcessFactory.php @@ -9,9 +9,41 @@ $factory->define(\ProcessMaker\Model\Process::class, function(Faker $faker) { /** * @todo Determine if we need more base columns populated */ - return [ + $process = [ 'PRO_UID' => G::generateUniqueID(), 'PRO_TITLE' => $faker->sentence(3), - 'PRO_DESCRIPTION' => $faker->paragraph(3) + 'PRO_DESCRIPTION' => $faker->paragraph(3), + 'PRO_CREATE_USER' => '00000000000000000000000000000001', + 'PRO_DYNAFORMS' => '', + 'PRO_ITEE' => 1, ]; + + $task1 = factory(\ProcessMaker\Model\Task::class) + ->create([ + 'PRO_UID' => $process['PRO_UID'], + 'TAS_START'=>'TRUE', + 'TAS_TITLE'=>'Task A' + ]); + + $task2 = factory(\ProcessMaker\Model\Task::class) + ->create([ + 'PRO_UID' => $process['PRO_UID'], + 'TAS_TITLE' => 'Task B' + ]); + + factory(\ProcessMaker\Model\Route::class) + ->create([ + 'PRO_UID' => $process['PRO_UID'], + 'TAS_UID' => $task2['TAS_UID'], + 'ROU_NEXT_TASK' => '-1', + ]); + + factory(\ProcessMaker\Model\Route::class) + ->create([ + 'PRO_UID' => $process['PRO_UID'], + 'TAS_UID' => $task1['TAS_UID'], + 'ROU_NEXT_TASK' => $task2['TAS_UID'] + ]); + + return $process; }); \ No newline at end of file diff --git a/database/factories/RouteFactory.php b/database/factories/RouteFactory.php new file mode 100644 index 000000000..7e649a31f --- /dev/null +++ b/database/factories/RouteFactory.php @@ -0,0 +1,23 @@ +define(\ProcessMaker\Model\Route::class, function(Faker $faker) { + + return [ + 'PRO_UID' => function() { + $process = factory(\ProcessMaker\Model\Process::class)->create(); + return $process->PRO_UID; + }, + 'TAS_UID' => function() { + $task = factory(\ProcessMaker\Model\Task::class)->create(); + return $task->TAS_UID; + }, + 'ROU_UID' => G::generateUniqueID(), + 'ROU_PARENT' => 0, + 'ROU_CASE' => 1, + 'ROU_TYPE' => 'SEQUENTIAL' + ]; +}); \ No newline at end of file diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php new file mode 100644 index 000000000..4ebc5a1d6 --- /dev/null +++ b/database/factories/TaskFactory.php @@ -0,0 +1,32 @@ +define(\ProcessMaker\Model\Task::class, function(Faker $faker) { + + return [ + 'PRO_UID' => function() { + $process = factory(\ProcessMaker\Model\Process::class)->create(); + return $process->PRO_UID; + }, + 'TAS_UID' => G::generateUniqueID(), + 'TAS_TITLE' => $faker->sentence(2), + 'TAS_TYPE' => 'NORMAL', + 'TAS_TYPE_DAY' => 1, + 'TAS_DURATION' => 1, + 'TAS_ASSIGN_TYPE' => 'BALANCED', + 'TAS_ASSIGN_VARIABLE' => '@@SYS_NEXT_USER_TO_BE_ASSIGNED', + 'TAS_MI_INSTANCE_VARIABLE' => '@@SYS_VAR_TOTAL_INSTANCE', + 'TAS_MI_COMPLETE_VARIABLE' => '@@SYS_VAR_TOTAL_INSTANCES_COMPLETE', + 'TAS_ASSIGN_LOCATION' => 'FALSE', + 'TAS_ASSIGN_LOCATION_ADHOC' => 'FALSE', + 'TAS_TRANSFER_FLY' => 'FALSE', + 'TAS_LAST_ASSIGNED' => 0, + 'TAS_USER' => 'FALSE', + 'TAS_CAN_UPLOAD' => 'FALSE', + 'TAS_CAN_CANCEL' => 'FALSE', + 'TAS_OWNER_APP' => 'FALSE', + ]; +}); \ No newline at end of file From ea6b0301931d071fb838cf5cedb6e663303ea11a Mon Sep 17 00:00:00 2001 From: dante Date: Thu, 25 Apr 2019 19:02:23 -0400 Subject: [PATCH 08/31] Model for ROUTE table --- .../engine/src/ProcessMaker/Model/Route.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 workflow/engine/src/ProcessMaker/Model/Route.php diff --git a/workflow/engine/src/ProcessMaker/Model/Route.php b/workflow/engine/src/ProcessMaker/Model/Route.php new file mode 100644 index 000000000..6be408ac0 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/Route.php @@ -0,0 +1,19 @@ + Date: Thu, 25 Apr 2019 16:10:12 -0700 Subject: [PATCH 09/31] Add some sort functionality and app title, case number and task title searching working properly. --- .../src/ProcessMaker/Model/Delegation.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 0ce42fecf..e443e092a 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -81,6 +81,8 @@ class Delegation extends Model $filterBy = 'APP_TITLE' ) { + $search = trim($search); + // Default pagination values $start = $start ? $start : 0; $limit = $limit ? $limit : 25; @@ -104,7 +106,7 @@ class Delegation extends Model }); // Add join for application, but only for certain scenarios of app title search or sorting by app title - if($filterBy == 'APP_TITLE' || $sort == 'APP_TITLE') { + if(($filterBy == 'APP_TITLE' && $search) || $sort == 'APP_TITLE') { $query->join('APPLICATION', function($join) use($filterBy, $search) { $join->on('APP_DELEGATION.APP_UID', '=', 'APPLICATION.APP_UID'); if($filterBy == 'APP_TITLE') { @@ -113,6 +115,19 @@ class Delegation extends Model }); } + if($filterBy == 'APP_NUMBER') { + $query->where('APP_DELEGATION.APP_NUMBER', 'LIKE', "%${search}%"); + } + + // Add any sort if needed + if($sort) { + // Clean up any specific sort parameters + if($sort == 'APP_NUMBER') { + $sort = 'APP_DELEGATION.APP_NUMBER'; + } + $query->orderBy($sort, $dir); + } + // Add pagination to the query $query = $query->offset($start) ->limit($limit); @@ -195,6 +210,7 @@ class Delegation extends Model $response = [ // Fake totalCount to show pagination 'totalCount' => $start + $limit + 1, + 'sql' => $query->toSql(), 'data' => $results->toArray() ]; From d3a944c2f62c5758020c9358651ed5219c96791f Mon Sep 17 00:00:00 2001 From: dante Date: Thu, 25 Apr 2019 19:11:37 -0400 Subject: [PATCH 10/31] User assignment for created tasks --- database/factories/ProcessFactory.php | 14 ++++++++++++++ database/factories/TaskFactory.php | 2 +- .../engine/src/ProcessMaker/Model/TaskUser.php | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 workflow/engine/src/ProcessMaker/Model/TaskUser.php diff --git a/database/factories/ProcessFactory.php b/database/factories/ProcessFactory.php index ad3f557c9..12e60c998 100644 --- a/database/factories/ProcessFactory.php +++ b/database/factories/ProcessFactory.php @@ -31,6 +31,7 @@ $factory->define(\ProcessMaker\Model\Process::class, function(Faker $faker) { 'TAS_TITLE' => 'Task B' ]); + //routes factory(\ProcessMaker\Model\Route::class) ->create([ 'PRO_UID' => $process['PRO_UID'], @@ -45,5 +46,18 @@ $factory->define(\ProcessMaker\Model\Process::class, function(Faker $faker) { 'ROU_NEXT_TASK' => $task2['TAS_UID'] ]); + //User assignments + factory(\ProcessMaker\Model\TaskUser::class) + ->create([ + 'TAS_UID' => $task1['TAS_UID'], + 'USR_UID' => \ProcessMaker\Model\User::all()->random()->USR_UID + ]); + + factory(\ProcessMaker\Model\TaskUser::class) + ->create([ + 'TAS_UID' => $task2['TAS_UID'], + 'USR_UID' => \ProcessMaker\Model\User::all()->random()->USR_UID + ]); + return $process; }); \ No newline at end of file diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php index 4ebc5a1d6..bf196690f 100644 --- a/database/factories/TaskFactory.php +++ b/database/factories/TaskFactory.php @@ -24,7 +24,7 @@ $factory->define(\ProcessMaker\Model\Task::class, function(Faker $faker) { 'TAS_ASSIGN_LOCATION_ADHOC' => 'FALSE', 'TAS_TRANSFER_FLY' => 'FALSE', 'TAS_LAST_ASSIGNED' => 0, - 'TAS_USER' => 'FALSE', + 'TAS_USER' => 0, 'TAS_CAN_UPLOAD' => 'FALSE', 'TAS_CAN_CANCEL' => 'FALSE', 'TAS_OWNER_APP' => 'FALSE', diff --git a/workflow/engine/src/ProcessMaker/Model/TaskUser.php b/workflow/engine/src/ProcessMaker/Model/TaskUser.php new file mode 100644 index 000000000..67549792b --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/TaskUser.php @@ -0,0 +1,12 @@ + Date: Thu, 25 Apr 2019 19:23:54 -0400 Subject: [PATCH 11/31] User factory --- database/factories/TaskUserFactory.php | 17 +++++++++++++++++ database/factories/UserFactory.php | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 database/factories/TaskUserFactory.php create mode 100644 database/factories/UserFactory.php diff --git a/database/factories/TaskUserFactory.php b/database/factories/TaskUserFactory.php new file mode 100644 index 000000000..751c491f7 --- /dev/null +++ b/database/factories/TaskUserFactory.php @@ -0,0 +1,17 @@ +define(\ProcessMaker\Model\TaskUser::class, function(Faker $faker) { + + return [ + 'TAS_UID' => function() { + $task = factory(\ProcessMaker\Model\Task::class)->create(); + return $task->TAS_UID; + }, + 'TU_TYPE' => 1, + 'TU_RELATION' => 1 + ]; +}); \ No newline at end of file diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php new file mode 100644 index 000000000..0eff02f51 --- /dev/null +++ b/database/factories/UserFactory.php @@ -0,0 +1,20 @@ +define(\ProcessMaker\Model\User::class, function(Faker $faker) { + + return [ + 'USR_UID' => G::generateUniqueID(), + 'USR_USERNAME' => $faker->unique()->userName, + 'USR_PASSWORD' => $faker->password, + 'USR_FIRSTNAME' => $faker->firstName, + 'USR_LASTNAME' => $faker->lastName, + 'USR_EMAIL' => $faker->unique()->email, + 'USR_DUE_DATE' => new \Carbon\Carbon(2030,1,1), + 'USR_STATUS' => 'ACTIVE', + 'USR_ROLE' => $faker->randomElement(['PROCESSMAKER_ADMIN', 'PROCESSMAKER_OPERATOR']), + 'USR_UX' => 'NORMAL', + 'USR_TIME_ZONE' => 'America/Anguilla', + 'USR_DEFAULT_LANG' => 'en', + ]; +}); \ No newline at end of file From 0331e65626630628f933df97789f49904764aa4c Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Thu, 25 Apr 2019 16:50:52 -0700 Subject: [PATCH 12/31] Make sure all sorting works. Verify process category selection. Use date range selection. --- .../src/ProcessMaker/Model/Application.php | 5 +- .../src/ProcessMaker/Model/Delegation.php | 74 ++++++++++++++++--- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index 2ca974844..38e30c69c 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -7,9 +7,8 @@ use Illuminate\Database\Eloquent\Model; class Application extends Model { protected $table = "APPLICATION"; - // Our custom timestamp columns - const CREATED_AT = 'APP_CREATE_DATE'; - const UPDATED_AT = 'APP_UPDATE_DATE'; + // No timestamps + public $timestamps = false; public function delegations() { diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index e443e092a..c5e7a86f5 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -100,32 +100,83 @@ class Delegation extends Model 'START-MESSAGE-EVENT', 'INTERMEDIATE-THROW' ]); - if($filterBy == 'TAS_TITLE') { + if($filterBy == 'TAS_TITLE' && $search) { $join->where('TASK.TAS_TITLE', 'LIKE', "%${search}%"); } }); - // Add join for application, but only for certain scenarios of app title search or sorting by app title - if(($filterBy == 'APP_TITLE' && $search) || $sort == 'APP_TITLE') { + // Add join for application, but only for certain scenarios of app title search or sorting by app title, update_date or status + if(($filterBy == 'APP_TITLE' && $search) || $sort == 'APP_TITLE' || $sort == 'APP_UPDATE_DATE' || $sort == 'APP_STATUS') { $query->join('APPLICATION', function($join) use($filterBy, $search) { $join->on('APP_DELEGATION.APP_UID', '=', 'APPLICATION.APP_UID'); - if($filterBy == 'APP_TITLE') { + if($filterBy == 'APP_TITLE' && $search) { $join->where('APPLICATION.APP_TITLE', 'LIKE', "%${search}%"); } }); } - if($filterBy == 'APP_NUMBER') { + // Add join for process, but only for certain scenarios such as category or process + if(($category && !$process) || $sort == 'APP_PRO_TITLE') { + $query->join('PROCESS', function($join) use ($category) { + $join->on('APP_DELEGATION.PRO_ID', '=', 'PROCESS.PRO_ID'); + if($category) { + $join->where('PROCESS.PRO_CATEGORY', $category); + } + }); + } + + // Add join for user, but only for certain scenarios as sorting + if($sort == 'APP_CURRENT_USER') { + $query->join('USERS', function($join) use ($userUid) { + $join->on('APP_DELEGATION.USR_ID', '=', 'USERS.USR_ID'); + }); + } + + // Search for specified user + if($userUid) { + $query->where('APP_DELEGATION.USR_ID', $userUid); + } + + // Search for specified process + if($process) { + $query->where('APP_DELEGATION.PRO_ID', $process); + } + + // Search for an app/case number + if($filterBy == 'APP_NUMBER' && $search) { $query->where('APP_DELEGATION.APP_NUMBER', 'LIKE', "%${search}%"); } + // Date range filter + if (!empty($dateFrom)) { + $query->where('APP_DELEGATION.DEL_DELEGATE_DATE', '>=', $dateFrom); + } + if (!empty($dateTo)) { + $dateTo = $dateTo . " 23:59:59"; + // This is inclusive + $query->where('APP_DELEGATION.DEL_DELEGATE_DATE', '<=', $dateTo); + } + + // Add any sort if needed - if($sort) { - // Clean up any specific sort parameters - if($sort == 'APP_NUMBER') { - $sort = 'APP_DELEGATION.APP_NUMBER'; - } - $query->orderBy($sort, $dir); + switch($sort) { + case 'APP_NUMBER': + $query->orderBy('APP_DELEGATION.APP_NUMBER', $dir); + break; + case 'APP_PRO_TITLE': + // We can do this because we joined the process table if sorting by it + $query->orderBy('PROCESS.PRO_TITLE', $dir); + break; + case 'APP_TAS_TITLE': + $query->orderBy('TASK.TAS_TITLE', $dir); + break; + case 'APP_CURRENT_USER': + // We can do this because we joined the user table if sorting by it + $query->orderBy('USERS.USR_LASTNAME', $dir); + $query->orderBy('USERS.USR_FIRSTNAME', $dir); + break; + default: + $query->orderBy($sort, $dir); } // Add pagination to the query @@ -211,6 +262,7 @@ class Delegation extends Model // Fake totalCount to show pagination 'totalCount' => $start + $limit + 1, 'sql' => $query->toSql(), + 'bindings' => $query->getBindings(), 'data' => $results->toArray() ]; From 52a877bb943d7edbb3c7fb763a38f54905c4e426 Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Thu, 25 Apr 2019 17:28:15 -0700 Subject: [PATCH 13/31] Add status filtering. Status always requires us joining on application. --- .../src/ProcessMaker/Model/Delegation.php | 124 ++++++++++++------ 1 file changed, 86 insertions(+), 38 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index c5e7a86f5..5023d173a 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -2,8 +2,8 @@ namespace ProcessMaker\Model; -use Illuminate\Database\Eloquent\Model; use G; +use Illuminate\Database\Eloquent\Model; class Delegation extends Model { @@ -79,8 +79,7 @@ class Delegation extends Model $dateFrom = null, $dateTo = null, $filterBy = 'APP_TITLE' - ) - { + ) { $search = trim($search); // Default pagination values @@ -92,58 +91,76 @@ class Delegation extends Model // Add join for task, filtering for task title if needed // It doesn't make sense for us to search for any delegations that match tasks that are events or web entry - $query->join('TASK', function($join) use($filterBy, $search) { + $query->join('TASK', function ($join) use ($filterBy, $search) { $join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID') ->whereNotIn('TASK.TAS_TYPE', [ 'WEBENTRYEVENT', 'END-MESSAGE-EVENT', 'START-MESSAGE-EVENT', - 'INTERMEDIATE-THROW' + 'INTERMEDIATE-THROW', ]); - if($filterBy == 'TAS_TITLE' && $search) { + if ($filterBy == 'TAS_TITLE' && $search) { $join->where('TASK.TAS_TITLE', 'LIKE', "%${search}%"); } }); - // Add join for application, but only for certain scenarios of app title search or sorting by app title, update_date or status - if(($filterBy == 'APP_TITLE' && $search) || $sort == 'APP_TITLE' || $sort == 'APP_UPDATE_DATE' || $sort == 'APP_STATUS') { - $query->join('APPLICATION', function($join) use($filterBy, $search) { - $join->on('APP_DELEGATION.APP_UID', '=', 'APPLICATION.APP_UID'); - if($filterBy == 'APP_TITLE' && $search) { - $join->where('APPLICATION.APP_TITLE', 'LIKE', "%${search}%"); - } - }); - } + // Add join for application, taking care of status and filtering if necessary + $query->join('APPLICATION', function ($join) use ($filterBy, $search, $status, $query) { + $join->on('APP_DELEGATION.APP_UID', '=', 'APPLICATION.APP_UID'); + if ($filterBy == 'APP_TITLE' && $search) { + $join->where('APPLICATION.APP_TITLE', 'LIKE', "%${search}%"); + } + // Based on the below, we can further limit the join so that we have a smaller data set based on join criteria + switch ($status) { + case 1: //DRAFT + $join->where('APPLICATION.APP_STATUS_ID', 1); + break; + case 2: //TO_DO + $join->where('APPLICATION.APP_STATUS_ID', 2); + break; + case 3: //COMPLETED + $join->where('APPLICATION.APP_STATUS_ID', 3); + break; + case 4: //CANCELLED + $join->where('APPLICATION.APP_STATUS_ID', 4); + break; + case "PAUSED": + $join->where('APPLICATION.APP_STATUS', 'TO_DO'); + break; + default: //All status + // Don't do anything here, we'll need to do the more advanced where below + } + }); // Add join for process, but only for certain scenarios such as category or process - if(($category && !$process) || $sort == 'APP_PRO_TITLE') { - $query->join('PROCESS', function($join) use ($category) { + if (($category && !$process) || $sort == 'APP_PRO_TITLE') { + $query->join('PROCESS', function ($join) use ($category) { $join->on('APP_DELEGATION.PRO_ID', '=', 'PROCESS.PRO_ID'); - if($category) { + if ($category) { $join->where('PROCESS.PRO_CATEGORY', $category); } }); } // Add join for user, but only for certain scenarios as sorting - if($sort == 'APP_CURRENT_USER') { - $query->join('USERS', function($join) use ($userUid) { + if ($sort == 'APP_CURRENT_USER') { + $query->join('USERS', function ($join) use ($userUid) { $join->on('APP_DELEGATION.USR_ID', '=', 'USERS.USR_ID'); }); } // Search for specified user - if($userUid) { + if ($userUid) { $query->where('APP_DELEGATION.USR_ID', $userUid); } // Search for specified process - if($process) { + if ($process) { $query->where('APP_DELEGATION.PRO_ID', $process); } // Search for an app/case number - if($filterBy == 'APP_NUMBER' && $search) { + if ($filterBy == 'APP_NUMBER' && $search) { $query->where('APP_DELEGATION.APP_NUMBER', 'LIKE', "%${search}%"); } @@ -157,9 +174,40 @@ class Delegation extends Model $query->where('APP_DELEGATION.DEL_DELEGATE_DATE', '<=', $dateTo); } + // Status Filter + // This is tricky, the below behavior is combined with the application join behavior above + switch ($status) { + case 1: //DRAFT + $query->where('APP_DELEGATION.DEL_THREAD_STATUS', 'OPEN'); + break; + case 2: //TO_DO + $query->where('APP_DELEGATION.DEL_THREAD_STATUS', 'OPEN'); + break; + case 3: //COMPLETED + $query->where('APP_DELEGATION.DEL_LAST_INDEX', 1); + break; + case 4: //CANCELLED + $query->where('APP_DELEGATION.DEL_LAST_INDEX', 1); + break; + case "PAUSED": + // Do nothing, as the app status check for TO_DO is performed in the join above + break; + default: //All statuses. + $query->where(function ($query) { + // Check to see if thread status is open + $query->where('APP_DELEGATION.DEL_THREAD_STATUS', 'OPEN') + ->orWhere(function ($query) { + // Or, we make sure if the thread is closed, and it's the last delegation, and if the app is completed or cancelled + $query->where('APP_DELEGATION.DEL_THREAD_STATUS', 'CLOSED') + ->where('APP_DELEGATION.DEL_LAST_INDEX', 1) + ->whereIn('APPLICATION.APP_STATUS_ID', [3, 4]); + }); + }); + break; + } // Add any sort if needed - switch($sort) { + switch ($sort) { case 'APP_NUMBER': $query->orderBy('APP_DELEGATION.APP_NUMBER', $dir); break; @@ -187,39 +235,39 @@ class Delegation extends Model $results = collect($query->get()); // Transform with additional data - $priorities = ['1' => 'VL','2' => 'L','3' => 'N','4' => 'H','5' => 'VH']; - $results->transform(function($item, $key) use($priorities) { + $priorities = ['1' => 'VL', '2' => 'L', '3' => 'N', '4' => 'H', '5' => 'VH']; + $results->transform(function ($item, $key) use ($priorities) { // Grab related records $application = Application::where('APP_NUMBER', $item['APP_NUMBER'])->first(); - if(!$application) { + if (!$application) { // Application wasn't found, return null return null; } $task = Task::where('TAS_ID', $item['TAS_ID'])->first(); - if(!$task) { + if (!$task) { // Task not found, return null return null; } $user = User::where('USR_ID', $item['USR_ID'])->first(); - if(!$user) { + if (!$user) { // User not found, return null return null; } $process = Process::where('PRO_ID', $item['PRO_ID'])->first();; - if(!$process) { + if (!$process) { // Process not found, return null return null; } - + // Rewrite priority string - if($item['DEL_PRIORITY']) { - $item['DEL_PRIORITY'] = G::LoadTranslation( "ID_PRIORITY_{$priorities[$item['DEL_PRIORITY']]}" ); + if ($item['DEL_PRIORITY']) { + $item['DEL_PRIORITY'] = G::LoadTranslation("ID_PRIORITY_{$priorities[$item['DEL_PRIORITY']]}"); } // Merge in desired application data $item['APP_STATUS'] = $application->APP_STATUS; - if($item['APP_STATUS']) { - $item['APP_STATUS_LABEL'] = G::LoadTranslation( "ID_${item['APP_STATUS']}"); + if ($item['APP_STATUS']) { + $item['APP_STATUS_LABEL'] = G::LoadTranslation("ID_${item['APP_STATUS']}"); } else { $item['APP_STATUS_LABEL'] = $application->APP_STATUS; } @@ -234,14 +282,14 @@ class Delegation extends Model // Merge in desired task data $item['APP_TAS_TITLE'] = $task->TAS_TITLE; $item['APP_TAS_TYPE'] = $task->TAS_TYPE; - + // Merge in desired user data $item['USR_LASTNAME'] = $user->USR_LASTNAME; $item['USR_FIRSTNAME'] = $user->USR_FIRSTNAME; $item['USR_USERNAME'] = $user->USR_USERNAME; //@todo: this section needs to use 'User Name Display Format', currently in the extJs is defined this - $item["APP_CURRENT_USER"] = $item["USR_LASTNAME"].' '.$item["USR_FIRSTNAME"]; + $item["APP_CURRENT_USER"] = $item["USR_LASTNAME"] . ' ' . $item["USR_FIRSTNAME"]; $item["APPDELCR_APP_TAS_TITLE"] = ''; @@ -263,7 +311,7 @@ class Delegation extends Model 'totalCount' => $start + $limit + 1, 'sql' => $query->toSql(), 'bindings' => $query->getBindings(), - 'data' => $results->toArray() + 'data' => $results->toArray(), ]; return $response; From 9768f07a1e16a65f1bf10fb2bc5acc21e96f9694 Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Thu, 25 Apr 2019 18:02:32 -0700 Subject: [PATCH 14/31] Add change to always bring in specific columns since we always join on task and application in search. --- .../src/ProcessMaker/Model/Delegation.php | 62 ++++++++++++------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 5023d173a..8e272c311 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -4,6 +4,7 @@ namespace ProcessMaker\Model; use G; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\DB; class Delegation extends Model { @@ -86,8 +87,41 @@ class Delegation extends Model $start = $start ? $start : 0; $limit = $limit ? $limit : 25; - // Start the query builder - $query = self::query(); + // Start the query builder, selecting our base attributes + $selectColumns = [ + 'APPLICATION.APP_NUMBER', + 'APPLICATION.APP_UID', + 'APPLICATION.APP_STATUS', + 'APPLICATION.APP_STATUS AS APP_STATUS_LABEL', + 'APPLICATION.PRO_UID', + 'APPLICATION.APP_CREATE_DATE', + 'APPLICATION.APP_FINISH_DATE', + 'APPLICATION.APP_UPDATE_DATE', + 'APPLICATION.APP_TITLE', + 'APP_DELEGATION.USR_UID', + 'APP_DELEGATION.TAS_UID', + 'APP_DELEGATION.USR_ID', + 'APP_DELEGATION.PRO_ID', + 'APP_DELEGATION.DEL_INDEX', + 'APP_DELEGATION.DEL_LAST_INDEX', + 'APP_DELEGATION.DEL_DELEGATE_DATE', + 'APP_DELEGATION.DEL_INIT_DATE', + 'APP_DELEGATION.DEL_FINISH_DATE', + 'APP_DELEGATION.DEL_TASK_DUE_DATE', + 'APP_DELEGATION.DEL_RISK_DATE', + 'APP_DELEGATION.DEL_THREAD_STATUS', + 'APP_DELEGATION.DEL_PRIORITY', + 'APP_DELEGATION.DEL_DURATION', + 'APP_DELEGATION.DEL_QUEUE_DURATION', + 'APP_DELEGATION.DEL_STARTED', + 'APP_DELEGATION.DEL_DELAY_DURATION', + 'APP_DELEGATION.DEL_FINISHED', + 'APP_DELEGATION.DEL_DELAYED', + 'APP_DELEGATION.DEL_DELAY_DURATION', + 'TASK.TAS_TITLE AS APP_TAS_TITLE', + 'TASK.TAS_TYPE AS APP_TAS_TYPE', + ]; + $query = DB::table('APP_DELEGATION')->select(DB::raw(implode(',', $selectColumns))); // Add join for task, filtering for task title if needed // It doesn't make sense for us to search for any delegations that match tasks that are events or web entry @@ -232,22 +266,13 @@ class Delegation extends Model ->limit($limit); // Fetch results and transform to a laravel collection - $results = collect($query->get()); + $results = $query->get(); // Transform with additional data $priorities = ['1' => 'VL', '2' => 'L', '3' => 'N', '4' => 'H', '5' => 'VH']; $results->transform(function ($item, $key) use ($priorities) { - // Grab related records - $application = Application::where('APP_NUMBER', $item['APP_NUMBER'])->first(); - if (!$application) { - // Application wasn't found, return null - return null; - } - $task = Task::where('TAS_ID', $item['TAS_ID'])->first(); - if (!$task) { - // Task not found, return null - return null; - } + // Convert to an array as our results must be an array + $item = json_decode(json_encode($item), true); $user = User::where('USR_ID', $item['USR_ID'])->first(); if (!$user) { // User not found, return null @@ -265,24 +290,15 @@ class Delegation extends Model } // Merge in desired application data - $item['APP_STATUS'] = $application->APP_STATUS; if ($item['APP_STATUS']) { $item['APP_STATUS_LABEL'] = G::LoadTranslation("ID_${item['APP_STATUS']}"); } else { $item['APP_STATUS_LABEL'] = $application->APP_STATUS; } - $item['APP_CREATE_DATE'] = $application->APP_CREATE_DATE; - $item['APP_FINISH_DATE'] = $application->APP_FINISH_DATE; - $item['APP_UPDATE_DATE'] = $application->APP_UPDATE_DATE; - $item['APP_TITLE'] = $application->APP_TITLE; // Merge in desired process data $item['APP_PRO_TITLE'] = $process->PRO_TITLE; - // Merge in desired task data - $item['APP_TAS_TITLE'] = $task->TAS_TITLE; - $item['APP_TAS_TYPE'] = $task->TAS_TYPE; - // Merge in desired user data $item['USR_LASTNAME'] = $user->USR_LASTNAME; $item['USR_FIRSTNAME'] = $user->USR_FIRSTNAME; From 1936f5cf3b4ad33dc74fb8002b562706dac258e0 Mon Sep 17 00:00:00 2001 From: dante Date: Thu, 25 Apr 2019 21:15:43 -0400 Subject: [PATCH 15/31] Delegations Factory --- database/factories/ApplicationFactory.php | 24 ++++++++++++++ database/factories/DelegationFactory.php | 32 +++++++++++++++++++ database/factories/TaskFactory.php | 2 ++ .../engine/src/ProcessMaker/Model/Process.php | 7 ++++ 4 files changed, 65 insertions(+) create mode 100644 database/factories/ApplicationFactory.php create mode 100644 database/factories/DelegationFactory.php diff --git a/database/factories/ApplicationFactory.php b/database/factories/ApplicationFactory.php new file mode 100644 index 000000000..21f92aef2 --- /dev/null +++ b/database/factories/ApplicationFactory.php @@ -0,0 +1,24 @@ +define(\ProcessMaker\Model\Application::class, function(Faker $faker) { + + $process = \ProcessMaker\Model\Process::all()->random(); + return [ + 'APP_UID' => G::generateUniqueID(), + 'APP_TITLE' => G::generateUniqueID(), + 'APP_NUMBER' => $faker->unique()->numberBetween(1000), + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 1, + 'PRO_UID' => $process->PRO_UID, + 'APP_PARALLEL' => 'N', + 'APP_INIT_USER' => \ProcessMaker\Model\User::all()->random()->USR_UID, + 'APP_CUR_USER' => \ProcessMaker\Model\User::all()->random()->USR_UID, + 'APP_PIN' => G::generateUniqueID(), + 'APP_CREATE_DATE' => $faker->dateTime(), + 'APP_UPDATE_DATE' => $faker->dateTime(), + 'APP_INIT_DATE' => $faker->dateTime(), + 'APP_DATA' => serialize(['APP_NUMBER' => 12]) + ]; +}); \ No newline at end of file diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php new file mode 100644 index 000000000..d4590d275 --- /dev/null +++ b/database/factories/DelegationFactory.php @@ -0,0 +1,32 @@ +define(\ProcessMaker\Model\Delegation::class, function(Faker $faker) { + + $app = factory(\ProcessMaker\Model\Application::class)->create(); + $process = \ProcessMaker\Model\Process::where('PRO_UID', $app->PRO_UID)->first(); + $task = $process->tasks->first(); + $user = \ProcessMaker\Model\User::all()->random(); + return [ + 'APP_UID' => $app->APP_UID, + 'DEL_INDEX' => 1, + 'APP_NUMBER' => $app->APP_NUMBER, + 'DEL_PREVIOUS' => 0, + 'PRO_UID' => $app->PRO_UID, + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'DEL_TYPE' => 'NORMAL', + 'DEL_THREAD' => 1, + 'DEL_THREAD_STATUS' => 'OPEN', + 'DEL_PRIORITY' => 3, + 'DEL_DELEGATE_DATE' => $faker->dateTime(), + 'DEL_INIT_DATE' => $faker->dateTime(), + 'DEL_TASK_DUE_DATE' => $faker->dateTime(), + 'DEL_RISK_DATE' => $faker->dateTime(), + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'TAS_ID' => $task->TAS_ID, + 'DEL_DATA' => '' + ]; +}); \ No newline at end of file diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php index bf196690f..ea6548bde 100644 --- a/database/factories/TaskFactory.php +++ b/database/factories/TaskFactory.php @@ -28,5 +28,7 @@ $factory->define(\ProcessMaker\Model\Task::class, function(Faker $faker) { 'TAS_CAN_UPLOAD' => 'FALSE', 'TAS_CAN_CANCEL' => 'FALSE', 'TAS_OWNER_APP' => 'FALSE', + 'TAS_CAN_SEND_MESSAGE' => 'FALSE', + 'TAS_SEND_LAST_EMAIL' => 'FALSE', ]; }); \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/Process.php b/workflow/engine/src/ProcessMaker/Model/Process.php index abaac4e7a..e136f07a3 100644 --- a/workflow/engine/src/ProcessMaker/Model/Process.php +++ b/workflow/engine/src/ProcessMaker/Model/Process.php @@ -27,6 +27,13 @@ class Process extends Model } + + public function tasks() + { + return $this->hasMany(Task::class, 'PRO_UID', 'PRO_UID'); + + } + public function creator() { return $this->hasOne(User::class, 'PRO_CREATE_USER', 'USR_UID'); From ef6c0276d93bca013919ccdb04b44f366bada921 Mon Sep 17 00:00:00 2001 From: dante Date: Thu, 25 Apr 2019 21:40:21 -0400 Subject: [PATCH 16/31] Task names are randomly generated --- database/factories/ApplicationFactory.php | 7 +++++-- database/factories/ProcessFactory.php | 4 +--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/database/factories/ApplicationFactory.php b/database/factories/ApplicationFactory.php index 21f92aef2..e497e9c38 100644 --- a/database/factories/ApplicationFactory.php +++ b/database/factories/ApplicationFactory.php @@ -5,12 +5,15 @@ use ProcessMaker\BusinessModel\Cases as BmCases; $factory->define(\ProcessMaker\Model\Application::class, function(Faker $faker) { $process = \ProcessMaker\Model\Process::all()->random(); + $statuses = ['DRAFT', 'TO_DO']; + $status = $faker->randomElement($statuses); + $statusId = array_search($status, $statuses) + 1; return [ 'APP_UID' => G::generateUniqueID(), 'APP_TITLE' => G::generateUniqueID(), 'APP_NUMBER' => $faker->unique()->numberBetween(1000), - 'APP_STATUS' => 'TO_DO', - 'APP_STATUS_ID' => 1, + 'APP_STATUS' => $status, + 'APP_STATUS_ID' => $statusId, 'PRO_UID' => $process->PRO_UID, 'APP_PARALLEL' => 'N', 'APP_INIT_USER' => \ProcessMaker\Model\User::all()->random()->USR_UID, diff --git a/database/factories/ProcessFactory.php b/database/factories/ProcessFactory.php index 12e60c998..2ddbe0d0f 100644 --- a/database/factories/ProcessFactory.php +++ b/database/factories/ProcessFactory.php @@ -21,14 +21,12 @@ $factory->define(\ProcessMaker\Model\Process::class, function(Faker $faker) { $task1 = factory(\ProcessMaker\Model\Task::class) ->create([ 'PRO_UID' => $process['PRO_UID'], - 'TAS_START'=>'TRUE', - 'TAS_TITLE'=>'Task A' + 'TAS_START'=>'TRUE' ]); $task2 = factory(\ProcessMaker\Model\Task::class) ->create([ 'PRO_UID' => $process['PRO_UID'], - 'TAS_TITLE' => 'Task B' ]); //routes From 9fa4c1750ac5d11a1e7acec51df59bae3ae98b14 Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Fri, 26 Apr 2019 08:45:38 -0700 Subject: [PATCH 17/31] Join on APP NUMBER instead of APP_UID --- workflow/engine/src/ProcessMaker/Model/Delegation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 8e272c311..d2b3e60e2 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -140,7 +140,7 @@ class Delegation extends Model // Add join for application, taking care of status and filtering if necessary $query->join('APPLICATION', function ($join) use ($filterBy, $search, $status, $query) { - $join->on('APP_DELEGATION.APP_UID', '=', 'APPLICATION.APP_UID'); + $join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER'); if ($filterBy == 'APP_TITLE' && $search) { $join->where('APPLICATION.APP_TITLE', 'LIKE', "%${search}%"); } From 17e6ef344135feffaf0b26c9663baa73b5884637 Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Wed, 1 May 2019 13:49:05 -0700 Subject: [PATCH 18/31] Add sample tests. Change userUid argument to be properly userId. Do some safe checks in search. --- database/factories/DelegationFactory.php | 9 ++- .../src/ProcessMaker/Model/DelegationTest.php | 80 +++++++++++++++++++ .../src/ProcessMaker/Model/Delegation.php | 57 +++++++------ 3 files changed, 116 insertions(+), 30 deletions(-) create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php index d4590d275..4b7c6e947 100644 --- a/database/factories/DelegationFactory.php +++ b/database/factories/DelegationFactory.php @@ -7,7 +7,14 @@ $factory->define(\ProcessMaker\Model\Delegation::class, function(Faker $faker) { $app = factory(\ProcessMaker\Model\Application::class)->create(); $process = \ProcessMaker\Model\Process::where('PRO_UID', $app->PRO_UID)->first(); $task = $process->tasks->first(); - $user = \ProcessMaker\Model\User::all()->random(); + + // Grab a user if random + $users = \ProcessMaker\Model\User::all(); + if(!count($users)) { + $user = factory(\ProcessMaker\Model\User::class)->create(); + } else{ + $user = $users->random(); + } return [ 'APP_UID' => $app->APP_UID, 'DEL_INDEX' => 1, diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php new file mode 100644 index 000000000..06493e73a --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -0,0 +1,80 @@ +create(); + factory(\ProcessMaker\Model\Process::class,10)->create(); + factory(Delegation::class, 51)->create(); + // Get first page, which is 25 + $results = Delegation::search(null, 0, 25); + $this->assertCount(25, $results['data']); + // Get second page, which is 25 results + $results = Delegation::search(null, 25, 25); + $this->assertCount(25, $results['data']); + // Get third page, which is only 1 result + $results = Delegation::search(null, 50, 25); + $this->assertCount(1, $results['data']); + } + + /** + * This ensures searching for a valid user works + * @test + */ + public function it_should_return_one_result_for_specified_user() + { + factory(\ProcessMaker\Model\User::class,100)->create(); + factory(\ProcessMaker\Model\Process::class,10)->create(); + // Create our unique user, with a unique username + $user = factory(\ProcessMaker\Model\User::class)->create([ + 'USR_USERNAME' => 'testcaseuser' + ]); + // Create a new delegation, but for this specific user + factory(Delegation::class)->create([ + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->id + ]); + // Now fetch results, and assume delegation count is 1 and the user points to our user + $results = Delegation::search($user->id); + $this->assertCount(1, $results['data']); + $this->assertEquals('testcaseuser', $results['data'][0]['USRCR_USR_USERNAME']); + } + + /** + * @test + */ + public function it_should_have_data_match_certain_schema() + { + $this->markTestIncomplete(); + } + + /** + * @test + */ + public function it_should_sort_by_case_id() + { + $this->markTestIncomplete(); + } + + /** + * @test + */ + public function it_should_sort_by_user() + { + $this->markTestIncomplete(); + } +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index d2b3e60e2..9e157dbba 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -51,7 +51,7 @@ class Delegation extends Model * The query is related to advanced search with different filters * We can search by process, status of case, category of process, users, delegate date from and to * - * @param string $userUid + * @param integer $userId The USR_ID to search for (Note, this is no longer the USR_UID) * @param integer $start for the pagination * @param integer $limit for the pagination * @param string $search @@ -68,9 +68,10 @@ class Delegation extends Model */ public static function search( - $userUid, - $start = null, - $limit = null, + $userId = null, + // Default pagination values + $start = 0, + $limit = 25, $search = null, $process = null, $status = null, @@ -83,10 +84,6 @@ class Delegation extends Model ) { $search = trim($search); - // Default pagination values - $start = $start ? $start : 0; - $limit = $limit ? $limit : 25; - // Start the query builder, selecting our base attributes $selectColumns = [ 'APPLICATION.APP_NUMBER', @@ -178,14 +175,14 @@ class Delegation extends Model // Add join for user, but only for certain scenarios as sorting if ($sort == 'APP_CURRENT_USER') { - $query->join('USERS', function ($join) use ($userUid) { + $query->join('USERS', function ($join) use ($userId) { $join->on('APP_DELEGATION.USR_ID', '=', 'USERS.USR_ID'); }); } // Search for specified user - if ($userUid) { - $query->where('APP_DELEGATION.USR_ID', $userUid); + if ($userId) { + $query->where('APP_DELEGATION.USR_ID', $userId); } // Search for specified process @@ -241,24 +238,26 @@ class Delegation extends Model } // Add any sort if needed - switch ($sort) { - case 'APP_NUMBER': - $query->orderBy('APP_DELEGATION.APP_NUMBER', $dir); - break; - case 'APP_PRO_TITLE': - // We can do this because we joined the process table if sorting by it - $query->orderBy('PROCESS.PRO_TITLE', $dir); - break; - case 'APP_TAS_TITLE': - $query->orderBy('TASK.TAS_TITLE', $dir); - break; - case 'APP_CURRENT_USER': - // We can do this because we joined the user table if sorting by it - $query->orderBy('USERS.USR_LASTNAME', $dir); - $query->orderBy('USERS.USR_FIRSTNAME', $dir); - break; - default: - $query->orderBy($sort, $dir); + if($sort) { + switch ($sort) { + case 'APP_NUMBER': + $query->orderBy('APP_DELEGATION.APP_NUMBER', $dir); + break; + case 'APP_PRO_TITLE': + // We can do this because we joined the process table if sorting by it + $query->orderBy('PROCESS.PRO_TITLE', $dir); + break; + case 'APP_TAS_TITLE': + $query->orderBy('TASK.TAS_TITLE', $dir); + break; + case 'APP_CURRENT_USER': + // We can do this because we joined the user table if sorting by it + $query->orderBy('USERS.USR_LASTNAME', $dir); + $query->orderBy('USERS.USR_FIRSTNAME', $dir); + break; + default: + $query->orderBy($sort, $dir); + } } // Add pagination to the query From dd81f0f759a0a6755a9199f866f726e4baa4b645 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Wed, 1 May 2019 18:10:46 -0400 Subject: [PATCH 19/31] First unit test --- .../src/ProcessMaker/Model/DelegationTest.php | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 06493e73a..fb5c25dce 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -31,6 +31,95 @@ class DelegationTest extends TestCase $this->assertCount(1, $results['data']); } + /** + * This checks to make sure pagination is working properly with search by caseTitle + * @test + */ + public function it_should_return_pages_of_data_filter_default_case_title() + { + factory(\ProcessMaker\Model\User::class,100)->create(); + factory(\ProcessMaker\Model\Process::class,10)->create(); + factory(\ProcessMaker\Model\Application::class,100)->create(); + factory(Delegation::class, 51)->create(); + $search = '#'; + // Get first page, which is 25 + $results = Delegation::search(null, 0, 25, $search); + $this->assertCount(10, $results['data']); + // Get second page, which is 25 results + $results = Delegation::search(null, 25, 25, $search); + $this->assertCount(10, $results['data']); + // Get third page, which is only 1 result + $results = Delegation::search(null, 50, 25, $search); + $this->assertCount(1, $results['data']); + } + + /** + * This checks to make sure pagination is working properly with search by case title + * @test + */ + public function it_should_return_pages_of_data_filter_case_title() + { + factory(\ProcessMaker\Model\User::class,100)->create(); + factory(\ProcessMaker\Model\Process::class,10)->create(); + factory(\ProcessMaker\Model\Application::class,51)->create(); + factory(Delegation::class, 51)->create(); + $search = '#'; + // Get first page, which is 25 + $results = Delegation::search(null, 0, 25, $search, null, null, null, null, null, null, null, 'APP_TITLE'); + $this->assertCount(10, $results['data']); + // Get second page, which is 25 results + $results = Delegation::search(null, 0, 25, $search, null, null, null, null, null, null, null, 'APP_TITLE'); + $this->assertCount(10, $results['data']); + // Get third page, which is only 1 result + $results = Delegation::search(null, 0, 25, $search, null, null, null, null, null, null, null, 'APP_TITLE'); + $this->assertCount(1, $results['data']); + } + + /** + * This checks to make sure pagination is working properly with search by case number + * @test + */ + public function it_should_return_pages_of_data_filter_case_number() + { + factory(\ProcessMaker\Model\User::class,100)->create(); + factory(\ProcessMaker\Model\Process::class,10)->create(); + factory(\ProcessMaker\Model\Application::class,101)->create(); + factory(Delegation::class, 101)->create(); + $search = '1'; + // Get first page, which is 25 + $results = Delegation::search(null, 0, 10, $search, null, null, null, null, null, null, null, 'APP_NUMBER'); + $this->assertCount(10, $results['data']); + // Get second page, which is 25 results + $results = Delegation::search(null, 10, 10, $search, null, null, null, null, null, null, null, 'APP_NUMBER'); + $this->assertCount(10, $results['data']); + // Get third page, which is only 1 result + $results = Delegation::search(null, 20, 10, $search, null, null, null, null, null, null, null, 'APP_NUMBER'); + $this->assertCount(1, $results['data']); + } + + /** + * This checks to make sure pagination is working properly with search by case title + * @test + */ + public function it_should_return_pages_of_data_filter_task_title() + { + factory(\ProcessMaker\Model\User::class,100)->create(); + factory(\ProcessMaker\Model\Process::class,10)->create(); + factory(\ProcessMaker\Model\Task::class,200)->create(); + factory(Delegation::class, 51)->create(); + //I need to check the Faker names + $search = 'task'; + // Get first page, which is 25 + $results = Delegation::search(null, 0, 10, $search, null, null, null, null, null, null, null, 'TAS_TITLE'); + $this->assertCount(10, $results['data']); + // Get second page, which is 25 results + $results = Delegation::search(null, 10, 10, $search, null, null, null, null, null, null, null, 'TAS_TITLE'); + $this->assertCount(10, $results['data']); + // Get third page, which is only 1 result + $results = Delegation::search(null, 20, 10, $search, null, null, null, null, null, null, null, 'TAS_TITLE'); + $this->assertCount(1, $results['data']); + } + /** * This ensures searching for a valid user works * @test From 24368423c05dd59f363d846697c6ba96d6f3d26b Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 2 May 2019 10:53:43 -0400 Subject: [PATCH 20/31] conflicts --- .../src/ProcessMaker/Model/DelegationTest.php | 163 ++++++++++++------ .../src/ProcessMaker/Model/Delegation.php | 2 +- 2 files changed, 108 insertions(+), 57 deletions(-) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index fb5c25dce..7c064abef 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -2,9 +2,10 @@ namespace Tests\unit\workflow\src\ProcessMaker\Model; use Illuminate\Foundation\Testing\DatabaseTransactions; -use ProcessMaker\Model\User; -use ProcessMaker\Model\Process; +use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; +use ProcessMaker\Model\Process; +use ProcessMaker\Model\User; use Tests\TestCase; class DelegationTest extends TestCase @@ -17,8 +18,8 @@ class DelegationTest extends TestCase */ public function it_should_return_pages_of_data() { - factory(\ProcessMaker\Model\User::class,100)->create(); - factory(\ProcessMaker\Model\Process::class,10)->create(); + factory(User::class,100)->create(); + factory(Process::class,10)->create(); factory(Delegation::class, 51)->create(); // Get first page, which is 25 $results = Delegation::search(null, 0, 25); @@ -32,91 +33,141 @@ class DelegationTest extends TestCase } /** - * This checks to make sure pagination is working properly with search by caseTitle + * This checks to make sure filter by process is working properly * @test */ - public function it_should_return_pages_of_data_filter_default_case_title() + public function it_should_return_process_of_data() { - factory(\ProcessMaker\Model\User::class,100)->create(); - factory(\ProcessMaker\Model\Process::class,10)->create(); - factory(\ProcessMaker\Model\Application::class,100)->create(); - factory(Delegation::class, 51)->create(); - $search = '#'; + factory(User::class,100)->create(); + $process = factory(Process::class, 1)->create([ + 'PRO_ID' => 1 + ]); + factory(Delegation::class, 51)->create([ + 'PRO_ID' => $process[0]->id + ]); // Get first page, which is 25 - $results = Delegation::search(null, 0, 25, $search); - $this->assertCount(10, $results['data']); + $results = Delegation::search(null, 0, 25, null, $process[0]->id); + $this->assertCount(25, $results['data']); // Get second page, which is 25 results - $results = Delegation::search(null, 25, 25, $search); - $this->assertCount(10, $results['data']); + $results = Delegation::search(null, 25, 25,null, $process[0]->id); + $this->assertCount(25, $results['data']); // Get third page, which is only 1 result - $results = Delegation::search(null, 50, 25, $search); + $results = Delegation::search(null, 50, 25,null, $process[0]->id); $this->assertCount(1, $results['data']); } /** - * This checks to make sure pagination is working properly with search by case title + * This checks to make sure filter by status is working properly + * Review status filter by a specific status, such as Draft * @test */ - public function it_should_return_pages_of_data_filter_case_title() + public function it_should_return_status_draft_of_data() { - factory(\ProcessMaker\Model\User::class,100)->create(); - factory(\ProcessMaker\Model\Process::class,10)->create(); - factory(\ProcessMaker\Model\Application::class,51)->create(); - factory(Delegation::class, 51)->create(); - $search = '#'; + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2001, + 'APP_STATUS_ID' => 1 + ]);//DRAFT + factory(Delegation::class, 51)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Review the filter by status DRAFT // Get first page, which is 25 - $results = Delegation::search(null, 0, 25, $search, null, null, null, null, null, null, null, 'APP_TITLE'); - $this->assertCount(10, $results['data']); + $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); + $this->assertCount(25, $results['data']); // Get second page, which is 25 results - $results = Delegation::search(null, 0, 25, $search, null, null, null, null, null, null, null, 'APP_TITLE'); - $this->assertCount(10, $results['data']); + $results = Delegation::search(null, 25, 25,null, null, $application[0]->APP_STATUS_ID); + $this->assertCount(25, $results['data']); // Get third page, which is only 1 result - $results = Delegation::search(null, 0, 25, $search, null, null, null, null, null, null, null, 'APP_TITLE'); + $results = Delegation::search(null, 50, 25,null, null, $application[0]->APP_STATUS_ID); $this->assertCount(1, $results['data']); } /** - * This checks to make sure pagination is working properly with search by case number + * This checks to make sure filter by status is working properly + * Review status filter by a specific status, such as To Do * @test */ - public function it_should_return_pages_of_data_filter_case_number() + public function it_should_return_status_todo_of_data() { - factory(\ProcessMaker\Model\User::class,100)->create(); - factory(\ProcessMaker\Model\Process::class,10)->create(); - factory(\ProcessMaker\Model\Application::class,101)->create(); - factory(Delegation::class, 101)->create(); - $search = '1'; + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2001, + 'APP_STATUS_ID' => 2 + ]);//DRAFT + + factory(Delegation::class, 51)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Review the filter by status TO_DO // Get first page, which is 25 - $results = Delegation::search(null, 0, 10, $search, null, null, null, null, null, null, null, 'APP_NUMBER'); - $this->assertCount(10, $results['data']); + $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); + $this->assertCount(25, $results['data']); // Get second page, which is 25 results - $results = Delegation::search(null, 10, 10, $search, null, null, null, null, null, null, null, 'APP_NUMBER'); - $this->assertCount(10, $results['data']); + $results = Delegation::search(null, 25, 25,null, null, $application[0]->APP_STATUS_ID); + $this->assertCount(25, $results['data']); // Get third page, which is only 1 result - $results = Delegation::search(null, 20, 10, $search, null, null, null, null, null, null, null, 'APP_NUMBER'); + $results = Delegation::search(null, 50, 25,null, null, $application[0]->APP_STATUS_ID); $this->assertCount(1, $results['data']); } /** - * This checks to make sure pagination is working properly with search by case title + * This checks to make sure filter by status is working properly + * Review status filter by a specific status, such as Completed * @test */ - public function it_should_return_pages_of_data_filter_task_title() + public function it_should_return_status_completed_of_data() { - factory(\ProcessMaker\Model\User::class,100)->create(); - factory(\ProcessMaker\Model\Process::class,10)->create(); - factory(\ProcessMaker\Model\Task::class,200)->create(); - factory(Delegation::class, 51)->create(); - //I need to check the Faker names - $search = 'task'; + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2001, + 'APP_STATUS_ID' => 3 + ]);//DRAFT + + factory(Delegation::class, 51)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Review the filter by status DRAFT // Get first page, which is 25 - $results = Delegation::search(null, 0, 10, $search, null, null, null, null, null, null, null, 'TAS_TITLE'); - $this->assertCount(10, $results['data']); + $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); + $this->assertCount(25, $results['data']); // Get second page, which is 25 results - $results = Delegation::search(null, 10, 10, $search, null, null, null, null, null, null, null, 'TAS_TITLE'); - $this->assertCount(10, $results['data']); + $results = Delegation::search(null, 25, 25,null, null, $application[0]->APP_STATUS_ID); + $this->assertCount(25, $results['data']); // Get third page, which is only 1 result - $results = Delegation::search(null, 20, 10, $search, null, null, null, null, null, null, null, 'TAS_TITLE'); + $results = Delegation::search(null, 50, 25,null, null, $application[0]->APP_STATUS_ID); + $this->assertCount(1, $results['data']); + } + + /** + * This checks to make sure filter by status is working properly + * Review status filter by a specific status, such as Cancelled + * @test + */ + public function it_should_return_status_cancelled_of_data() + { + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2001, + 'APP_STATUS_ID' => 4 + ]);//DRAFT + + factory(Delegation::class, 51)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Review the filter by status DRAFT + // Get first page, which is 25 + $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); + $this->assertCount(25, $results['data']); + // Get second page, which is 25 results + $results = Delegation::search(null, 25, 25,null, null, $application[0]->APP_STATUS_ID); + $this->assertCount(25, $results['data']); + // Get third page, which is only 1 result + $results = Delegation::search(null, 50, 25,null, null, $application[0]->APP_STATUS_ID); $this->assertCount(1, $results['data']); } @@ -126,10 +177,10 @@ class DelegationTest extends TestCase */ public function it_should_return_one_result_for_specified_user() { - factory(\ProcessMaker\Model\User::class,100)->create(); - factory(\ProcessMaker\Model\Process::class,10)->create(); + factory(User::class,100)->create(); + factory(Process::class,10)->create(); // Create our unique user, with a unique username - $user = factory(\ProcessMaker\Model\User::class)->create([ + $user = factory(User::class)->create([ 'USR_USERNAME' => 'testcaseuser' ]); // Create a new delegation, but for this specific user diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 9e157dbba..304081921 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -326,7 +326,7 @@ class Delegation extends Model 'totalCount' => $start + $limit + 1, 'sql' => $query->toSql(), 'bindings' => $query->getBindings(), - 'data' => $results->toArray(), + 'data' => $results->values()->toArray(), ]; return $response; From 7b96da5bc5d9801cee013c10bd8e594a7f2eb9b4 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 2 May 2019 11:43:38 -0400 Subject: [PATCH 21/31] sort by case and user --- .../src/ProcessMaker/Model/DelegationTest.php | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 7c064abef..7951c33fd 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -203,18 +203,74 @@ class DelegationTest extends TestCase } /** + * This ensures ordering ascending works by case number * @test */ public function it_should_sort_by_case_id() { - $this->markTestIncomplete(); + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2001 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 30002 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Get first page, the minor case id + $results = Delegation::search(null, 0, 25, null, null, null, 'ASC', 'APP_NUMBER'); + $this->assertCount(2, $results['data']); + $this->assertEquals(2001, $results['data'][0]['APP_NUMBER']); + $this->assertEquals(30002, $results['data'][1]['APP_NUMBER']); + // Get first page, the major case id + $results = Delegation::search(null, 0, 25, null, null, null, 'DESC', 'APP_NUMBER'); + $this->assertCount(2, $results['data']); + $this->assertEquals(30002, $results['data'][0]['APP_NUMBER']); + $this->assertEquals(2001, $results['data'][1]['APP_NUMBER']); } /** + * This ensures ordering ascending and descending works by user * @test */ public function it_should_sort_by_user() { - $this->markTestIncomplete(); + factory(User::class,100)->create(); + factory(Process::class,10)->create(); + // Create our unique user, with a unique username + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'gary', + 'USR_LASTNAME' => 'Gary', + 'USR_FIRSTNAME' => 'Bailey', + ]); + // Create a new delegation, but for this specific user + factory(Delegation::class)->create([ + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->id + ]); + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'paul', + 'USR_LASTNAME' => 'Paul', + 'USR_FIRSTNAME' => 'Griffis', + ]); + // Create a new delegation, but for this specific user + factory(Delegation::class)->create([ + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->id + ]); + // Now fetch results, and assume delegation count is 2 and the ordering ascending return Gary + $results = Delegation::search(null, 0, 25, null, null, null, 'ASC', 'APP_CURRENT_USER'); + $this->assertCount(2, $results['data']); + $this->assertEquals('Gary Bailey', $results['data'][0]['APP_CURRENT_USER']); + + // Now fetch results, and assume delegation count is 2 and the ordering descending return Gary + $results = Delegation::search(null, 0, 25, null, null, null, 'DESC', 'APP_CURRENT_USER'); + $this->assertCount(2, $results['data']); + $this->assertEquals('Paul Griffis', $results['data'][0]['APP_CURRENT_USER']); } } \ No newline at end of file From a874ab23906c877c563c90cb805f7caca308f473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Thu, 2 May 2019 12:46:53 -0400 Subject: [PATCH 22/31] First commit for filter by category --- database/factories/ProcessCategoryFactory.php | 14 +++++++++++ .../src/ProcessMaker/Model/DelegationTest.php | 24 +++++++++++++++++++ .../engine/src/ProcessMaker/Model/Process.php | 9 ++++--- .../ProcessMaker/Model/ProcessCategory.php | 17 +++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 database/factories/ProcessCategoryFactory.php create mode 100644 workflow/engine/src/ProcessMaker/Model/ProcessCategory.php diff --git a/database/factories/ProcessCategoryFactory.php b/database/factories/ProcessCategoryFactory.php new file mode 100644 index 000000000..df5dc69d0 --- /dev/null +++ b/database/factories/ProcessCategoryFactory.php @@ -0,0 +1,14 @@ +define(\ProcessMaker\Model\ProcessCategory::class, function (Faker $faker) { + return [ + 'CATEGORY_UID' => G::generateUniqueID(), + 'CATEGORY_PARENT' => '', + 'CATEGORY_NAME' => $faker->paragraph(3), + 'CATEGORY_ICON' => '', + ]; +}); diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 7951c33fd..7c971ea26 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -273,4 +273,28 @@ class DelegationTest extends TestCase $this->assertCount(2, $results['data']); $this->assertEquals('Paul Griffis', $results['data'][0]['APP_CURRENT_USER']); } + + /** + * This checks to make sure filter by category is working properly + * @test + */ + public function it_should_return_categories_of_data() + { + /*factory(User::class,100)->create(); + $process = factory(Process::class, 1)->create([ + 'PRO_ID' => 1 + ]); + factory(Delegation::class, 51)->create([ + 'PRO_ID' => $process[0]->id + ]); + // Get first page, which is 25 + $results = Delegation::search(null, 0, 25, null, $process[0]->id); + $this->assertCount(25, $results['data']); + // Get second page, which is 25 results + $results = Delegation::search(null, 25, 25,null, $process[0]->id); + $this->assertCount(25, $results['data']); + // Get third page, which is only 1 result + $results = Delegation::search(null, 50, 25,null, $process[0]->id); + $this->assertCount(1, $results['data']);*/ + } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/Process.php b/workflow/engine/src/ProcessMaker/Model/Process.php index e136f07a3..52ff107e2 100644 --- a/workflow/engine/src/ProcessMaker/Model/Process.php +++ b/workflow/engine/src/ProcessMaker/Model/Process.php @@ -24,18 +24,21 @@ class Process extends Model public function applications() { return $this->hasMany(Application::class, 'PRO_ID', 'PRO_ID'); - } public function tasks() { return $this->hasMany(Task::class, 'PRO_UID', 'PRO_UID'); - } public function creator() { return $this->hasOne(User::class, 'PRO_CREATE_USER', 'USR_UID'); } -} \ No newline at end of file + + public function category() + { + return $this->hasOne(ProcessCategory::class, 'PRO_CATEGORY', 'CATEGORY_UID'); + } +} diff --git a/workflow/engine/src/ProcessMaker/Model/ProcessCategory.php b/workflow/engine/src/ProcessMaker/Model/ProcessCategory.php new file mode 100644 index 000000000..9d8c69bd4 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/ProcessCategory.php @@ -0,0 +1,17 @@ + Date: Thu, 2 May 2019 13:23:23 -0400 Subject: [PATCH 23/31] conflicts --- .../src/ProcessMaker/Model/DelegationTest.php | 138 ++++++++++++++---- .../src/ProcessMaker/Model/Delegation.php | 4 +- 2 files changed, 115 insertions(+), 27 deletions(-) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 7c971ea26..8e99a843e 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -5,6 +5,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Process; +use ProcessMaker\Model\Task; use ProcessMaker\Model\User; use Tests\TestCase; @@ -67,8 +68,9 @@ class DelegationTest extends TestCase factory(Process::class,1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, - 'APP_STATUS_ID' => 1 - ]);//DRAFT + 'APP_STATUS_ID' => 1, + 'APP_STATUS' => 'DRAFT' + ]); factory(Delegation::class, 51)->create([ 'APP_NUMBER' => $application[0]->APP_NUMBER ]); @@ -95,9 +97,9 @@ class DelegationTest extends TestCase factory(Process::class,1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, - 'APP_STATUS_ID' => 2 - ]);//DRAFT - + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); factory(Delegation::class, 51)->create([ 'APP_NUMBER' => $application[0]->APP_NUMBER ]); @@ -124,13 +126,15 @@ class DelegationTest extends TestCase factory(Process::class,1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, - 'APP_STATUS_ID' => 3 - ]);//DRAFT + 'APP_STATUS_ID' => 3, + 'APP_STATUS' => 'COMPLETED', + ]); factory(Delegation::class, 51)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_LAST_INDEX' => 1 ]); - // Review the filter by status DRAFT + // Review the filter by status COMPLETED // Get first page, which is 25 $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); @@ -153,13 +157,15 @@ class DelegationTest extends TestCase factory(Process::class,1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, - 'APP_STATUS_ID' => 4 - ]);//DRAFT + 'APP_STATUS_ID' => 4, + 'APP_STATUS' => 'CANCELLED' + ]); factory(Delegation::class, 51)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_LAST_INDEX' => 1 ]); - // Review the filter by status DRAFT + // Review the filter by status CANCELLED // Get first page, which is 25 $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); @@ -235,7 +241,41 @@ class DelegationTest extends TestCase } /** - * This ensures ordering ascending and descending works by user + * This ensures ordering ascending works by case title + * @test + */ + public function it_should_sort_by_case_title() + { + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2001, + 'APP_TITLE' => 'Request by Thomas' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 30002, + 'APP_TITLE' => 'Request by Ariel' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Get first page, the minor case id + $results = Delegation::search(null, 0, 25, null, null, null, 'ASC', 'APP_TITLE'); + $this->assertCount(2, $results['data']); + $this->assertEquals('Request by Ariel', $results['data'][0]['APP_TITLE']); + $this->assertEquals('Request by Thomas', $results['data'][1]['APP_TITLE']); + // Get first page, the major case id + $results = Delegation::search(null, 0, 25, null, null, null, 'DESC', 'APP_TITLE'); + $this->assertCount(2, $results['data']); + $this->assertEquals('Request by Thomas', $results['data'][0]['APP_TITLE']); + $this->assertEquals('Request by Ariel', $results['data'][1]['APP_TITLE']); + } + + /** + * This ensures ordering ascending and descending works by current user * @test */ public function it_should_sort_by_user() @@ -280,21 +320,69 @@ class DelegationTest extends TestCase */ public function it_should_return_categories_of_data() { - /*factory(User::class,100)->create(); + + } + + /** + * This checks to make sure filter by process is working properly + * @test + */ + public function it_should_return_data_issue() + { + factory(User::class,100)->create(); + // Create a threads over the process $process = factory(Process::class, 1)->create([ 'PRO_ID' => 1 ]); - factory(Delegation::class, 51)->create([ + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 1, + 'APP_TITLE' => 'Request by Thomas', + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); + // Create a user Gary in a thread + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'gary', + 'USR_LASTNAME' => 'Gary', + 'USR_FIRSTNAME' => 'Bailey', + ]); + // Create a thread with the user Gary + factory(Delegation::class, 1)->create([ + 'PRO_ID' => $process[0]->id, + 'USR_ID' => $user->id, + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + + // Define a dummy task + $task = factory(Task::class, 1)->create([ + 'TAS_ID' => 1, + 'TAS_TYPE' => 'INTERMEDIATE-THROW' + ]); + // Create a thread with the dummy task this does not need a user + factory(Delegation::class, 1)->create([ + 'PRO_ID' => $process[0]->id, + 'USR_ID' => 0, + 'TAS_ID' => $task[0]->id, + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Create a user Paul in a thread + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'Paul', + 'USR_LASTNAME' => 'Griffis', + 'USR_FIRSTNAME' => 'paul', + ]); + // Create a thread with the user Paul + factory(Delegation::class, 1)->create([ + 'PRO_ID' => $process[0]->id, + 'USR_ID' => $user->id, + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Create others delegations + factory(Delegation::class, 24)->create([ 'PRO_ID' => $process[0]->id ]); - // Get first page, which is 25 - $results = Delegation::search(null, 0, 25, null, $process[0]->id); - $this->assertCount(25, $results['data']); - // Get second page, which is 25 results - $results = Delegation::search(null, 25, 25,null, $process[0]->id); - $this->assertCount(25, $results['data']); - // Get third page, which is only 1 result - $results = Delegation::search(null, 50, 25,null, $process[0]->id); - $this->assertCount(1, $results['data']);*/ + // Get first page, which is 25 of 26 + $results = Delegation::search(null, 0, 10, null, $process[0]->id, null, 'ASC', 'APP_NUMBER'); + $this->assertCount(10, $results['data']); } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 304081921..839c7db33 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -285,12 +285,12 @@ class Delegation extends Model // Rewrite priority string if ($item['DEL_PRIORITY']) { - $item['DEL_PRIORITY'] = G::LoadTranslation("ID_PRIORITY_{$priorities[$item['DEL_PRIORITY']]}"); + $item['DEL_PRIORITY'] = G::LoadTranslation("ID_PRIORITY_{$priorities[$item['DEL_PRIORITY']]}", 'en'); } // Merge in desired application data if ($item['APP_STATUS']) { - $item['APP_STATUS_LABEL'] = G::LoadTranslation("ID_${item['APP_STATUS']}"); + $item['APP_STATUS_LABEL'] = G::LoadTranslation("ID_${item['APP_STATUS']}", 'en'); } else { $item['APP_STATUS_LABEL'] = $application->APP_STATUS; } From 5955ff6737a14dac5815ca83f3a95d689a94fe3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Thu, 2 May 2019 14:48:50 -0400 Subject: [PATCH 24/31] conflicts --- database/factories/ProcessCategoryFactory.php | 2 +- .../src/ProcessMaker/Model/DelegationTest.php | 49 +++++++++++++++---- .../ProcessMaker/Model/ProcessCategory.php | 2 + 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/database/factories/ProcessCategoryFactory.php b/database/factories/ProcessCategoryFactory.php index df5dc69d0..0f8f19776 100644 --- a/database/factories/ProcessCategoryFactory.php +++ b/database/factories/ProcessCategoryFactory.php @@ -8,7 +8,7 @@ $factory->define(\ProcessMaker\Model\ProcessCategory::class, function (Faker $fa return [ 'CATEGORY_UID' => G::generateUniqueID(), 'CATEGORY_PARENT' => '', - 'CATEGORY_NAME' => $faker->paragraph(3), + 'CATEGORY_NAME' => $faker->sentence(5), 'CATEGORY_ICON' => '', ]; }); diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 8e99a843e..63c93bad0 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -5,6 +5,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Process; +use ProcessMaker\Model\ProcessCategory; use ProcessMaker\Model\Task; use ProcessMaker\Model\User; use Tests\TestCase; @@ -314,15 +315,6 @@ class DelegationTest extends TestCase $this->assertEquals('Paul Griffis', $results['data'][0]['APP_CURRENT_USER']); } - /** - * This checks to make sure filter by category is working properly - * @test - */ - public function it_should_return_categories_of_data() - { - - } - /** * This checks to make sure filter by process is working properly * @test @@ -385,4 +377,43 @@ class DelegationTest extends TestCase $results = Delegation::search(null, 0, 10, null, $process[0]->id, null, 'ASC', 'APP_NUMBER'); $this->assertCount(10, $results['data']); } + + /** + * This checks to make sure filter by category is working properly + * @test + */ + public function it_should_return_categories_of_data() + { + factory(User::class, 100)->create(); + // Dummy Processes + factory(ProcessCategory::class, 4)->create(); + factory(Process::class, 4)->create([ + 'PRO_CATEGORY' => \ProcessMaker\Model\ProcessCategory::all()->random()->CATEGORY_UID + ]); + // Dummy Delegations + factory(Delegation::class, 100)->create([ + 'PRO_ID' => \ProcessMaker\Model\Process::all()->random()->PRO_ID + ]); + // Process with the category to search + $processCategorySearch = factory(ProcessCategory::class, 1)->create(); + $categoryUid = $processCategorySearch[0]->CATEGORY_UID; + $processSearch = factory(Process::class, 1)->create([ + 'PRO_ID' => 5, + 'PRO_CATEGORY' => $categoryUid + ]); + // Delegations to found + factory(Delegation::class, 51)->create([ + 'PRO_ID' => $processSearch[0]->id + ]); + + // Get first page, which is 25 + $results = Delegation::search(null, 0, 25, null, null, null, null, null, $categoryUid); + $this->assertCount(25, $results['data']); + // Get second page, which is 25 results + $results = Delegation::search(null, 25, 25, null, null, null, null, null, $categoryUid); + $this->assertCount(25, $results['data']); + // Get third page, which is only 1 result + $results = Delegation::search(null, 50, 25, null, null, null, null, null, $categoryUid); + $this->assertCount(1, $results['data']); + } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/ProcessCategory.php b/workflow/engine/src/ProcessMaker/Model/ProcessCategory.php index 9d8c69bd4..8ad9d705e 100644 --- a/workflow/engine/src/ProcessMaker/Model/ProcessCategory.php +++ b/workflow/engine/src/ProcessMaker/Model/ProcessCategory.php @@ -14,4 +14,6 @@ class ProcessCategory extends Model { // Set our table name protected $table = 'PROCESS_CATEGORY'; + + public $timestamps = false; } From 9b2ac65d23239330bd15b0e11f7852aa950f0d37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Thu, 2 May 2019 15:02:20 -0400 Subject: [PATCH 25/31] Change test name to it_should_return_data_filtered_by_process_category --- .../workflow/engine/src/ProcessMaker/Model/DelegationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 63c93bad0..57e077e69 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -382,7 +382,7 @@ class DelegationTest extends TestCase * This checks to make sure filter by category is working properly * @test */ - public function it_should_return_categories_of_data() + public function it_should_return_data_filtered_by_process_category() { factory(User::class, 100)->create(); // Dummy Processes From 8b74343026840850725493ba145087b7e9707f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Thu, 2 May 2019 16:30:07 -0400 Subject: [PATCH 26/31] Add self service delegation for it_should_return_pages_of_data --- .../engine/src/ProcessMaker/Model/DelegationTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 57e077e69..e06b1bd26 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -22,7 +22,10 @@ class DelegationTest extends TestCase { factory(User::class,100)->create(); factory(Process::class,10)->create(); - factory(Delegation::class, 51)->create(); + factory(Delegation::class, 50)->create(); + factory(Delegation::class, 1)->create([ + 'USR_ID' => 0 // A self service delegation + ]); // Get first page, which is 25 $results = Delegation::search(null, 0, 25); $this->assertCount(25, $results['data']); From a2d9c857a8fc645ffa86dbcfe68a22adc1b2862b Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 2 May 2019 16:51:47 -0400 Subject: [PATCH 27/31] filter with unassigned, date from and date to --- .../src/ProcessMaker/Model/DelegationTest.php | 95 +++++++++++++++++-- 1 file changed, 85 insertions(+), 10 deletions(-) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index e06b1bd26..8f62c5231 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -19,6 +19,25 @@ class DelegationTest extends TestCase * @test */ public function it_should_return_pages_of_data() + { + factory(User::class,100)->create(); + factory(Process::class,10)->create(); + factory(Delegation::class, 51)->create(); + // Get first page, which is 25 + $results = Delegation::search(null, 0, 25); + $this->assertCount(25, $results['data']); + // Get second page, which is 25 results + $results = Delegation::search(null, 25, 25); + $this->assertCount(25, $results['data']); + // Get third page, which is only 1 result + $results = Delegation::search(null, 50, 25); + $this->assertCount(1, $results['data']); + } + /** + * This checks to make sure pagination is working properly + * @test + */ + public function it_should_return_pages_of_data_unassigned() { factory(User::class,100)->create(); factory(Process::class,10)->create(); @@ -204,14 +223,6 @@ class DelegationTest extends TestCase $this->assertEquals('testcaseuser', $results['data'][0]['USRCR_USR_USERNAME']); } - /** - * @test - */ - public function it_should_have_data_match_certain_schema() - { - $this->markTestIncomplete(); - } - /** * This ensures ordering ascending works by case number * @test @@ -391,11 +402,11 @@ class DelegationTest extends TestCase // Dummy Processes factory(ProcessCategory::class, 4)->create(); factory(Process::class, 4)->create([ - 'PRO_CATEGORY' => \ProcessMaker\Model\ProcessCategory::all()->random()->CATEGORY_UID + 'PRO_CATEGORY' => ProcessCategory::all()->random()->CATEGORY_UID ]); // Dummy Delegations factory(Delegation::class, 100)->create([ - 'PRO_ID' => \ProcessMaker\Model\Process::all()->random()->PRO_ID + 'PRO_ID' => Process::all()->random()->PRO_ID ]); // Process with the category to search $processCategorySearch = factory(ProcessCategory::class, 1)->create(); @@ -419,4 +430,68 @@ class DelegationTest extends TestCase $results = Delegation::search(null, 50, 25, null, null, null, null, null, $categoryUid); $this->assertCount(1, $results['data']); } + + /** + * This ensure the result is right when you search between two given dates + * @test + */ + public function it_should_return_right_data_between_two_dates() + { + factory(User::class, 10)->create(); + factory(Process::class, 10)->create(); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-02 00:00:00']); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-03 00:00:00']); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-04 00:00:00']); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-05 00:00:00']); + $results = Delegation::search(null, 0, 25, null, null, null, null, null, null, '2019-01-02 00:00:00', + '2019-01-03 00:00:00'); + $this->assertCount(20, $results['data']); + foreach ($results['data'] as $value) { + $this->assertGreaterThanOrEqual('2019-01-02 00:00:00', $value['DEL_DELEGATE_DATE']); + $this->assertLessThanOrEqual('2019-01-03 00:00:00', $value['DEL_DELEGATE_DATE']); + $this->assertRegExp('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ', $value['DEL_DELEGATE_DATE']); + } + } + + /** + * This ensure the result is right when you search from a given date + * @test + */ + public function it_should_return_right_data_when_you_send_only_dateFrom_parameter() + { + factory(User::class, 10)->create(); + factory(Process::class, 10)->create(); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-02 00:00:00']); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-03 00:00:00']); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-04 00:00:00']); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-05 00:00:00']); + $results = Delegation::search(null, 0, 50, null, null, null, null, null, null, '2019-01-02 00:00:00', + null); + $this->assertCount(40, $results['data']); + foreach ($results['data'] as $value) { + $this->assertGreaterThanOrEqual('2019-01-02 00:00:00', $value['DEL_DELEGATE_DATE']); + $this->assertRegExp('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ', $value['DEL_DELEGATE_DATE']); + } + } + + /** + * This ensure the result is right when you search to a given date + * @test + */ + public function it_should_return_right_data_when_you_send_only_dateTo_parameter() + { + factory(User::class, 10)->create(); + factory(Process::class, 10)->create(); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-02 00:00:00']); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-03 00:00:00']); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-04 00:00:00']); + factory(Delegation::class, 10)->create(['DEL_DELEGATE_DATE' => '2019-01-05 00:00:00']); + $results = Delegation::search(null, 0, 50, null, null, null, null, null, null, null, + '2019-01-04 00:00:00'); + $this->assertCount(30, $results['data']); + foreach ($results['data'] as $value) { + $this->assertLessThanOrEqual('2019-01-04 00:00:00', $value['DEL_DELEGATE_DATE']); + $this->assertRegExp('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ', $value['DEL_DELEGATE_DATE']); + } + } } \ No newline at end of file From 3b28019fe54cb83b21cc8c791596455b1437214f Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Thu, 2 May 2019 14:06:55 -0700 Subject: [PATCH 28/31] Add check for invalid USER potentially due to unassigned. In this situation, assign blank values to result. Fixes test to check for unassigned users. --- .../src/ProcessMaker/Model/DelegationTest.php | 1 + .../src/ProcessMaker/Model/Delegation.php | 24 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 8f62c5231..d14433108 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -41,6 +41,7 @@ class DelegationTest extends TestCase { factory(User::class,100)->create(); factory(Process::class,10)->create(); + factory(Delegation::class, 50)->create(); factory(Delegation::class, 1)->create([ 'USR_ID' => 0 // A self service delegation diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 839c7db33..a5a11b08b 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -272,16 +272,13 @@ class Delegation extends Model $results->transform(function ($item, $key) use ($priorities) { // Convert to an array as our results must be an array $item = json_decode(json_encode($item), true); - $user = User::where('USR_ID', $item['USR_ID'])->first(); - if (!$user) { - // User not found, return null - return null; - } - $process = Process::where('PRO_ID', $item['PRO_ID'])->first();; - if (!$process) { - // Process not found, return null - return null; + // If it's assigned, fetch the user + if($item['USR_ID']) { + $user = User::where('USR_ID', $item['USR_ID'])->first(); + } else { + $user = null; } + $process = Process::where('PRO_ID', $item['PRO_ID'])->first(); // Rewrite priority string if ($item['DEL_PRIORITY']) { @@ -296,12 +293,13 @@ class Delegation extends Model } // Merge in desired process data - $item['APP_PRO_TITLE'] = $process->PRO_TITLE; + // Handle situation where the process might not be in the system anymore + $item['APP_PRO_TITLE'] = $process ? $process->PRO_TITLE : ''; // Merge in desired user data - $item['USR_LASTNAME'] = $user->USR_LASTNAME; - $item['USR_FIRSTNAME'] = $user->USR_FIRSTNAME; - $item['USR_USERNAME'] = $user->USR_USERNAME; + $item['USR_LASTNAME'] = $user ? $user->USR_LASTNAME : ''; + $item['USR_FIRSTNAME'] = $user ? $user->USR_FIRSTNAME : ''; + $item['USR_USERNAME'] = $user ? $user->USR_USERNAME : ''; //@todo: this section needs to use 'User Name Display Format', currently in the extJs is defined this $item["APP_CURRENT_USER"] = $item["USR_LASTNAME"] . ' ' . $item["USR_FIRSTNAME"]; From c983a67a87c665f3c4ca49c6ecdd59ddb3c1e5dc Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 2 May 2019 17:12:35 -0400 Subject: [PATCH 29/31] Filter by case number --- .../src/ProcessMaker/Model/DelegationTest.php | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index d14433108..9c570ec0f 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -224,6 +224,148 @@ class DelegationTest extends TestCase $this->assertEquals('testcaseuser', $results['data'][0]['USRCR_USR_USERNAME']); } + /** + * This ensures searching by case number and review the page + * @test + */ + public function it_should_search_by_case_id_and_pages_of_data() + { + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2001 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2010 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2011 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2012 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2013 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2014 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2015 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Get first page, the major case id + $results = Delegation::search(null, 0, 10, 1, null, null, 'DESC', + 'APP_NUMBER', null, null, null,'APP_NUMBER'); + $this->assertCount(7, $results['data']); + $this->assertEquals(2015, $results['data'][0]['APP_NUMBER']); + // Get first page, the minor case id + $results = Delegation::search(null, 0, 10, 1, null, null, 'ASC', + 'APP_NUMBER', null, null, null, 'APP_NUMBER'); + $this->assertCount(7, $results['data']); + $this->assertEquals(2001, $results['data'][0]['APP_NUMBER']); + //Check the pagination + $results = Delegation::search(null, 0, 5, 1, null, null, 'DESC', + 'APP_NUMBER', null, null, null, 'APP_NUMBER'); + $this->assertCount(5, $results['data']); + $results = Delegation::search(null, 5, 2, 1, null, null, 'DESC', + 'APP_NUMBER', null, null, null, 'APP_NUMBER'); + $this->assertCount(2, $results['data']); + } + + /** + * This ensures searching by case title and review the page + * case title contain the case number, ex: APP_TITLE = 'Request # @=APP_NUMBER' + * @test + */ + public function it_should_search_by_case_title_and_pages_of_data_app_number_matches_case_title() + { + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 3001, + 'APP_TITLE' => 'Request # 3001' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 3010, + 'APP_TITLE' => 'Request # 3010' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 3011, + 'APP_TITLE' => 'Request # 3011' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 3012, + 'APP_TITLE' => 'Request # 3012' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 3013, + 'APP_TITLE' => 'Request # 3013' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_TITLE' => 3014, + 'APP_TITLE' => 'Request # 3014' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + + // Get first page, the major case id + $results = Delegation::search(null, 0, 10, '1', null, null, 'DESC', + 'APP_NUMBER', null, null, null, 'APP_TITLE'); + $this->assertCount(6, $results['data']); + $this->assertEquals('Request # 3014', $results['data'][0]['APP_TITLE']); + + // Get first page, the minor case id + $results = Delegation::search(null, 0, 10, '1', null, null, 'ASC', + 'APP_NUMBER', null, null, null,'APP_TITLE'); + $this->assertCount(6, $results['data']); + $this->assertEquals(3001, $results['data'][0]['APP_NUMBER']); + $this->assertEquals('Request # 3001', $results['data'][0]['APP_TITLE']); + //Check the pagination + $results = Delegation::search(null, 0, 5, '1', null, null, 'ASC', + 'APP_NUMBER', null, null, null,'APP_TITLE'); + $this->assertCount(5, $results['data']); + $results = Delegation::search(null, 5, 2, '1', null, null, 'ASC', + 'APP_NUMBER', null, null, null,'APP_TITLE'); + $this->assertCount(1, $results['data']); + } + /** * This ensures ordering ascending works by case number * @test From 9f844097dad23238852fb0a81feb1bd96a3d8672 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 2 May 2019 17:19:10 -0400 Subject: [PATCH 30/31] Adding user case Hertland --- .../src/ProcessMaker/Model/DelegationTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 9c570ec0f..1ad1f55a7 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -366,6 +366,73 @@ class DelegationTest extends TestCase $this->assertCount(1, $results['data']); } + /** + * This ensures searching by case title and review the page + * case title does not match with case number (hertland use case) + * @test + */ + public function it_should_search_by_case_title_and_pages_of_data_app_number_no_matches_case_title() + { + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2001, + 'APP_TITLE' => 'Request from Abigail check nro 25001' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2010, + 'APP_TITLE' => 'Request from Abigail check nro 12' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2011, + 'APP_TITLE' => 'Request from Abigail check nro 1000' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2012, + 'APP_TITLE' => 'Request from Abigail check nro 11000' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2013, + 'APP_TITLE' => 'Request from Abigail check nro 12000' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_TITLE' => 2014, + 'APP_TITLE' => 'Request from Abigail check nro 111' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Get first page, the major case title + $results = Delegation::search(null, 0, 10, '1', null, null, 'ASC', + 'APP_NUMBER', null, null, null, 'APP_TITLE'); + $this->assertCount(6, $results['data']); + $this->assertEquals(2001, $results['data'][0]['APP_NUMBER']); + $this->assertEquals('Request from Abigail check nro 25001', $results['data'][0]['APP_TITLE']); + + //Check the pagination + $results = Delegation::search(null, 0, 5, '1', null, null, 'ASC', + 'APP_NUMBER', null, null, null,'APP_TITLE'); + $this->assertCount(5, $results['data']); + $results = Delegation::search(null, 5, 2, '1', null, null, 'ASC', + 'APP_NUMBER', null, null, null,'APP_TITLE'); + $this->assertCount(1, $results['data']); + } + /** * This ensures ordering ascending works by case number * @test From 7f3b8b1e40ca78fa5a67e665f88c93799cac292a Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Fri, 3 May 2019 08:03:56 -0400 Subject: [PATCH 31/31] filter by task title and order by lastModified, dueDate, status, process and task --- config/app.php | 2 - database/factories/ApplicationFactory.php | 1 - database/factories/DelegationFactory.php | 1 - database/factories/ProcessFactory.php | 1 - database/factories/RouteFactory.php | 1 - database/factories/TaskFactory.php | 1 - database/factories/TaskUserFactory.php | 1 - database/factories/UserFactory.php | 1 - .../src/ProcessMaker/Model/DelegationTest.php | 510 ++++++++++++++---- .../engine/methods/cases/proxyCasesList.php | 2 +- .../src/ProcessMaker/Model/Application.php | 1 - .../engine/src/ProcessMaker/Model/Process.php | 2 - .../engine/src/ProcessMaker/Model/User.php | 1 - 13 files changed, 418 insertions(+), 107 deletions(-) diff --git a/config/app.php b/config/app.php index 035380c52..651ebfc6a 100644 --- a/config/app.php +++ b/config/app.php @@ -21,9 +21,7 @@ return [ Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, Illuminate\Queue\QueueServiceProvider::class, Illuminate\Translation\TranslationServiceProvider::class, - Laravel\Tinker\TinkerServiceProvider::class, - ], 'aliases' => [ diff --git a/database/factories/ApplicationFactory.php b/database/factories/ApplicationFactory.php index e497e9c38..76728224a 100644 --- a/database/factories/ApplicationFactory.php +++ b/database/factories/ApplicationFactory.php @@ -3,7 +3,6 @@ use Faker\Generator as Faker; use ProcessMaker\BusinessModel\Cases as BmCases; $factory->define(\ProcessMaker\Model\Application::class, function(Faker $faker) { - $process = \ProcessMaker\Model\Process::all()->random(); $statuses = ['DRAFT', 'TO_DO']; $status = $faker->randomElement($statuses); diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php index 4b7c6e947..e5917a414 100644 --- a/database/factories/DelegationFactory.php +++ b/database/factories/DelegationFactory.php @@ -3,7 +3,6 @@ use Faker\Generator as Faker; use ProcessMaker\BusinessModel\Cases as BmCases; $factory->define(\ProcessMaker\Model\Delegation::class, function(Faker $faker) { - $app = factory(\ProcessMaker\Model\Application::class)->create(); $process = \ProcessMaker\Model\Process::where('PRO_UID', $app->PRO_UID)->first(); $task = $process->tasks->first(); diff --git a/database/factories/ProcessFactory.php b/database/factories/ProcessFactory.php index 2ddbe0d0f..40ae93dc3 100644 --- a/database/factories/ProcessFactory.php +++ b/database/factories/ProcessFactory.php @@ -5,7 +5,6 @@ use Faker\Generator as Faker; $factory->define(\ProcessMaker\Model\Process::class, function(Faker $faker) { - /** * @todo Determine if we need more base columns populated */ diff --git a/database/factories/RouteFactory.php b/database/factories/RouteFactory.php index 7e649a31f..18a3e2f57 100644 --- a/database/factories/RouteFactory.php +++ b/database/factories/RouteFactory.php @@ -5,7 +5,6 @@ use Faker\Generator as Faker; $factory->define(\ProcessMaker\Model\Route::class, function(Faker $faker) { - return [ 'PRO_UID' => function() { $process = factory(\ProcessMaker\Model\Process::class)->create(); diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php index ea6548bde..41f1167a9 100644 --- a/database/factories/TaskFactory.php +++ b/database/factories/TaskFactory.php @@ -5,7 +5,6 @@ use Faker\Generator as Faker; $factory->define(\ProcessMaker\Model\Task::class, function(Faker $faker) { - return [ 'PRO_UID' => function() { $process = factory(\ProcessMaker\Model\Process::class)->create(); diff --git a/database/factories/TaskUserFactory.php b/database/factories/TaskUserFactory.php index 751c491f7..a4c0a5e7d 100644 --- a/database/factories/TaskUserFactory.php +++ b/database/factories/TaskUserFactory.php @@ -5,7 +5,6 @@ use Faker\Generator as Faker; $factory->define(\ProcessMaker\Model\TaskUser::class, function(Faker $faker) { - return [ 'TAS_UID' => function() { $task = factory(\ProcessMaker\Model\Task::class)->create(); diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 0eff02f51..1885c421e 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -2,7 +2,6 @@ use Faker\Generator as Faker; $factory->define(\ProcessMaker\Model\User::class, function(Faker $faker) { - return [ 'USR_UID' => G::generateUniqueID(), 'USR_USERNAME' => $faker->unique()->userName, diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 1ad1f55a7..a584902b4 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -20,8 +20,8 @@ class DelegationTest extends TestCase */ public function it_should_return_pages_of_data() { - factory(User::class,100)->create(); - factory(Process::class,10)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 10)->create(); factory(Delegation::class, 51)->create(); // Get first page, which is 25 $results = Delegation::search(null, 0, 25); @@ -33,14 +33,15 @@ class DelegationTest extends TestCase $results = Delegation::search(null, 50, 25); $this->assertCount(1, $results['data']); } + /** * This checks to make sure pagination is working properly * @test */ public function it_should_return_pages_of_data_unassigned() { - factory(User::class,100)->create(); - factory(Process::class,10)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 10)->create(); factory(Delegation::class, 50)->create(); factory(Delegation::class, 1)->create([ @@ -63,7 +64,7 @@ class DelegationTest extends TestCase */ public function it_should_return_process_of_data() { - factory(User::class,100)->create(); + factory(User::class, 100)->create(); $process = factory(Process::class, 1)->create([ 'PRO_ID' => 1 ]); @@ -74,10 +75,10 @@ class DelegationTest extends TestCase $results = Delegation::search(null, 0, 25, null, $process[0]->id); $this->assertCount(25, $results['data']); // Get second page, which is 25 results - $results = Delegation::search(null, 25, 25,null, $process[0]->id); + $results = Delegation::search(null, 25, 25, null, $process[0]->id); $this->assertCount(25, $results['data']); // Get third page, which is only 1 result - $results = Delegation::search(null, 50, 25,null, $process[0]->id); + $results = Delegation::search(null, 50, 25, null, $process[0]->id); $this->assertCount(1, $results['data']); } @@ -88,8 +89,8 @@ class DelegationTest extends TestCase */ public function it_should_return_status_draft_of_data() { - factory(User::class,100)->create(); - factory(Process::class,1)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, 'APP_STATUS_ID' => 1, @@ -103,10 +104,10 @@ class DelegationTest extends TestCase $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); // Get second page, which is 25 results - $results = Delegation::search(null, 25, 25,null, null, $application[0]->APP_STATUS_ID); + $results = Delegation::search(null, 25, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); // Get third page, which is only 1 result - $results = Delegation::search(null, 50, 25,null, null, $application[0]->APP_STATUS_ID); + $results = Delegation::search(null, 50, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(1, $results['data']); } @@ -117,8 +118,8 @@ class DelegationTest extends TestCase */ public function it_should_return_status_todo_of_data() { - factory(User::class,100)->create(); - factory(Process::class,1)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, 'APP_STATUS_ID' => 2, @@ -132,10 +133,10 @@ class DelegationTest extends TestCase $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); // Get second page, which is 25 results - $results = Delegation::search(null, 25, 25,null, null, $application[0]->APP_STATUS_ID); + $results = Delegation::search(null, 25, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); // Get third page, which is only 1 result - $results = Delegation::search(null, 50, 25,null, null, $application[0]->APP_STATUS_ID); + $results = Delegation::search(null, 50, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(1, $results['data']); } @@ -146,8 +147,8 @@ class DelegationTest extends TestCase */ public function it_should_return_status_completed_of_data() { - factory(User::class,100)->create(); - factory(Process::class,1)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, 'APP_STATUS_ID' => 3, @@ -163,10 +164,10 @@ class DelegationTest extends TestCase $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); // Get second page, which is 25 results - $results = Delegation::search(null, 25, 25,null, null, $application[0]->APP_STATUS_ID); + $results = Delegation::search(null, 25, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); // Get third page, which is only 1 result - $results = Delegation::search(null, 50, 25,null, null, $application[0]->APP_STATUS_ID); + $results = Delegation::search(null, 50, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(1, $results['data']); } @@ -177,8 +178,8 @@ class DelegationTest extends TestCase */ public function it_should_return_status_cancelled_of_data() { - factory(User::class,100)->create(); - factory(Process::class,1)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, 'APP_STATUS_ID' => 4, @@ -194,10 +195,10 @@ class DelegationTest extends TestCase $results = Delegation::search(null, 0, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); // Get second page, which is 25 results - $results = Delegation::search(null, 25, 25,null, null, $application[0]->APP_STATUS_ID); + $results = Delegation::search(null, 25, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(25, $results['data']); // Get third page, which is only 1 result - $results = Delegation::search(null, 50, 25,null, null, $application[0]->APP_STATUS_ID); + $results = Delegation::search(null, 50, 25, null, null, $application[0]->APP_STATUS_ID); $this->assertCount(1, $results['data']); } @@ -207,8 +208,8 @@ class DelegationTest extends TestCase */ public function it_should_return_one_result_for_specified_user() { - factory(User::class,100)->create(); - factory(Process::class,10)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 10)->create(); // Create our unique user, with a unique username $user = factory(User::class)->create([ 'USR_USERNAME' => 'testcaseuser' @@ -230,8 +231,8 @@ class DelegationTest extends TestCase */ public function it_should_search_by_case_id_and_pages_of_data() { - factory(User::class,100)->create(); - factory(Process::class,1)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001 ]); @@ -276,7 +277,7 @@ class DelegationTest extends TestCase ]); // Get first page, the major case id $results = Delegation::search(null, 0, 10, 1, null, null, 'DESC', - 'APP_NUMBER', null, null, null,'APP_NUMBER'); + 'APP_NUMBER', null, null, null, 'APP_NUMBER'); $this->assertCount(7, $results['data']); $this->assertEquals(2015, $results['data'][0]['APP_NUMBER']); // Get first page, the minor case id @@ -300,8 +301,8 @@ class DelegationTest extends TestCase */ public function it_should_search_by_case_title_and_pages_of_data_app_number_matches_case_title() { - factory(User::class,100)->create(); - factory(Process::class,1)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 3001, 'APP_TITLE' => 'Request # 3001' @@ -353,19 +354,67 @@ class DelegationTest extends TestCase // Get first page, the minor case id $results = Delegation::search(null, 0, 10, '1', null, null, 'ASC', - 'APP_NUMBER', null, null, null,'APP_TITLE'); + 'APP_NUMBER', null, null, null, 'APP_TITLE'); $this->assertCount(6, $results['data']); $this->assertEquals(3001, $results['data'][0]['APP_NUMBER']); $this->assertEquals('Request # 3001', $results['data'][0]['APP_TITLE']); //Check the pagination $results = Delegation::search(null, 0, 5, '1', null, null, 'ASC', - 'APP_NUMBER', null, null, null,'APP_TITLE'); + 'APP_NUMBER', null, null, null, 'APP_TITLE'); $this->assertCount(5, $results['data']); $results = Delegation::search(null, 5, 2, '1', null, null, 'ASC', - 'APP_NUMBER', null, null, null,'APP_TITLE'); + 'APP_NUMBER', null, null, null, 'APP_TITLE'); $this->assertCount(1, $results['data']); } + /** + * This ensures searching by task title and review the page + * @test + */ + public function it_should_search_by_task_title_and_pages_of_data() + { + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); + $task = factory(Task::class, 1)->create([ + 'TAS_ID' => 1, + 'TAS_TITLE' => 'Request task' + ]); + factory(Delegation::class, 5)->create([ + 'TAS_ID' => $task[0]->TAS_ID + ]); + $task = factory(Task::class, 1)->create([ + 'TAS_ID' => 2, + 'TAS_TITLE' => 'Account task' + ]); + factory(Delegation::class, 5)->create([ + 'TAS_ID' => $task[0]->TAS_ID + ]); + // Get first page, the order taskTitle + $results = Delegation::search(null, 0, 6, 'task', null, null, 'ASC', + 'TAS_TITLE', null, null, null, 'TAS_TITLE'); + $this->assertCount(6, $results['data']); + $this->assertEquals('Account task', $results['data'][0]['APP_TAS_TITLE']); + $results = Delegation::search(null, 6, 6, 'task', null, null, 'ASC', + 'TAS_TITLE', null, null, null, 'TAS_TITLE'); + $this->assertEquals('Request task', $results['data'][0]['APP_TAS_TITLE']); + + // Get first page, the order taskTitle + $results = Delegation::search(null, 0, 6, 'task', null, null, 'DESC', + 'TAS_TITLE', null, null, null, 'TAS_TITLE'); + $this->assertCount(6, $results['data']); + $this->assertEquals('Request task', $results['data'][0]['APP_TAS_TITLE']); + $results = Delegation::search(null, 6, 6, 'task', null, null, 'DESC', + 'TAS_TITLE', null, null, null, 'TAS_TITLE'); + $this->assertEquals('Account task', $results['data'][0]['APP_TAS_TITLE']); + //Check the pagination + $results = Delegation::search(null, 0, 6, 'task', null, null, 'DESC', + 'TAS_TITLE', null, null, null, 'TAS_TITLE'); + $this->assertCount(6, $results['data']); + $results = Delegation::search(null, 6, 6, 'task', null, null, 'DESC', + 'TAS_TITLE', null, null, null, 'TAS_TITLE'); + $this->assertCount(4, $results['data']); + } + /** * This ensures searching by case title and review the page * case title does not match with case number (hertland use case) @@ -373,8 +422,8 @@ class DelegationTest extends TestCase */ public function it_should_search_by_case_title_and_pages_of_data_app_number_no_matches_case_title() { - factory(User::class,100)->create(); - factory(Process::class,1)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, 'APP_TITLE' => 'Request from Abigail check nro 25001' @@ -426,21 +475,21 @@ class DelegationTest extends TestCase //Check the pagination $results = Delegation::search(null, 0, 5, '1', null, null, 'ASC', - 'APP_NUMBER', null, null, null,'APP_TITLE'); + 'APP_NUMBER', null, null, null, 'APP_TITLE'); $this->assertCount(5, $results['data']); $results = Delegation::search(null, 5, 2, '1', null, null, 'ASC', - 'APP_NUMBER', null, null, null,'APP_TITLE'); + 'APP_NUMBER', null, null, null, 'APP_TITLE'); $this->assertCount(1, $results['data']); } /** - * This ensures ordering ascending works by case number + * This ensures ordering ascending and descending works by case number APP_NUMBER * @test */ public function it_should_sort_by_case_id() { - factory(User::class,100)->create(); - factory(Process::class,1)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001 ]); @@ -466,13 +515,13 @@ class DelegationTest extends TestCase } /** - * This ensures ordering ascending works by case title + * This ensures ordering ascending and descending works by case title APP_TITLE * @test */ public function it_should_sort_by_case_title() { - factory(User::class,100)->create(); - factory(Process::class,1)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); $application = factory(Application::class, 1)->create([ 'APP_NUMBER' => 2001, 'APP_TITLE' => 'Request by Thomas' @@ -499,14 +548,92 @@ class DelegationTest extends TestCase $this->assertEquals('Request by Ariel', $results['data'][1]['APP_TITLE']); } + /** + * This ensures ordering ascending and descending works by case title APP_PRO_TITLE + * @test + */ + public function it_should_sort_by_process() + { + factory(User::class, 100)->create(); + $process = factory(Process::class, 1)->create([ + 'PRO_ID' => 2, + 'PRO_TITLE' => 'Egypt Supplier Payment Proposal' + ]); + factory(Delegation::class, 1)->create([ + 'PRO_ID' => $process[0]->id + ]); + $process = factory(Process::class, 1)->create([ + 'PRO_ID' => 1, + 'PRO_TITLE' => 'China Supplier Payment Proposal' + ]); + factory(Delegation::class, 1)->create([ + 'PRO_ID' => $process[0]->id + ]); + $process = factory(Process::class, 1)->create([ + 'PRO_ID' => 3, + 'PRO_TITLE' => 'Russia Supplier Payment Proposal' + ]); + factory(Delegation::class, 1)->create([ + 'PRO_ID' => $process[0]->id + ]); + // Get first page, all process ordering ascending + $results = Delegation::search(null, 0, 3, null, null, null, 'ASC', 'APP_PRO_TITLE'); + $this->assertCount(3, $results['data']); + $this->assertEquals('China Supplier Payment Proposal', $results['data'][0]['APP_PRO_TITLE']); + $this->assertEquals('Egypt Supplier Payment Proposal', $results['data'][1]['APP_PRO_TITLE']); + $this->assertEquals('Russia Supplier Payment Proposal', $results['data'][2]['APP_PRO_TITLE']); + // Get first page, all process ordering descending + $results = Delegation::search(null, 0, 3, null, null, null, 'DESC', 'APP_PRO_TITLE'); + $this->assertCount(3, $results['data']); + $this->assertEquals('Russia Supplier Payment Proposal', $results['data'][0]['APP_PRO_TITLE']); + $this->assertEquals('Egypt Supplier Payment Proposal', $results['data'][1]['APP_PRO_TITLE']); + $this->assertEquals('China Supplier Payment Proposal', $results['data'][2]['APP_PRO_TITLE']); + } + + /** + * This ensures ordering ascending and descending works by task title APP_TAS_TITLE + * @test + */ + public function it_should_sort_by_task_title() + { + factory(User::class, 100)->create(); + factory(Process::class, 1)->create(); + + $task = factory(Task::class, 1)->create([ + 'TAS_ID' => 1000, + 'TAS_TITLE' => 'Initiate Request' + ]); + factory(Delegation::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID + ]); + + $task = factory(Task::class, 1)->create([ + 'TAS_ID' => 4000, + 'TAS_TITLE' => 'Waiting for AP Manager Validation' + ]); + factory(Delegation::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID + ]); + + $results = Delegation::search(null, 0, 25, null, null, null, 'ASC', 'APP_TAS_TITLE'); + $this->assertCount(2, $results['data']); + $this->assertEquals('Initiate Request', $results['data'][0]['APP_TAS_TITLE']); + $this->assertEquals('Waiting for AP Manager Validation', $results['data'][1]['APP_TAS_TITLE']); + + $results = Delegation::search(null, 0, 25, null, null, null, 'DESC', 'APP_TAS_TITLE'); + $this->assertCount(2, $results['data']); + $this->assertEquals('Waiting for AP Manager Validation', $results['data'][0]['APP_TAS_TITLE']); + $this->assertEquals('Initiate Request', $results['data'][1]['APP_TAS_TITLE']); + } + /** * This ensures ordering ascending and descending works by current user * @test */ public function it_should_sort_by_user() { - factory(User::class,100)->create(); - factory(Process::class,10)->create(); + factory(User::class, 100)->create(); + factory(Process::class, 10)->create(); // Create our unique user, with a unique username $user = factory(User::class)->create([ 'USR_USERNAME' => 'gary', @@ -540,66 +667,151 @@ class DelegationTest extends TestCase } /** - * This checks to make sure filter by process is working properly + * This ensures ordering ordering ascending and descending works by last modified APP_UPDATE_DATE * @test */ - public function it_should_return_data_issue() + public function it_should_sort_by_last_modified() { factory(User::class,100)->create(); - // Create a threads over the process - $process = factory(Process::class, 1)->create([ - 'PRO_ID' => 1 + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_UPDATE_DATE' => '2019-01-02 00:00:00' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_UPDATE_DATE' => '2019-01-03 00:00:00' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_UPDATE_DATE' => '2019-01-04 00:00:00' + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Get first page, the minor last modified + $results = Delegation::search(null, 0, 1, null, null, null, 'ASC', 'APP_UPDATE_DATE'); + $this->assertCount(1, $results['data']); + $this->assertEquals('2019-01-02 00:00:00', $results['data'][0]['APP_UPDATE_DATE']); + + $results = Delegation::search(null, 1, 1, null, null, null, 'ASC', 'APP_UPDATE_DATE'); + $this->assertCount(1, $results['data']); + $this->assertEquals('2019-01-03 00:00:00', $results['data'][0]['APP_UPDATE_DATE']); + + $results = Delegation::search(null, 2, 1, null, null, null, 'ASC', 'APP_UPDATE_DATE'); + $this->assertCount(1, $results['data']); + $this->assertEquals('2019-01-04 00:00:00', $results['data'][0]['APP_UPDATE_DATE']); + + $results = Delegation::search(null, 0, 1, null, null, null, 'DESC', 'APP_UPDATE_DATE'); + $this->assertCount(1, $results['data']); + $this->assertEquals('2019-01-04 00:00:00', $results['data'][0]['APP_UPDATE_DATE']); + + $results = Delegation::search(null, 1, 1, null, null, null, 'DESC', 'APP_UPDATE_DATE'); + $this->assertCount(1, $results['data']); + $this->assertEquals('2019-01-03 00:00:00', $results['data'][0]['APP_UPDATE_DATE']); + + $results = Delegation::search(null, 2, 1, null, null, null, 'DESC', 'APP_UPDATE_DATE'); + $this->assertCount(1, $results['data']); + $this->assertEquals('2019-01-02 00:00:00', $results['data'][0]['APP_UPDATE_DATE']); + } + + /** + * This ensures ordering ascending and descending works by due date DEL_TASK_DUE_DATE + * @test + */ + public function it_should_sort_by_due_date() + { + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + factory(Delegation::class, 10)->create([ + 'DEL_TASK_DUE_DATE' => '2019-01-02 00:00:00' + ]); + factory(Delegation::class, 10)->create([ + 'DEL_TASK_DUE_DATE' => '2019-01-03 00:00:00' + ]); + factory(Delegation::class, 9)->create([ + 'DEL_TASK_DUE_DATE' => '2019-01-04 00:00:00' + ]); + // Get first page, the minor last modified + $results = Delegation::search(null, 0, 10, null, null, null, 'ASC', 'DEL_TASK_DUE_DATE'); + $this->assertCount(10, $results['data']); + $this->assertEquals('2019-01-02 00:00:00', $results['data'][0]['DEL_TASK_DUE_DATE']); + + $results = Delegation::search(null, 10, 10, null, null, null, 'ASC', 'DEL_TASK_DUE_DATE'); + $this->assertCount(10, $results['data']); + $this->assertEquals('2019-01-03 00:00:00', $results['data'][0]['DEL_TASK_DUE_DATE']); + + $results = Delegation::search(null, 20, 10, null, null, null, 'ASC', 'DEL_TASK_DUE_DATE'); + $this->assertCount(9, $results['data']); + $this->assertEquals('2019-01-04 00:00:00', $results['data'][0]['DEL_TASK_DUE_DATE']); + + $results = Delegation::search(null, 0, 10, null, null, null, 'DESC', 'DEL_TASK_DUE_DATE'); + $this->assertCount(10, $results['data']); + $this->assertEquals('2019-01-04 00:00:00', $results['data'][0]['DEL_TASK_DUE_DATE']); + + $results = Delegation::search(null, 10, 10, null, null, null, 'DESC', 'DEL_TASK_DUE_DATE'); + $this->assertCount(10, $results['data']); + $this->assertEquals('2019-01-03 00:00:00', $results['data'][0]['DEL_TASK_DUE_DATE']); + + $results = Delegation::search(null, 20, 10, null, null, null, 'DESC', 'DEL_TASK_DUE_DATE'); + $this->assertCount(9, $results['data']); + $this->assertEquals('2019-01-02 00:00:00', $results['data'][0]['DEL_TASK_DUE_DATE']); + } + + /** + * This ensures ordering ascending and descending works by status APP_STATUS + * @test + */ + public function it_should_sort_by_status() + { + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $application = factory(Application::class, 1)->create([ + 'APP_STATUS' => 'DRAFT' + ]); + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER ]); $application = factory(Application::class, 1)->create([ - 'APP_NUMBER' => 1, - 'APP_TITLE' => 'Request by Thomas', - 'APP_STATUS_ID' => 2, 'APP_STATUS' => 'TO_DO' ]); - // Create a user Gary in a thread - $user = factory(User::class)->create([ - 'USR_USERNAME' => 'gary', - 'USR_LASTNAME' => 'Gary', - 'USR_FIRSTNAME' => 'Bailey', + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER ]); - // Create a thread with the user Gary - factory(Delegation::class, 1)->create([ - 'PRO_ID' => $process[0]->id, - 'USR_ID' => $user->id, + $application = factory(Application::class, 1)->create([ + 'APP_STATUS' => 'COMPLETED' + ]); + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + $application = factory(Application::class, 1)->create([ + 'APP_STATUS' => 'CANCELLED' + ]); + factory(Delegation::class, 25)->create([ 'APP_NUMBER' => $application[0]->APP_NUMBER ]); - // Define a dummy task - $task = factory(Task::class, 1)->create([ - 'TAS_ID' => 1, - 'TAS_TYPE' => 'INTERMEDIATE-THROW' - ]); - // Create a thread with the dummy task this does not need a user - factory(Delegation::class, 1)->create([ - 'PRO_ID' => $process[0]->id, - 'USR_ID' => 0, - 'TAS_ID' => $task[0]->id, - 'APP_NUMBER' => $application[0]->APP_NUMBER - ]); - // Create a user Paul in a thread - $user = factory(User::class)->create([ - 'USR_USERNAME' => 'Paul', - 'USR_LASTNAME' => 'Griffis', - 'USR_FIRSTNAME' => 'paul', - ]); - // Create a thread with the user Paul - factory(Delegation::class, 1)->create([ - 'PRO_ID' => $process[0]->id, - 'USR_ID' => $user->id, - 'APP_NUMBER' => $application[0]->APP_NUMBER - ]); - // Create others delegations - factory(Delegation::class, 24)->create([ - 'PRO_ID' => $process[0]->id - ]); - // Get first page, which is 25 of 26 - $results = Delegation::search(null, 0, 10, null, $process[0]->id, null, 'ASC', 'APP_NUMBER'); - $this->assertCount(10, $results['data']); + // Get first page, the minor status label + $results = Delegation::search(null, 0, 25, null, null, null, 'ASC', 'APP_STATUS'); + $this->assertEquals('CANCELLED', $results['data'][0]['APP_STATUS']); + $results = Delegation::search(null, 25, 25, null, null, null, 'ASC', 'APP_STATUS'); + $this->assertEquals('COMPLETED', $results['data'][0]['APP_STATUS']); + $results = Delegation::search(null, 50, 25, null, null, null, 'ASC', 'APP_STATUS'); + $this->assertEquals('DRAFT', $results['data'][0]['APP_STATUS']); + $results = Delegation::search(null, 75, 25, null, null, null, 'ASC', 'APP_STATUS'); + $this->assertEquals('TO_DO', $results['data'][0]['APP_STATUS']); + // Get first page, the major status label + $results = Delegation::search(null, 0, 25, null, null, null, 'DESC', 'APP_STATUS'); + $this->assertEquals('TO_DO', $results['data'][0]['APP_STATUS']); + $results = Delegation::search(null, 25, 25, null, null, null, 'DESC', 'APP_STATUS'); + $this->assertEquals('DRAFT', $results['data'][0]['APP_STATUS']); + $results = Delegation::search(null, 50, 25, null, null, null, 'DESC', 'APP_STATUS'); + $this->assertEquals('COMPLETED', $results['data'][0]['APP_STATUS']); + $results = Delegation::search(null, 75, 25, null, null, null, 'DESC', 'APP_STATUS'); + $this->assertEquals('CANCELLED', $results['data'][0]['APP_STATUS']); } /** @@ -704,4 +916,116 @@ class DelegationTest extends TestCase $this->assertRegExp('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ', $value['DEL_DELEGATE_DATE']); } } + + /** + * This ensures return the correct data by sequential + * @test + */ + public function it_should_return_by_sequential_tasks_pages_of_data() + { + factory(User::class, 100)->create(); + // Create a threads over the process + $process = factory(Process::class, 1)->create([ + 'PRO_ID' => 1 + ]); + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 1, + 'APP_TITLE' => 'Request by Thomas', + ]); + // Create a user Gary in a thread + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'gary', + 'USR_LASTNAME' => 'Bailey', + 'USR_FIRSTNAME' => 'Gary', + ]); + // Create a thread with the user Gary + factory(Delegation::class, 1)->create([ + 'PRO_ID' => $process[0]->id, + 'USR_ID' => $user->id, + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_THREAD_STATUS' => 'CLOSED' + ]); + + // Define a dummy task + $task = factory(Task::class, 1)->create([ + 'TAS_TYPE' => 'INTERMEDIATE-THROW' + ]); + // Create a thread with the dummy task this does not need a user + factory(Delegation::class, 1)->create([ + 'PRO_ID' => $process[0]->id, + 'USR_ID' => 0, + 'TAS_ID' => $task[0]->id, + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + // Create a user Paul in a thread + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'paul', + 'USR_LASTNAME' => 'Griffis', + 'USR_FIRSTNAME' => 'Paul', + ]); + // Create a thread with the user Paul + factory(Delegation::class, 1)->create([ + 'PRO_ID' => $process[0]->id, + 'USR_ID' => $user->id, + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_THREAD_STATUS' => 'OPEN' + ]); + // Get first page, which is 25 of 26 + $results = Delegation::search(null, 0, 10, null, $process[0]->id, null, 'ASC', 'APP_NUMBER'); + $this->assertCount(1, $results['data']); + $this->assertEquals('Griffis Paul', $results['data'][0]['APP_CURRENT_USER']); + } + + /** + * This ensures return the correct data by parallel task all threads CLOSED + * @test + */ + public function it_should_return_by_parallel_tasks_threads_closed() + { + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + $task = factory(Task::class,1)->create([ + 'TAS_TITLE' => 'Parallel task 1' + ]); + factory(Delegation::class, 5)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'DEL_THREAD_STATUS' => 'CLOSED' + ]); + $task = factory(Task::class,1)->create([ + 'TAS_TITLE' => 'Parallel task 2' + ]); + factory(Delegation::class, 5)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'DEL_THREAD_STATUS' => 'CLOSED' + ]); + // Get first page, the order taskTitle + $results = Delegation::search(null, 0, 2, null, null, null, 'ASC', + 'TAS_TITLE', null, null, null,'TAS_TITLE'); + $this->assertCount(0, $results['data']); + + // Get first page, the order taskTitle + $results = Delegation::search(null, 0, 2, null, null, null, 'DESC', + 'TAS_TITLE', null, null, null,'TAS_TITLE'); + $this->assertCount(0, $results['data']); + } + + /** + * This ensures return the correct data by parallel task all threads OPEN + * @test + */ + public function it_should_return_by_parallel_tasks_threads_open() + { + factory(User::class,100)->create(); + factory(Process::class,1)->create(); + //Create the threads + factory(Delegation::class, 5)->create([ + 'DEL_THREAD_STATUS' => 'OPEN' + ]); + // Get first page, all the open status + $results = Delegation::search(null, 0, 5, null, null, null); + $this->assertCount(5, $results['data']); + $this->assertEquals('OPEN', $results['data'][0]['DEL_THREAD_STATUS']); + $this->assertEquals('OPEN', $results['data'][4]['DEL_THREAD_STATUS']); + + } } \ No newline at end of file diff --git a/workflow/engine/methods/cases/proxyCasesList.php b/workflow/engine/methods/cases/proxyCasesList.php index fbe9bd03e..0be7607f4 100644 --- a/workflow/engine/methods/cases/proxyCasesList.php +++ b/workflow/engine/methods/cases/proxyCasesList.php @@ -50,7 +50,7 @@ $filterStatus = isset($_REQUEST["filterStatus"]) ? strtoupper($_REQUEST["filterS // What user $user = isset($_REQUEST["user"]) ? $_REQUEST["user"] : ""; -// What search??? +// What keywords to search $search = isset($_REQUEST["search"]) ? $_REQUEST["search"] : ""; // What kind of action diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index 38e30c69c..eb367a03c 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -24,5 +24,4 @@ class Application extends Model { return $this->hasOne(User::class, 'APP_CUR_USER', 'USR_UID'); } - } diff --git a/workflow/engine/src/ProcessMaker/Model/Process.php b/workflow/engine/src/ProcessMaker/Model/Process.php index 52ff107e2..b32b92eb1 100644 --- a/workflow/engine/src/ProcessMaker/Model/Process.php +++ b/workflow/engine/src/ProcessMaker/Model/Process.php @@ -17,7 +17,6 @@ class Process extends Model // Our custom timestamp columns const CREATED_AT = 'PRO_CREATE_DATE'; const UPDATED_AT = 'PRO_UPDATE_DATE'; - /** * Retrieve all applications that belong to this process */ @@ -26,7 +25,6 @@ class Process extends Model return $this->hasMany(Application::class, 'PRO_ID', 'PRO_ID'); } - public function tasks() { return $this->hasMany(Task::class, 'PRO_UID', 'PRO_UID'); diff --git a/workflow/engine/src/ProcessMaker/Model/User.php b/workflow/engine/src/ProcessMaker/Model/User.php index 40fc1be55..7c6da958d 100644 --- a/workflow/engine/src/ProcessMaker/Model/User.php +++ b/workflow/engine/src/ProcessMaker/Model/User.php @@ -17,6 +17,5 @@ class User extends Model public function delegations() { return $this->hasMany(Delegation::class, 'USR_ID', 'USR_ID'); - } }