diff --git a/public/index.php b/public/index.php index ab46a893cf..c20f780f0d 100644 --- a/public/index.php +++ b/public/index.php @@ -6,7 +6,7 @@ $lang = new \App\Translation(); $translator = $lang->loadLanguage(); $apiversion = 'v1'; -$basePath = "/gsit96"; +$basePath = "/"; $phpunit = false; // manage the basepath dynamically diff --git a/src/App.php b/src/App.php index 8bb2e66130..879eb01ea5 100644 --- a/src/App.php +++ b/src/App.php @@ -111,10 +111,6 @@ public function __construct() $GLOBALS['entity_id'] = $arguments['decoded']['entity_id']; $GLOBALS['entity_treepath'] = $arguments['decoded']['entity_treepath']; $GLOBALS['entity_recursive'] = $arguments['decoded']['entity_recursive']; - // Load permissions - // $GLOBALS['permissions'] = \App\v1\Controllers\Config\Role::generatePermission( - // $arguments['decoded']['role_id'] - // ); }, "error" => function ($response, $arguments) { diff --git a/src/Events/RuleCreating.php b/src/Events/RuleCreating.php new file mode 100644 index 0000000000..b8e9ffa6ad --- /dev/null +++ b/src/Events/RuleCreating.php @@ -0,0 +1,19 @@ +sub_type = 'Rule' . $spl[array_key_last($spl)]; + } +} diff --git a/src/Models/Appliance.php b/src/Models/Appliance.php index 3d7a64952f..8111276bba 100644 --- a/src/Models/Appliance.php +++ b/src/Models/Appliance.php @@ -3,7 +3,6 @@ namespace App\Models; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Database\Eloquent\Relations\MorphMany; diff --git a/src/Models/Common.php b/src/Models/Common.php index 0d000568d0..c8aa48b8da 100644 --- a/src/Models/Common.php +++ b/src/Models/Common.php @@ -182,6 +182,7 @@ public function getDropdownValues($filter = null) /** * Get definition fields of model * @param $bypassRights boolean Set true is not want manage rights (only on some features like notifications) + * @param $usein string=search|form|notification|rule Force to get only definition for this part of the app */ public function getDefinitions($bypassRights = false, $usein = null) { diff --git a/src/Models/Definitions/Applianceitem.php b/src/Models/Definitions/Applianceitem.php index 7c82a786b5..5f725dfda8 100644 --- a/src/Models/Definitions/Applianceitem.php +++ b/src/Models/Definitions/Applianceitem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Applianceitemrelation.php b/src/Models/Definitions/Applianceitemrelation.php index beb114514a..39dc5b45e6 100644 --- a/src/Models/Definitions/Applianceitemrelation.php +++ b/src/Models/Definitions/Applianceitemrelation.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Calendarsegment.php b/src/Models/Definitions/Calendarsegment.php index ad3d2f78a7..423dd81961 100644 --- a/src/Models/Definitions/Calendarsegment.php +++ b/src/Models/Definitions/Calendarsegment.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Cartridge.php b/src/Models/Definitions/Cartridge.php index 1df537afa3..b81a82a389 100644 --- a/src/Models/Definitions/Cartridge.php +++ b/src/Models/Definitions/Cartridge.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Certificateitem.php b/src/Models/Definitions/Certificateitem.php index 91351accb9..73ed004e46 100644 --- a/src/Models/Definitions/Certificateitem.php +++ b/src/Models/Definitions/Certificateitem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ChangeItem.php b/src/Models/Definitions/ChangeItem.php index 98321d3977..9dff6c93a7 100644 --- a/src/Models/Definitions/ChangeItem.php +++ b/src/Models/Definitions/ChangeItem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ChangeProblem.php b/src/Models/Definitions/ChangeProblem.php index 7ae389c42e..4dd3356edc 100644 --- a/src/Models/Definitions/ChangeProblem.php +++ b/src/Models/Definitions/ChangeProblem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ChangeTicket.php b/src/Models/Definitions/ChangeTicket.php index 5d231de4e6..a5a4f3edbb 100644 --- a/src/Models/Definitions/ChangeTicket.php +++ b/src/Models/Definitions/ChangeTicket.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Changecost.php b/src/Models/Definitions/Changecost.php index 105c4e0e93..1c089a8095 100644 --- a/src/Models/Definitions/Changecost.php +++ b/src/Models/Definitions/Changecost.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Changevalidation.php b/src/Models/Definitions/Changevalidation.php index 5467423891..70d1bc2f2b 100644 --- a/src/Models/Definitions/Changevalidation.php +++ b/src/Models/Definitions/Changevalidation.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Clusteritem.php b/src/Models/Definitions/Clusteritem.php index 6d5e409dae..8a89bf5cc3 100644 --- a/src/Models/Definitions/Clusteritem.php +++ b/src/Models/Definitions/Clusteritem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Computeritem.php b/src/Models/Definitions/Computeritem.php index d25fda94ed..65f5d7837c 100644 --- a/src/Models/Definitions/Computeritem.php +++ b/src/Models/Definitions/Computeritem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Consumable.php b/src/Models/Definitions/Consumable.php index 87db00f427..4fd4ae1aca 100644 --- a/src/Models/Definitions/Consumable.php +++ b/src/Models/Definitions/Consumable.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ContractItem.php b/src/Models/Definitions/ContractItem.php index 6292080b31..4410e47eac 100644 --- a/src/Models/Definitions/ContractItem.php +++ b/src/Models/Definitions/ContractItem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Documentitem.php b/src/Models/Definitions/Documentitem.php index eefe5f8244..5f8168f234 100644 --- a/src/Models/Definitions/Documentitem.php +++ b/src/Models/Definitions/Documentitem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Infocom.php b/src/Models/Definitions/Infocom.php index 88241d3926..803cc4d948 100644 --- a/src/Models/Definitions/Infocom.php +++ b/src/Models/Definitions/Infocom.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicebattery.php b/src/Models/Definitions/ItemDevicebattery.php index e8a5ab5ada..ed69e750ca 100644 --- a/src/Models/Definitions/ItemDevicebattery.php +++ b/src/Models/Definitions/ItemDevicebattery.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicecase.php b/src/Models/Definitions/ItemDevicecase.php index 6e5b8f2e11..2ab26f9709 100644 --- a/src/Models/Definitions/ItemDevicecase.php +++ b/src/Models/Definitions/ItemDevicecase.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicecontrol.php b/src/Models/Definitions/ItemDevicecontrol.php index 4b47b00a7e..ddfad5e781 100644 --- a/src/Models/Definitions/ItemDevicecontrol.php +++ b/src/Models/Definitions/ItemDevicecontrol.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicedrive.php b/src/Models/Definitions/ItemDevicedrive.php index 5656fa3b5e..16cb6270bc 100644 --- a/src/Models/Definitions/ItemDevicedrive.php +++ b/src/Models/Definitions/ItemDevicedrive.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicefirmware.php b/src/Models/Definitions/ItemDevicefirmware.php index 01f996fa9c..f871e861af 100644 --- a/src/Models/Definitions/ItemDevicefirmware.php +++ b/src/Models/Definitions/ItemDevicefirmware.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicegeneric.php b/src/Models/Definitions/ItemDevicegeneric.php index 38d9029afd..820fd42940 100644 --- a/src/Models/Definitions/ItemDevicegeneric.php +++ b/src/Models/Definitions/ItemDevicegeneric.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicegraphiccard.php b/src/Models/Definitions/ItemDevicegraphiccard.php index 8c2a615c92..b021408113 100644 --- a/src/Models/Definitions/ItemDevicegraphiccard.php +++ b/src/Models/Definitions/ItemDevicegraphiccard.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDeviceharddrive.php b/src/Models/Definitions/ItemDeviceharddrive.php index 6be6d40270..5d36d035c7 100644 --- a/src/Models/Definitions/ItemDeviceharddrive.php +++ b/src/Models/Definitions/ItemDeviceharddrive.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicememory.php b/src/Models/Definitions/ItemDevicememory.php index 2b14795fed..118954031d 100644 --- a/src/Models/Definitions/ItemDevicememory.php +++ b/src/Models/Definitions/ItemDevicememory.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicemotherboard.php b/src/Models/Definitions/ItemDevicemotherboard.php index a5bcf27818..5a850f3d33 100644 --- a/src/Models/Definitions/ItemDevicemotherboard.php +++ b/src/Models/Definitions/ItemDevicemotherboard.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicenetworkcard.php b/src/Models/Definitions/ItemDevicenetworkcard.php index 4aaf030d33..068d4a60cc 100644 --- a/src/Models/Definitions/ItemDevicenetworkcard.php +++ b/src/Models/Definitions/ItemDevicenetworkcard.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicepci.php b/src/Models/Definitions/ItemDevicepci.php index f8689d0aa8..3468ea4377 100644 --- a/src/Models/Definitions/ItemDevicepci.php +++ b/src/Models/Definitions/ItemDevicepci.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicepowersupply.php b/src/Models/Definitions/ItemDevicepowersupply.php index 69b89578d7..d367fca08b 100644 --- a/src/Models/Definitions/ItemDevicepowersupply.php +++ b/src/Models/Definitions/ItemDevicepowersupply.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDeviceprocessor.php b/src/Models/Definitions/ItemDeviceprocessor.php index 7d8f1bfbc0..ffd94b0260 100644 --- a/src/Models/Definitions/ItemDeviceprocessor.php +++ b/src/Models/Definitions/ItemDeviceprocessor.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicesensor.php b/src/Models/Definitions/ItemDevicesensor.php index 172df1df6b..92e6fddd9e 100644 --- a/src/Models/Definitions/ItemDevicesensor.php +++ b/src/Models/Definitions/ItemDevicesensor.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemDevicesoundcard.php b/src/Models/Definitions/ItemDevicesoundcard.php index e51c895405..8ab29b06af 100644 --- a/src/Models/Definitions/ItemDevicesoundcard.php +++ b/src/Models/Definitions/ItemDevicesoundcard.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemEnclosure.php b/src/Models/Definitions/ItemEnclosure.php index 87a97dd6d5..01b46e63c1 100644 --- a/src/Models/Definitions/ItemEnclosure.php +++ b/src/Models/Definitions/ItemEnclosure.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemProblem.php b/src/Models/Definitions/ItemProblem.php index 383f08263e..a9ef978933 100644 --- a/src/Models/Definitions/ItemProblem.php +++ b/src/Models/Definitions/ItemProblem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemSoftwarelicence.php b/src/Models/Definitions/ItemSoftwarelicence.php index 5b00e8debc..76357002b1 100644 --- a/src/Models/Definitions/ItemSoftwarelicence.php +++ b/src/Models/Definitions/ItemSoftwarelicence.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemSoftwareversion.php b/src/Models/Definitions/ItemSoftwareversion.php index 132f1ceeb4..c06ca834ee 100644 --- a/src/Models/Definitions/ItemSoftwareversion.php +++ b/src/Models/Definitions/ItemSoftwareversion.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ItemTicket.php b/src/Models/Definitions/ItemTicket.php index b8526556ed..0164dea589 100644 --- a/src/Models/Definitions/ItemTicket.php +++ b/src/Models/Definitions/ItemTicket.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Itilproject.php b/src/Models/Definitions/Itilproject.php index 44ff25a1ff..847d9417d6 100644 --- a/src/Models/Definitions/Itilproject.php +++ b/src/Models/Definitions/Itilproject.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Networkalias.php b/src/Models/Definitions/Networkalias.php index a24d5b91f2..a73b158268 100644 --- a/src/Models/Definitions/Networkalias.php +++ b/src/Models/Definitions/Networkalias.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Ola.php b/src/Models/Definitions/Ola.php index ed15b8d4ff..74f5a8eb90 100644 --- a/src/Models/Definitions/Ola.php +++ b/src/Models/Definitions/Ola.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ProblemTicket.php b/src/Models/Definitions/ProblemTicket.php index db1d3b6dc2..a9f4f4a411 100644 --- a/src/Models/Definitions/ProblemTicket.php +++ b/src/Models/Definitions/ProblemTicket.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Problemcost.php b/src/Models/Definitions/Problemcost.php index 3ad40814b2..562b81c155 100644 --- a/src/Models/Definitions/Problemcost.php +++ b/src/Models/Definitions/Problemcost.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ProfileUser.php b/src/Models/Definitions/ProfileUser.php index d382c20de6..c8b4897529 100644 --- a/src/Models/Definitions/ProfileUser.php +++ b/src/Models/Definitions/ProfileUser.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Projectcost.php b/src/Models/Definitions/Projectcost.php index 07b0d37507..8f209c19f4 100644 --- a/src/Models/Definitions/Projectcost.php +++ b/src/Models/Definitions/Projectcost.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Projectitem.php b/src/Models/Definitions/Projectitem.php index e00525572f..c9304ac79c 100644 --- a/src/Models/Definitions/Projectitem.php +++ b/src/Models/Definitions/Projectitem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/ProjecttaskTicket.php b/src/Models/Definitions/ProjecttaskTicket.php index d52d85be05..c6fcacf639 100644 --- a/src/Models/Definitions/ProjecttaskTicket.php +++ b/src/Models/Definitions/ProjecttaskTicket.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Projecttaskteam.php b/src/Models/Definitions/Projecttaskteam.php index cd2f80bf34..f1998e0f0c 100644 --- a/src/Models/Definitions/Projecttaskteam.php +++ b/src/Models/Definitions/Projecttaskteam.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Projectteam.php b/src/Models/Definitions/Projectteam.php index 97100822dd..186291268d 100644 --- a/src/Models/Definitions/Projectteam.php +++ b/src/Models/Definitions/Projectteam.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Reservation.php b/src/Models/Definitions/Reservation.php index 0168de3b24..b38151c9a6 100644 --- a/src/Models/Definitions/Reservation.php +++ b/src/Models/Definitions/Reservation.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Reservationitem.php b/src/Models/Definitions/Reservationitem.php index 4ed88fc263..124ea53ba6 100644 --- a/src/Models/Definitions/Reservationitem.php +++ b/src/Models/Definitions/Reservationitem.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Rule.php b/src/Models/Definitions/Rule.php index e5753bcad5..e7c033b7ef 100644 --- a/src/Models/Definitions/Rule.php +++ b/src/Models/Definitions/Rule.php @@ -21,6 +21,7 @@ public static function getDefinition() 'type' => 'input', 'name' => 'ranking', 'fillable' => true, + 'display' => false, ], [ 'id' => 4, diff --git a/src/Models/Definitions/Rulecriterium.php b/src/Models/Definitions/Rulecriterium.php index 68e3ed0492..f8d9869fd6 100644 --- a/src/Models/Definitions/Rulecriterium.php +++ b/src/Models/Definitions/Rulecriterium.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Sla.php b/src/Models/Definitions/Sla.php index 616a6f2124..6aea0ac025 100644 --- a/src/Models/Definitions/Sla.php +++ b/src/Models/Definitions/Sla.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Ticketcost.php b/src/Models/Definitions/Ticketcost.php index 91099028b9..ef1ace5c20 100644 --- a/src/Models/Definitions/Ticketcost.php +++ b/src/Models/Definitions/Ticketcost.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Tickettemplatehiddenfields.php b/src/Models/Definitions/Tickettemplatehiddenfields.php index 517268e90b..f14c6eaf07 100644 --- a/src/Models/Definitions/Tickettemplatehiddenfields.php +++ b/src/Models/Definitions/Tickettemplatehiddenfields.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Tickettemplatemandatoryfields.php b/src/Models/Definitions/Tickettemplatemandatoryfields.php index 062c8514be..33433fa919 100644 --- a/src/Models/Definitions/Tickettemplatemandatoryfields.php +++ b/src/Models/Definitions/Tickettemplatemandatoryfields.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Tickettemplatepredefinedfields.php b/src/Models/Definitions/Tickettemplatepredefinedfields.php index 3feac97226..7db2bdc50e 100644 --- a/src/Models/Definitions/Tickettemplatepredefinedfields.php +++ b/src/Models/Definitions/Tickettemplatepredefinedfields.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/Ticketvalidation.php b/src/Models/Definitions/Ticketvalidation.php index 1729b857bf..8226db0162 100644 --- a/src/Models/Definitions/Ticketvalidation.php +++ b/src/Models/Definitions/Ticketvalidation.php @@ -13,7 +13,6 @@ public static function getDefinition() 'title' => $translator->translate('ID'), 'type' => 'input', 'name' => 'id', - 'displaygroup' => 'main', 'display' => false, ], ]; diff --git a/src/Models/Definitions/_specifications.md b/src/Models/Definitions/_specifications.md index 0fb8aec0df..3e03b7dc26 100644 --- a/src/Models/Definitions/_specifications.md +++ b/src/Models/Definitions/_specifications.md @@ -14,6 +14,10 @@ Mandatory fields: * type: string | values are: * input * inputpassword + * textarea + * email + * boolean + * date * datetime * dropdown * dropdown_remote diff --git a/src/Models/Rules/Ruleaction.php b/src/Models/Rules/Ruleaction.php index 774bcaac48..e8cff385e5 100644 --- a/src/Models/Rules/Ruleaction.php +++ b/src/Models/Rules/Ruleaction.php @@ -30,11 +30,9 @@ class Ruleaction extends \App\Models\Common public function getFieldviewfieldAttribute() { $rule = \App\Models\Rules\Rule::find($this->attributes['rule_id']); - $modelName = '\App\Models\Rules\\' . ltrim($rule->sub_type, 'Rule'); + $modelName = '\App\Models\\' . ltrim($rule->sub_type, 'Rule'); - $ruleCtrl = new $modelName(); - // TODO get model - $model = new \App\Models\Ticket(); + $model = new $modelName(); // get definitions $definitions = $model->getDefinitions(); foreach ($definitions as $def) diff --git a/src/Models/Rules/Rulecriterium.php b/src/Models/Rules/Rulecriterium.php index 486c6d0ad0..a7712f3609 100644 --- a/src/Models/Rules/Rulecriterium.php +++ b/src/Models/Rules/Rulecriterium.php @@ -28,11 +28,9 @@ class Rulecriterium extends \App\Models\Common public function getCriteriaAttribute() { $rule = \App\Models\Rules\Rule::find($this->attributes['rule_id']); - $modelName = '\App\Models\Rules\\' . ltrim($rule->sub_type, 'Rule'); + $modelName = '\App\Models\\' . ltrim($rule->sub_type, 'Rule'); - $ruleCtrl = new $modelName(); - // TODO get model - $model = new \App\Models\Ticket(); + $model = new $modelName(); // get definitions $definitions = $model->getDefinitions(); foreach ($definitions as $def) @@ -45,7 +43,7 @@ public function getCriteriaAttribute() return []; } - public function getPattern() + public function getPatternAttribute() { $pattern = $this->attributes['pattern']; $criteria = $this->getCriteriaAttribute(); @@ -87,6 +85,7 @@ public function getPattern() public function getPatternviewfieldAttribute() { $criteria = $this->criteria; + $criteria['title'] = 'Pattern'; if (!is_array($criteria)) { $criteria = $this->getCriteriaAttribute($criteria); @@ -99,11 +98,11 @@ public function getPatternviewfieldAttribute() } if ($criteria['type'] == 'dropdown' || $criteria['type'] == 'dropdown_remote') { - $pattern = $this->getPattern(); + $pattern = $this->getPatternAttribute(); if (is_array($pattern)) { - $criteria['name'] = $pattern['id']; - $criteria['value'] = $pattern['value']; + $criteria['value'] = $pattern['id']; + $criteria['valuename'] = $pattern['value']; } } return $criteria; diff --git a/src/Models/Rules/Ticket.php b/src/Models/Rules/Ticket.php index df2672f7a2..cae891dee0 100644 --- a/src/Models/Rules/Ticket.php +++ b/src/Models/Rules/Ticket.php @@ -28,6 +28,11 @@ class Ticket extends \App\Models\Common 'actions', ]; + // For default values + protected $attributes = [ + 'sub_type' => 'RuleTicket', + ]; + protected static function booted(): void { parent::booted(); diff --git a/src/Route.php b/src/Route.php index 4825abb0bb..28a1a6e649 100644 --- a/src/Route.php +++ b/src/Route.php @@ -35,6 +35,26 @@ public static function setRoutes(&$app) '/dropdown/rule/criteria/condition', \App\v1\Controllers\Dropdown::class . ':getRuleCriteriaCondition' ); + $view->map( + ['GET'], + '/dropdown/rule/criteria/pattern', + \App\v1\Controllers\Dropdown::class . ':getRuleCriteriaPattern' + ); + $view->map( + ['GET'], + '/dropdown/rule/actions/field', + \App\v1\Controllers\Dropdown::class . ':getRuleActionsField' + ); + $view->map( + ['GET'], + '/dropdown/rule/actions/actiontype', + \App\v1\Controllers\Dropdown::class . ':getRuleActionsType' + ); + $view->map( + ['GET'], + '/dropdown/rule/actions/value', + \App\v1\Controllers\Dropdown::class . ':getRuleActionsValue' + ); $view->group('/login', function (RouteCollectorProxy $login) { @@ -988,6 +1008,12 @@ public static function setRoutes(&$app) $rules->group("/tickets", function (RouteCollectorProxy $tickets) { $tickets->map(['GET'], '', \App\v1\Controllers\Rules\Ticket::class . ':getAll'); + $tickets->group("/new", function (RouteCollectorProxy $ticketNew) + { + $ticketNew->map(['GET'], '', \App\v1\Controllers\Rules\Ticket::class . ':showNewItem'); + $ticketNew->map(['POST'], '', \App\v1\Controllers\Rules\Ticket::class . ':newItem'); + }); + $tickets->group("/{id:[0-9]+}", function (RouteCollectorProxy $ticketId) { $ticketId->map(['GET'], '', \App\v1\Controllers\Rules\Ticket::class . ':showItem'); @@ -995,7 +1021,17 @@ public static function setRoutes(&$app) $ticketId->group('/', function (RouteCollectorProxy $sub) { $sub->map(['GET'], 'criteria', \App\v1\Controllers\Rules\Ticket::class . ':showCriteria'); + $sub->group("criteria/new", function (RouteCollectorProxy $criteriaNew) + { + $criteriaNew->map(['GET'], '', \App\v1\Controllers\Rules\Ticket::class . ':showNewCriteria'); + $criteriaNew->map(['POST'], '', \App\v1\Controllers\Rules\Ticket::class . ':newCriteria'); + }); $sub->map(['GET'], 'actions', \App\v1\Controllers\Rules\Ticket::class . ':showActions'); + $sub->group("actions/new", function (RouteCollectorProxy $actionNew) + { + $actionNew->map(['GET'], '', \App\v1\Controllers\Rules\Ticket::class . ':showNewAction'); + $actionNew->map(['POST'], '', \App\v1\Controllers\Rules\Ticket::class . ':newAction'); + }); }); }); }); diff --git a/src/v1/Controllers/Dropdown.php b/src/v1/Controllers/Dropdown.php index 316b2b3b1a..3616c0b47b 100644 --- a/src/v1/Controllers/Dropdown.php +++ b/src/v1/Controllers/Dropdown.php @@ -11,48 +11,7 @@ final class Dropdown extends Common { public function getAll(Request $request, Response $response, $args): Response { - // $data = json_decode($request->getBody()); $data = (object) $request->getQueryParams(); - - // POST - // itemtype - // filter - // entity_restrict - // page (option) - - // GLPI values - // itemtype "ITILCategory" - // display_emptychoice "1" - // emptylabel "-----" - // condition "fc20cd4dd8f56c07f744c2684be72be48c64dc53" - // entity_restrict "0" - // permit_select_parent "0" - // _idor_toke "5e4a3ab5e4137a71daccbaf311c2ad8f0cdccaefc09cbd0d363efd70cfebbc58" - // page_limit "100" - // page "1" - - // response format - JSON - // { - // "success": true, - // "results": [ - // { - // // name displayed in dropdown - // "name" : "Choice 1", - // // selected value - // "value" : "value1", - // // name displayed after selection (optional) - // "text" : "Choice 1" - // // whether field should be displayed as disabled (optional) - // "disabled" : false - // }, - // { - // "name" : "Choice 2", - // "value" : "value2", - // "text" : "Choice 2" - // } - // ] - // } - $dropData = []; $success = false; @@ -77,6 +36,9 @@ public function getAll(Request $request, Response $response, $args): Response return $response->withHeader('Content-Type', 'application/json'); } + /** + * Get the criteria for a rule + */ public function getRuleCriteria(Request $request, Response $response, $args): Response { $data = (object) $request->getQueryParams(); @@ -84,14 +46,18 @@ public function getRuleCriteria(Request $request, Response $response, $args): Re $dropData = []; $success = false; - $classname = '\\App\\v1\\Controllers\\Rules\\Criteria\\' . $data->itemtype; + $classname = '\\App\\Models\\' . $data->itemtype; + $item = new $classname(); - $criteria = $classname::get(); - foreach ($criteria as $id => $crit) + // TODO manage usein = rule + // TODO manage only fields have display = true + + $criteria = $item->getDefinitions(); + foreach ($criteria as $crit) { $dropData[] = [ 'name' => $crit['title'], - 'value' => $id, + 'value' => $crit['name'], ]; } @@ -104,65 +70,310 @@ public function getRuleCriteria(Request $request, Response $response, $args): Re return $response->withHeader('Content-Type', 'application/json'); } + /** + * Get the condition rule, for the criteria selected + */ public function getRuleCriteriaCondition(Request $request, Response $response, $args): Response { global $translator; $data = (object) $request->getQueryParams(); - $dropData = [ - [ - 'name' => $translator->translate('is'), - 'value' => \App\v1\Controllers\Rules\Common::PATTERN_IS, - ], - [ - 'name' => $translator->translate('is not'), - 'value' => \App\v1\Controllers\Rules\Common::PATTERN_IS_NOT, - ], - [ - 'name' => $translator->translate('contains'), - 'value' => \App\v1\Controllers\Rules\Common::PATTERN_CONTAIN, - ], - [ - 'name' => $translator->translate('does not contains'), - 'value' => \App\v1\Controllers\Rules\Common::PATTERN_NOT_CONTAIN, - ], - [ - 'name' => $translator->translate('starting with'), - 'value' => \App\v1\Controllers\Rules\Common::PATTERN_BEGIN, - ], - [ - 'name' => $translator->translate('finished by'), - 'value' => \App\v1\Controllers\Rules\Common::PATTERN_END, - ], - [ - 'name' => $translator->translate('regular expression matches'), - 'value' => \App\v1\Controllers\Rules\Common::REGEX_MATCH, - ], - [ - 'name' => $translator->translate('regular expression does not match'), - 'value' => \App\v1\Controllers\Rules\Common::REGEX_NOT_MATCH, - ], - [ - 'name' => $translator->translate('exists'), - 'value' => \App\v1\Controllers\Rules\Common::PATTERN_EXISTS, - ], - [ - 'name' => $translator->translate('does not exist'), - 'value' => \App\v1\Controllers\Rules\Common::PATTERN_DOES_NOT_EXISTS, - ], + $conditions = \App\v1\Controllers\Rules\Criterium::getConditionsForDefinition( + $data->itemtype, + $data->definitionname + ); + + $dropData = []; + foreach ($conditions as $condition) + { + switch ($condition) { + case \App\v1\Controllers\Rules\Common::PATTERN_IS: + $dropData[] = [ + 'name' => $translator->translate('is'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_IS_NOT: + $dropData[] = [ + 'name' => $translator->translate('is not'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_CONTAIN: + $dropData[] = [ + 'name' => $translator->translate('contains'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_NOT_CONTAIN: + $dropData[] = [ + 'name' => $translator->translate('does not contains'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_BEGIN: + $dropData[] = [ + 'name' => $translator->translate('starting with'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_END: + $dropData[] = [ + 'name' => $translator->translate('finished by'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::REGEX_MATCH: + $dropData[] = [ + 'name' => $translator->translate('regular expression matches'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::REGEX_NOT_MATCH: + $dropData[] = [ + 'name' => $translator->translate('regular expression does not match'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_EXISTS: + $dropData[] = [ + 'name' => $translator->translate('exists'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_DOES_NOT_EXISTS: + $dropData[] = [ + 'name' => $translator->translate('does not exist'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_UNDER: + $dropData[] = [ + 'name' => $translator->translate('is under'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_NOT_UNDER: + $dropData[] = [ + 'name' => $translator->translate('is not under'), + 'value' => $condition, + ]; + break; + + case \App\v1\Controllers\Rules\Common::PATTERN_IS_EMPTY: + $dropData[] = [ + 'name' => $translator->translate('is empty'), + 'value' => $condition, + ]; + break; + } + } + + $respdata = [ + "success" => true, + "results" => $dropData, ]; - $success = false; - $classname = '\\App\\v1\\Controllers\\Rules\\Criteria\\' . $data->itemtype; + $response->getBody()->write(json_encode($respdata)); + return $response->withHeader('Content-Type', 'application/json'); + } + + /** + * Get the rule pattern, based on criteria and condition + */ + public function getRuleCriteriaPattern(Request $request, Response $response, $args): Response + { + global $translator; + + $data = (object) $request->getQueryParams(); + // itemtype + // definitionname + // condition + + $returnData = []; + switch ($data->condition) { + case \App\v1\Controllers\Rules\Common::PATTERN_IS: + case \App\v1\Controllers\Rules\Common::PATTERN_IS_NOT: + case \App\v1\Controllers\Rules\Common::PATTERN_UNDER: + case \App\v1\Controllers\Rules\Common::PATTERN_NOT_UNDER: + $completeModelName = '\App\Models\\' . $data->itemtype; + if (!class_exists($completeModelName)) + { + return []; + } + $itemCriteria = new $completeModelName(); + + $definitions = $itemCriteria->getDefinitions(); + foreach ($definitions as $definition) + { + if ($definition['name'] == $data->definitionname) + { + if (isset($definition['values'])) + { + $valuesForDrodown = []; + foreach ($definition['values'] as $key => $value) + { + $valuesForDrodown[] = [ + 'name' => $value['title'], + 'value' => $key, + ]; + } + + $respdata = [ + "success" => true, + "results" => $valuesForDrodown, + ]; + $response->getBody()->write(json_encode($respdata)); + return $response->withHeader('Content-Type', 'application/json'); + } + $item = new $definition['itemtype'](); + $returnData = $item->getDropdownValues($data->q); + $respdata = [ + "success" => true, + "results" => $returnData, + ]; + $response->getBody()->write(json_encode($respdata)); + return $response->withHeader('Content-Type', 'application/json'); + } + } + break; - // $criteria = $classname::get(); - // $crit = $criteria[$data->criteria] + case \App\v1\Controllers\Rules\Common::PATTERN_EXISTS: + case \App\v1\Controllers\Rules\Common::PATTERN_DOES_NOT_EXISTS: + case \App\v1\Controllers\Rules\Common::PATTERN_IS_EMPTY: + $returnData[] = [ + 'name' => $translator->translate('yes'), + 'value' => true, + ]; + break; + } + $respdata = [ + "success" => true, + "results" => $returnData, + ]; + $response->getBody()->write(json_encode($respdata)); + return $response->withHeader('Content-Type', 'application/json'); + } + + public function getRuleActionsField(Request $request, Response $response, $args): Response + { + return $this->getRuleCriteria($request, $response, $args); + } + public function getRuleActionsType(Request $request, Response $response, $args): Response + { + global $translator; + + $data = (object) $request->getQueryParams(); + $completeModelName = '\App\Models\\' . $data->itemtype; + if (!class_exists($completeModelName)) + { + return []; + } + $item = new $completeModelName(); + $definitions = $item->getDefinitions(); + $types = []; + foreach ($definitions as $definition) + { + if ($definition['name'] == $data->definitionname) + { + switch ($definition['type']) { + case 'dropdown_remote': + case 'dropdown': + case 'boolean': + $types = [ + [ + 'name' => $translator->translate('assign'), + 'value' => 'assign_dropdown' + ] + ]; + if (isset($definition['multiple'])) + { + $types[] = [ + 'name' => $translator->translate('append'), + 'value' => 'append_dropdown' + ]; + } + break; + + case 'input': + case 'textarea': + case 'date': + case 'datetime': + $types = [ + [ + 'name' => $translator->translate('assign'), + 'value' => 'assign' + ], + [ + 'name' => $translator->translate('append'), + 'value' => 'append' + ], + [ + 'name' => $translator->translate('assign regex result'), + 'value' => 'regex_result' + ], + [ + 'name' => $translator->translate('append regex result'), + 'value' => 'append_regex_result' + ] + ]; + break; + } + break; + } + } + $respdata = [ + "success" => true, + "results" => $types, + ]; + $response->getBody()->write(json_encode($respdata)); + return $response->withHeader('Content-Type', 'application/json'); + } + + public function getRuleActionsValue(Request $request, Response $response, $args): Response + { + $data = (object) $request->getQueryParams(); + $completeModelName = '\App\Models\\' . $data->itemtype; + if (!class_exists($completeModelName)) + { + return []; + } + $respdata = []; + $dropData = []; + $success = false; + + $item = new $completeModelName(); + $definitions = $item->getDefinitions(); + + foreach ($definitions as $definition) + { + if ($definition['name'] == $data->field) + { + if (class_exists($definition['itemtype'])) + { + $item = new $definition['itemtype'](); + $dropData = $item->getDropdownValues($data->q); + $success = true; + } + break; + } + } $respdata = [ "success" => $success, "results" => $dropData, ]; - $response->getBody()->write(json_encode($respdata)); return $response->withHeader('Content-Type', 'application/json'); } diff --git a/src/v1/Controllers/Rules/Action.php b/src/v1/Controllers/Rules/Action.php index 8ab638527c..00e0331439 100644 --- a/src/v1/Controllers/Rules/Action.php +++ b/src/v1/Controllers/Rules/Action.php @@ -9,6 +9,10 @@ public function runAction($action, $preparedData, array $regexResult = []) switch ($action->action_type) { case "assign": + $preparedData[$action->field] = $action->value; + break; + + case "assign_dropdown": if (isset($action->fieldviewfield['multiple'])) { $preparedData[$action->field] = [$action->value]; @@ -18,6 +22,15 @@ public function runAction($action, $preparedData, array $regexResult = []) break; case "append": + if (!isset($preparedData[$action->field])) + { + $preparedData[$action->field] = $action->value; + } else { + $preparedData[$action->field] .= $action->value; + } + break; + + case "append_dropdown": if (!isset($preparedData[$action->field])) { if (isset($action->fieldviewfield['multiple'])) diff --git a/src/v1/Controllers/Rules/Common.php b/src/v1/Controllers/Rules/Common.php index 7c325c4372..c8715c01ea 100644 --- a/src/v1/Controllers/Rules/Common.php +++ b/src/v1/Controllers/Rules/Common.php @@ -101,7 +101,7 @@ public function checkCriterias($rule, $item, $preparedData) foreach ($criteria as $criterium) { $crit = new \App\v1\Controllers\Rules\Criterium(); - $ret = $crit->checkCriteria($criterium, $preparedData, $item->getDefinitions()); + $ret = $crit->checkCriteria($criterium, $preparedData); if (trim($rule->match) == self::AND_MATCHING && $ret === false) { return false; diff --git a/src/v1/Controllers/Rules/Criteria/Ticket.php b/src/v1/Controllers/Rules/Criteria/Ticket.php index 944f283726..b25195c47f 100644 --- a/src/v1/Controllers/Rules/Criteria/Ticket.php +++ b/src/v1/Controllers/Rules/Criteria/Ticket.php @@ -9,281 +9,281 @@ public static function get() global $translator; return [ - 'name' => [ - 'title' => $translator->translate('Title'), - 'dbname' => 'name', - 'type' => 'string', - 'execute' => 'standard', - ], - 'content' => [ - 'title' => $translator->translate('Description'), - 'dbname' => 'content', - 'type' => 'string', - 'execute' => 'standard', - ], + // 'name' => [ + // 'title' => $translator->translate('Title'), + // 'dbname' => 'name', + // 'type' => 'string', + // 'execute' => 'standard', + // ], + // 'content' => [ + // 'title' => $translator->translate('Description'), + // 'dbname' => 'content', + // 'type' => 'string', + // 'execute' => 'standard', + // ], - // 'date_mod' => [ - // // 'table' => 'glpi_tickets', - // 'model' => '\App\Models\Ticket', - // 'field' => 'date_mod', - // 'name' => $translator->translate('Last update'), - // 'linkfield' => 'date_mod', - // ], + // // 'date_mod' => [ + // // // 'table' => 'glpi_tickets', + // // 'model' => '\App\Models\Ticket', + // // 'field' => 'date_mod', + // // 'name' => $translator->translate('Last update'), + // // 'linkfield' => 'date_mod', + // // ], - 'itilcategories_id' => [ - 'title' => $translator->translate('Category') . ' - ' . $translator->translate('Name'), - 'dbname' => 'category_id', - 'model' => '\App\Models\Category', - 'relationdbname' => 'name', - 'type' => 'dropdown', - 'execute' => 'standard', - ], - 'itilcategories_id_cn' => [ - 'title' => $translator->translate('Category') . ' - ' . $translator->translate('Complete name'), - 'dbname' => 'category_id', - 'model' => '\App\Models\Category', - 'relationdbname' => 'completename', - 'type' => 'dropdown', - 'execute' => 'standard', - ], - 'itilcategories_id_code' => [ - 'title' => $translator->translate('Code representing the ticket category'), - 'dbname' => 'category_id', - 'model' => '\App\Models\Category', - 'relationdbname' => 'code', - 'type' => 'dropdown', - 'execute' => 'standard', - ], + // 'itilcategories_id' => [ + // 'title' => $translator->translate('Category') . ' - ' . $translator->translate('Name'), + // 'dbname' => 'category_id', + // 'model' => '\App\Models\Category', + // 'relationdbname' => 'name', + // 'type' => 'dropdown_remote', + // 'execute' => 'standard', + // ], + // 'itilcategories_id_cn' => [ + // 'title' => $translator->translate('Category') . ' - ' . $translator->translate('Complete name'), + // 'dbname' => 'category_id', + // 'model' => '\App\Models\Category', + // 'relationdbname' => 'completename', + // 'type' => 'dropdown_remote', + // 'execute' => 'standard', + // ], + // 'itilcategories_id_code' => [ + // 'title' => $translator->translate('Code representing the ticket category'), + // 'dbname' => 'category_id', + // 'model' => '\App\Models\Category', + // 'relationdbname' => 'code', + // 'type' => 'dropdown_remote', + // 'execute' => 'standard', + // ], - // 'type' => [ - // // 'table' => 'glpi_tickets', - // 'model' => '\App\Models\Ticket', - // 'field' => 'type', - // 'name' => $translator->translatePlural('Type', 'Types', 1), - // 'linkfield' => 'type', - // 'type' => 'dropdown_tickettype', - // ], - // '_users_id_requester' => [ - // // 'table' => 'glpi_users', - // 'model' => '\App\Models\User', - // 'field' => 'name', - // 'name' => $translator->translatePlural('Requester', 'Requesters', 1), - // 'linkfield' => '_users_id_requester', - // 'type' => 'dropdown_users', - // 'linked_criteria' => '_groups_id_of_requester', - // ], - // '_groups_id_of_requester' => [ - // // 'table' => 'glpi_groups', - // 'model' => '\App\Models\Group', - // 'field' => 'completename', - // 'name' => $translator->translate('Requester in group'), - // 'linkfield' => '_groups_id_of_requester', - // 'type' => 'dropdown', - // ], - // '_locations_id_of_requester' => [ - // // 'table' => 'glpi_locations', - // 'model' => '\App\Models\Location', - // 'field' => 'completename', - // 'name' => $translator->translate('Requester location'), - // 'linkfield' => '_locations_id_of_requester', - // 'type' => 'dropdown', - // ], + // // 'type' => [ + // // // 'table' => 'glpi_tickets', + // // 'model' => '\App\Models\Ticket', + // // 'field' => 'type', + // // 'name' => $translator->translatePlural('Type', 'Types', 1), + // // 'linkfield' => 'type', + // // 'type' => 'dropdown_tickettype', + // // ], + // // '_users_id_requester' => [ + // // // 'table' => 'glpi_users', + // // 'model' => '\App\Models\User', + // // 'field' => 'name', + // // 'name' => $translator->translatePlural('Requester', 'Requesters', 1), + // // 'linkfield' => '_users_id_requester', + // // 'type' => 'dropdown_users', + // // 'linked_criteria' => '_groups_id_of_requester', + // // ], + // // '_groups_id_of_requester' => [ + // // // 'table' => 'glpi_groups', + // // 'model' => '\App\Models\Group', + // // 'field' => 'completename', + // // 'name' => $translator->translate('Requester in group'), + // // 'linkfield' => '_groups_id_of_requester', + // // 'type' => 'dropdown', + // // ], + // // '_locations_id_of_requester' => [ + // // // 'table' => 'glpi_locations', + // // 'model' => '\App\Models\Location', + // // 'field' => 'completename', + // // 'name' => $translator->translate('Requester location'), + // // 'linkfield' => '_locations_id_of_requester', + // // 'type' => 'dropdown', + // // ], - '_locations_id_of_item' => [ - 'title' => $translator->translate('Item location'), - 'dbname' => null, - 'model' => '\App\Models\Location', - 'relationdbname' => 'completename', - 'type' => 'dropdown', - 'execute' => 'locationOfItem', - ], + // '_locations_id_of_item' => [ + // 'title' => $translator->translate('Item location'), + // 'dbname' => null, + // 'model' => '\App\Models\Location', + // 'relationdbname' => 'completename', + // 'type' => 'dropdown', + // 'execute' => 'locationOfItem', + // ], - // '_groups_id_of_item' => [ - // // 'table' => 'glpi_groups', - // 'model' => '\App\Models\Group', - // 'field' => 'completename', - // 'name' => $translator->translate('Item group'), - // 'linkfield' => '_groups_id_of_item', - // 'type' => 'dropdown', - // ], - // '_states_id_of_item' => [ - // // 'table' => 'glpi_states', - // 'model' => '\App\Models\State', - // 'field' => 'completename', - // 'name' => $translator->translate('Item state'), - // 'linkfield' => '_states_id_of_item', - // 'type' => 'dropdown', - // ], + // // '_groups_id_of_item' => [ + // // // 'table' => 'glpi_groups', + // // 'model' => '\App\Models\Group', + // // 'field' => 'completename', + // // 'name' => $translator->translate('Item group'), + // // 'linkfield' => '_groups_id_of_item', + // // 'type' => 'dropdown', + // // ], + // // '_states_id_of_item' => [ + // // // 'table' => 'glpi_states', + // // 'model' => '\App\Models\State', + // // 'field' => 'completename', + // // 'name' => $translator->translate('Item state'), + // // 'linkfield' => '_states_id_of_item', + // // 'type' => 'dropdown', + // // ], - 'locations_id' => [ - 'title' => $translator->translate('Ticket location'), - 'dbname' => 'locations_id', - 'model' => '\App\Models\Location', - 'relationdbname' => 'completename', - 'type' => 'dropdown', - 'execute' => 'standard', - ], + // 'locations_id' => [ + // 'title' => $translator->translate('Ticket location'), + // 'dbname' => 'locations_id', + // 'model' => '\App\Models\Location', + // 'relationdbname' => 'completename', + // 'type' => 'dropdown', + // 'execute' => 'standard', + // ], - // '_groups_id_requester' => [ - // // 'table' => 'glpi_groups', - // 'model' => '\App\Models\Group', - // 'field' => 'completename', - // 'name' => $translator->translatePlural('Requester group', 'Requester groups', 1), - // 'linkfield' => '_groups_id_requester', - // 'type' => 'dropdown', - // ], - // '_users_id_assign' => [ - // // 'table' => 'glpi_users', - // 'model' => '\App\Models\User', - // 'field' => 'name', - // 'name' => $translator->translate('Technician'), - // 'linkfield' => '_users_id_assign', - // 'type' => 'dropdown_users', - // ], - // '_groups_id_assign' => [ - // // 'table' => 'glpi_groups', - // 'model' => '\App\Models\Group', - // 'field' => 'completename', - // 'name' => $translator->translate('Technician group'), - // 'linkfield' => '_groups_id_assign', - // 'type' => 'dropdown', - // 'condition' => ['is_assign' => 1], - // ], - // '_suppliers_id_assign' => [ - // // 'table' => 'glpi_suppliers', - // 'model' => '\App\Models\Supplier', - // 'field' => 'name', - // 'name' => $translator->translate('Assigned to a supplier'), - // 'linkfield' => '_suppliers_id_assign', - // 'type' => 'dropdown', - // ], - // '_users_id_observer' => [ - // // 'table' => 'glpi_users', - // 'model' => '\App\Models\User', - // 'field' => 'name', - // 'name' => $translator->translatePlural('Watcher', 'Watchers', 1), - // 'linkfield' => '_users_id_observer', - // 'type' => 'dropdown_users', - // ], - // '_groups_id_observer' => [ - // // 'table' => 'glpi_groups', - // 'model' => '\App\Models\Group', - // 'field' => 'completename', - // 'name' => $translator->translatePlural('Watcher group', 'Watcher groups', 1), - // 'linkfield' => '_groups_id_observer', - // 'type' => 'dropdown', - // ], - // 'requesttypes_id' => [ - // // 'table' => 'glpi_requesttypes', - // 'model' => '\App\Models\Requesttype', - // 'field' => 'name', - // 'name' => $translator->translatePlural('Request source', 'Request sources', 1), - // 'linkfield' => 'requesttypes_id', - // 'type' => 'dropdown', - // ], - // 'itemtype' => [ - // // 'table' => 'glpi_tickets', - // 'model' => '\App\Models\Ticket', - // 'field' => 'itemtype', - // 'name' => $translator->translate('Item type'), - // 'linkfield' => 'itemtype', - // 'type' => 'dropdown_tracking_itemtype', - // ], - // 'entities_id' => [ - // // 'table' => 'glpi_entities', - // 'model' => '\App\Models\Entity', - // 'field' => 'name', - // 'name' => $translator->translatePlural('Entity', 'Entities', 1), - // 'linkfield' => 'entities_id', - // 'type' => 'dropdown', - // ], - // 'profiles_id' => [ - // // 'table' => 'glpi_profiles', - // 'model' => '\App\Models\Profile', - // 'field' => 'name', - // 'name' => $translator->translate('Default profile'), - // 'linkfield' => 'profiles_id', - // 'type' => 'dropdown', - // ], - // 'urgency' => [ - // 'name' => $translator->translate('Urgency'), - // 'type' => 'dropdown_urgency', - // ], - // 'impact' => [ - // 'name' => $translator->translate('Impact'), - // 'type' => 'dropdown_impact', - // ], - // 'priority' => [ - // 'name' => $translator->translate('Priority'), - // 'type' => 'dropdown_priority', - // ], - // 'status' => [ - // 'table' => '', - // 'field' => '', - // 'name' => $translator->translate('Status'), - // 'type' => 'dropdown_status', - // ], - // '_mailgate' => [ - // // 'table' => 'glpi_mailcollectors', - // 'model' => '\App\Models\Mailcollector', - // 'field' => 'name', - // 'name' => $translator->translate('Mails receiver'), - // 'linkfield' => '_mailgate', - // 'type' => 'dropdown', - // ], - // '_x-priority' => [ - // 'table' => '', - // 'name' => $translator->translate('X-Priority email header'), - // 'type' => 'text', - // ], - // 'slas_id_ttr' => [ - // // 'table' => 'glpi_slas', - // 'model' => '\App\Models\Sla', - // 'field' => 'name', - // 'name' => $translator->translate('SLA') . ' ' . $translator->translate('Time to resolve'), - // 'linkfield' => 'slas_id_ttr', - // 'type' => 'dropdown', - // // 'condition' => ['glpi_slas.type' => SLM::TTR], - // ], - // 'slas_id_tto' => [ - // // 'table' => 'glpi_slas', - // 'model' => '\App\Models\Sla', - // 'field' => 'name', - // 'name' => $translator->translate('SLA') . ' ' . $translator->translate('Time to own'), - // 'linkfield' => 'slas_id_tto', - // 'type' => 'dropdown', - // // 'condition' => ['glpi_slas.type' => SLM::TTO], - // ], - // 'olas_id_ttr' => [ - // // 'table' => 'glpi_olas', - // 'model' => '\App\Models\Ola', - // 'field' => 'name', - // 'name' => $translator->translate('OLA') . ' ' . $translator->translate('Time to resolve'), - // 'linkfield' => 'olas_id_ttr', - // 'type' => 'dropdown', - // // 'condition' => ['glpi_olas.type' => SLM::TTR], - // ], - // 'olas_id_tto' => [ - // // 'table' => 'glpi_olas', - // 'model' => '\App\Models\Ola', - // 'field' => 'name', - // 'name' => $translator->translate('OLA') . ' ' . $translator->translate('Time to own'), - // 'linkfield' => 'olas_id_tto', - // 'type' => 'dropdown', - // // 'condition' => ['glpi_olas.type' => SLM::TTO], - // ], - // '_date_creation_calendars_id' => [ - // // 'table' => 'calendars', - // 'model' => '\App\Models\Calendar', - // 'field' => 'name', - // 'name' => $translator->translate('Creation date is a working hour in calendar'), - // 'linkfield' => '_date_creation_calendars_id', - // 'type' => 'dropdown', - // ], + // // '_groups_id_requester' => [ + // // // 'table' => 'glpi_groups', + // // 'model' => '\App\Models\Group', + // // 'field' => 'completename', + // // 'name' => $translator->translatePlural('Requester group', 'Requester groups', 1), + // // 'linkfield' => '_groups_id_requester', + // // 'type' => 'dropdown', + // // ], + // // '_users_id_assign' => [ + // // // 'table' => 'glpi_users', + // // 'model' => '\App\Models\User', + // // 'field' => 'name', + // // 'name' => $translator->translate('Technician'), + // // 'linkfield' => '_users_id_assign', + // // 'type' => 'dropdown_users', + // // ], + // // '_groups_id_assign' => [ + // // // 'table' => 'glpi_groups', + // // 'model' => '\App\Models\Group', + // // 'field' => 'completename', + // // 'name' => $translator->translate('Technician group'), + // // 'linkfield' => '_groups_id_assign', + // // 'type' => 'dropdown', + // // 'condition' => ['is_assign' => 1], + // // ], + // // '_suppliers_id_assign' => [ + // // // 'table' => 'glpi_suppliers', + // // 'model' => '\App\Models\Supplier', + // // 'field' => 'name', + // // 'name' => $translator->translate('Assigned to a supplier'), + // // 'linkfield' => '_suppliers_id_assign', + // // 'type' => 'dropdown', + // // ], + // // '_users_id_observer' => [ + // // // 'table' => 'glpi_users', + // // 'model' => '\App\Models\User', + // // 'field' => 'name', + // // 'name' => $translator->translatePlural('Watcher', 'Watchers', 1), + // // 'linkfield' => '_users_id_observer', + // // 'type' => 'dropdown_users', + // // ], + // // '_groups_id_observer' => [ + // // // 'table' => 'glpi_groups', + // // 'model' => '\App\Models\Group', + // // 'field' => 'completename', + // // 'name' => $translator->translatePlural('Watcher group', 'Watcher groups', 1), + // // 'linkfield' => '_groups_id_observer', + // // 'type' => 'dropdown', + // // ], + // // 'requesttypes_id' => [ + // // // 'table' => 'glpi_requesttypes', + // // 'model' => '\App\Models\Requesttype', + // // 'field' => 'name', + // // 'name' => $translator->translatePlural('Request source', 'Request sources', 1), + // // 'linkfield' => 'requesttypes_id', + // // 'type' => 'dropdown', + // // ], + // // 'itemtype' => [ + // // // 'table' => 'glpi_tickets', + // // 'model' => '\App\Models\Ticket', + // // 'field' => 'itemtype', + // // 'name' => $translator->translate('Item type'), + // // 'linkfield' => 'itemtype', + // // 'type' => 'dropdown_tracking_itemtype', + // // ], + // // 'entities_id' => [ + // // // 'table' => 'glpi_entities', + // // 'model' => '\App\Models\Entity', + // // 'field' => 'name', + // // 'name' => $translator->translatePlural('Entity', 'Entities', 1), + // // 'linkfield' => 'entities_id', + // // 'type' => 'dropdown', + // // ], + // // 'profiles_id' => [ + // // // 'table' => 'glpi_profiles', + // // 'model' => '\App\Models\Profile', + // // 'field' => 'name', + // // 'name' => $translator->translate('Default profile'), + // // 'linkfield' => 'profiles_id', + // // 'type' => 'dropdown', + // // ], + // // 'urgency' => [ + // // 'name' => $translator->translate('Urgency'), + // // 'type' => 'dropdown_urgency', + // // ], + // // 'impact' => [ + // // 'name' => $translator->translate('Impact'), + // // 'type' => 'dropdown_impact', + // // ], + // // 'priority' => [ + // // 'name' => $translator->translate('Priority'), + // // 'type' => 'dropdown_priority', + // // ], + // // 'status' => [ + // // 'table' => '', + // // 'field' => '', + // // 'name' => $translator->translate('Status'), + // // 'type' => 'dropdown_status', + // // ], + // // '_mailgate' => [ + // // // 'table' => 'glpi_mailcollectors', + // // 'model' => '\App\Models\Mailcollector', + // // 'field' => 'name', + // // 'name' => $translator->translate('Mails receiver'), + // // 'linkfield' => '_mailgate', + // // 'type' => 'dropdown', + // // ], + // // '_x-priority' => [ + // // 'table' => '', + // // 'name' => $translator->translate('X-Priority email header'), + // // 'type' => 'text', + // // ], + // // 'slas_id_ttr' => [ + // // // 'table' => 'glpi_slas', + // // 'model' => '\App\Models\Sla', + // // 'field' => 'name', + // // 'name' => $translator->translate('SLA') . ' ' . $translator->translate('Time to resolve'), + // // 'linkfield' => 'slas_id_ttr', + // // 'type' => 'dropdown', + // // // 'condition' => ['glpi_slas.type' => SLM::TTR], + // // ], + // // 'slas_id_tto' => [ + // // // 'table' => 'glpi_slas', + // // 'model' => '\App\Models\Sla', + // // 'field' => 'name', + // // 'name' => $translator->translate('SLA') . ' ' . $translator->translate('Time to own'), + // // 'linkfield' => 'slas_id_tto', + // // 'type' => 'dropdown', + // // // 'condition' => ['glpi_slas.type' => SLM::TTO], + // // ], + // // 'olas_id_ttr' => [ + // // // 'table' => 'glpi_olas', + // // 'model' => '\App\Models\Ola', + // // 'field' => 'name', + // // 'name' => $translator->translate('OLA') . ' ' . $translator->translate('Time to resolve'), + // // 'linkfield' => 'olas_id_ttr', + // // 'type' => 'dropdown', + // // // 'condition' => ['glpi_olas.type' => SLM::TTR], + // // ], + // // 'olas_id_tto' => [ + // // // 'table' => 'glpi_olas', + // // 'model' => '\App\Models\Ola', + // // 'field' => 'name', + // // 'name' => $translator->translate('OLA') . ' ' . $translator->translate('Time to own'), + // // 'linkfield' => 'olas_id_tto', + // // 'type' => 'dropdown', + // // // 'condition' => ['glpi_olas.type' => SLM::TTO], + // // ], + // // '_date_creation_calendars_id' => [ + // // // 'table' => 'calendars', + // // 'model' => '\App\Models\Calendar', + // // 'field' => 'name', + // // 'name' => $translator->translate('Creation date is a working hour in calendar'), + // // 'linkfield' => '_date_creation_calendars_id', + // // 'type' => 'dropdown', + // // ], ]; } } diff --git a/src/v1/Controllers/Rules/Criterium.php b/src/v1/Controllers/Rules/Criterium.php index fccedf4b65..14bb4b97c3 100644 --- a/src/v1/Controllers/Rules/Criterium.php +++ b/src/v1/Controllers/Rules/Criterium.php @@ -8,9 +8,8 @@ final class Criterium // TODO rename in criterion - public function checkCriteria(\App\Models\Rules\Rulecriterium $crit, $input, $definitions) + public function checkCriteria(\App\Models\Rules\Rulecriterium $crit, $input) { - $criterium = new self(); // separate condition on multiple groups // group 1: check id (is, is not, exists, not exists, empty, under, not under) @@ -46,13 +45,21 @@ public function checkCriteria(\App\Models\Rules\Rulecriterium $crit, $input, $de $inputVal = $input[$crit->criteria['name']]; $patternId = null; - if ($crit->patternviewfield['type'] == 'boolean') + if ($crit->criteria['type'] == 'boolean') { - $patternId = $crit->patternviewfield['value']; + if (is_bool($crit->pattern) === true) + { + $patternId = $crit->pattern; + } else { + $patternId = boolval($crit->pattern); + } } - elseif ($crit->patternviewfield['name'] != 'pattern') + elseif ( + ($crit->criteria['type'] == 'dropdown' || $crit->criteria['type'] == 'dropdown_remote') && + is_array($crit->pattern) + ) { - $patternId = $crit->patternviewfield['name']; + $patternId = $crit->pattern['id']; } // TODO @@ -86,13 +93,18 @@ public function checkCriteria(\App\Models\Rules\Rulecriterium $crit, $input, $de $patternValue = ''; $modelName = null; - if (isset($crit->patternviewfield['value'])) + // if (isset($crit->patternviewfield['valuename'])) + // { + // $patternValue = $crit->patternviewfield['value']; + // } else { + if (is_array($crit->pattern)) { - $patternValue = $crit->patternviewfield['value']; + $patternValue = $crit->pattern['value']; } else { - $patternValue = $crit->patternviewfield['value']; - // $patternValue = $crit->pattern; + $patternValue = $crit->pattern; } + // $patternValue = $crit->pattern; + // } if (isset($crit->criteria['itemtype'])) { $modelName = $crit->criteria['itemtype']; @@ -205,9 +217,9 @@ public static function getConditionForCriterium($criteria, $condition) ]; return [ - 'title' => $translator->translate('condition'), + 'title' => $translator->translate('Condition'), 'type' => 'dropdown', - 'name' => 'condition', + 'name' => 'ondition', 'values' => $values, 'value' => $condition, 'valuename' => $values[$condition]['title'], @@ -611,4 +623,92 @@ public function getRegexResults() { return $this->regexResults; } + + public static function getConditionsForDefinition($model, $name) + { + $completeModelName = '\App\Models\\' . $model; + if (!class_exists($completeModelName)) + { + return []; + } + $item = new $completeModelName(); + $definitions = $item->getDefinitions(); + + $type = null; + $typeModelTree = false; + foreach ($definitions as $definition) + { + if ($definition['name'] == $name) + { + $type = $definition['type']; + if (isset($definition['itemtype'])) + { + $typeModel = $definition['itemtype']; + $item = new $typeModel(); + $typeModelTree = $item->isTree(); + } + break; + } + } + + if (is_null($type)) + { + return []; + } + + $conditions = []; + switch ($type) + { + case 'string': + case 'input': + case 'textarea': + case 'email': + case 'date': + case 'datetime': + $conditions = [ + \App\v1\Controllers\Rules\Common::PATTERN_CONTAIN, + \App\v1\Controllers\Rules\Common::PATTERN_NOT_CONTAIN, + \App\v1\Controllers\Rules\Common::PATTERN_BEGIN, + \App\v1\Controllers\Rules\Common::PATTERN_END, + \App\v1\Controllers\Rules\Common::REGEX_MATCH, + \App\v1\Controllers\Rules\Common::REGEX_NOT_MATCH, + \App\v1\Controllers\Rules\Common::PATTERN_EXISTS, + \App\v1\Controllers\Rules\Common::PATTERN_DOES_NOT_EXISTS, + \App\v1\Controllers\Rules\Common::PATTERN_IS_EMPTY, + ]; + break; + + case 'boolean': + $conditions = [ + \App\v1\Controllers\Rules\Common::PATTERN_IS, + \App\v1\Controllers\Rules\Common::PATTERN_IS_NOT, + \App\v1\Controllers\Rules\Common::PATTERN_EXISTS, + \App\v1\Controllers\Rules\Common::PATTERN_DOES_NOT_EXISTS, + ]; + break; + + case 'dropdown': + case 'dropdown_remote': + $conditions = [ + \App\v1\Controllers\Rules\Common::PATTERN_IS, + \App\v1\Controllers\Rules\Common::PATTERN_IS_NOT, + \App\v1\Controllers\Rules\Common::PATTERN_CONTAIN, + \App\v1\Controllers\Rules\Common::PATTERN_NOT_CONTAIN, + \App\v1\Controllers\Rules\Common::PATTERN_BEGIN, + \App\v1\Controllers\Rules\Common::PATTERN_END, + \App\v1\Controllers\Rules\Common::REGEX_MATCH, + \App\v1\Controllers\Rules\Common::REGEX_NOT_MATCH, + \App\v1\Controllers\Rules\Common::PATTERN_EXISTS, + \App\v1\Controllers\Rules\Common::PATTERN_DOES_NOT_EXISTS, + \App\v1\Controllers\Rules\Common::PATTERN_IS_EMPTY, + ]; + if ($typeModelTree) + { + $conditions[] = \App\v1\Controllers\Rules\Common::PATTERN_UNDER; + $conditions[] = \App\v1\Controllers\Rules\Common::PATTERN_NOT_UNDER; + } + break; + } + return $conditions; + } } diff --git a/src/v1/Controllers/Rules/Ticket.php b/src/v1/Controllers/Rules/Ticket.php index e5c21a4efc..f92eb12682 100644 --- a/src/v1/Controllers/Rules/Ticket.php +++ b/src/v1/Controllers/Rules/Ticket.php @@ -5,7 +5,6 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; -use Slim\Routing\RouteContext; final class Ticket extends Common { @@ -55,12 +54,16 @@ public function showCriteria(Request $request, Response $response, $args): Respo $list = []; foreach ($rulecriteria as $rc) { + $condition = \App\v1\Controllers\Rules\Criterium::getConditionForCriterium($rc->criteria, $rc->condition); + $condition['readonly'] = true; + $patternviewfield = $rc->patternviewfield; + $patternviewfield['readonly'] = true; $list[] = [ 'id' => $rc->id, 'criteria' => $rc->criteria, - 'condition' => \App\v1\Controllers\Rules\Criterium::getConditionForCriterium($rc->criteria, $rc->condition), + 'condition' => $condition, 'pattern' => $rc->pattern, - 'patternviewfield' => $rc->patternviewfield, + 'patternviewfield' => $patternviewfield, ]; } @@ -78,7 +81,7 @@ public function showCriteria(Request $request, Response $response, $args): Respo $viewData->addData('model', 'Ticket'); - return $view->render($response, 'subitem/rulecriteria.html.twig', (array)$viewData); + return $view->render($response, 'subitem/Rules/rulecriteria.html.twig', (array)$viewData); } public function showActions(Request $request, Response $response, $args): Response @@ -102,6 +105,7 @@ public function showActions(Request $request, Response $response, $args): Respon 'type' => 'dropdown', 'name' => 'value', 'values' => [], + 'readonly' => true, ]; foreach ($definitions as $definition) { @@ -115,11 +119,14 @@ public function showActions(Request $request, Response $response, $args): Respon } } + $value = $ra->valueviewfield; + $value['readonly'] = true; + $value['title'] = 'Value'; $list[] = [ 'id' => $ra->id, 'action_type' => $ra->action_type, 'field' => $fields, - 'value' => $ra->valueviewfield, + 'value' => $value, ]; } @@ -134,6 +141,94 @@ public function showActions(Request $request, Response $response, $args): Respon $viewData->addData('fields', $item->getFormData($myItem)); $viewData->addData('actions', $list); - return $view->render($response, 'subitem/ruleactions.html.twig', (array)$viewData); + return $view->render($response, 'subitem/Rules/ruleactions.html.twig', (array)$viewData); + } + + public function showNewCriteria(Request $request, Response $response, $args): Response + { + $item = new \App\Models\Rules\Ticket(); + $view = Twig::fromRequest($request); + + // Load the item + $myItem = $item->find($args['id']); + + $rootUrl = $this->getUrlWithoutQuery($request); + $rootUrl = rtrim($rootUrl, '/criteria/new'); + + // form data + $viewData = new \App\v1\Controllers\Datastructures\Viewdata($myItem, $request); + $viewData->addHeaderColor('red'); + + $viewData->addRelatedPages($item->getRelatedPages($rootUrl)); + + $viewData->addData('fields', $item->getFormData($myItem)); + + $viewData->addData('model', 'Ticket'); + + return $view->render($response, 'subitem/Rules/newcriteria.html.twig', (array)$viewData); + } + + public function newCriteria(Request $request, Response $response, $args): Response + { + $data = (object) $request->getParsedBody(); + + $item = new \App\Models\Rules\Rulecriterium(); + $item->rule_id = $args['id']; + $item->criteria = $data->criteria; + $item->condition = $data->condition; + $item->pattern = $data->pattern; + $item->save(); + + // add message to session + \App\v1\Controllers\Toolbox::addSessionMessage('The criterion has been created successfully'); + + $uri = $request->getUri(); + $newUrl = rtrim((string) $uri, '/new'); + header('Location: ' . $newUrl); + exit(); + } + + public function showNewAction(Request $request, Response $response, $args): Response + { + $item = new \App\Models\Rules\Ticket(); + $view = Twig::fromRequest($request); + + // Load the item + $myItem = $item->find($args['id']); + + $rootUrl = $this->getUrlWithoutQuery($request); + $rootUrl = rtrim($rootUrl, '/actions/new'); + + // form data + $viewData = new \App\v1\Controllers\Datastructures\Viewdata($myItem, $request); + $viewData->addHeaderColor('red'); + + $viewData->addRelatedPages($item->getRelatedPages($rootUrl)); + + $viewData->addData('fields', $item->getFormData($myItem)); + + $viewData->addData('model', 'Ticket'); + + return $view->render($response, 'subitem/Rules/newaction.html.twig', (array)$viewData); + } + + public function newAction(Request $request, Response $response, $args): Response + { + $data = (object) $request->getParsedBody(); + + $item = new \App\Models\Rules\Ruleaction(); + $item->rule_id = $args['id']; + $item->action_type = $data->actiontype; + $item->field = $data->field; + $item->value = $data->value; + $item->save(); + + // add message to session + \App\v1\Controllers\Toolbox::addSessionMessage('The action has been created successfully'); + + $uri = $request->getUri(); + $newUrl = rtrim((string) $uri, '/new'); + header('Location: ' . $newUrl); + exit(); } } diff --git a/src/v1/Controllers/Ticket.php b/src/v1/Controllers/Ticket.php index 9613387d35..1287ebcb85 100644 --- a/src/v1/Controllers/Ticket.php +++ b/src/v1/Controllers/Ticket.php @@ -159,8 +159,6 @@ public function updateItem(Request $request, Response $response, $args): Respons $updateData = $rule->processAllRules( $input ); - // print_r($updateData); - // exit; foreach ($updateData as $field => $value) { @@ -225,20 +223,9 @@ public function runRules($data, $id) } $preparedData = $rule->prepareData($ticket, $data); - - // echo "
"; - // print_r($preparedData); - // echo ""; - $ruledData = $rule->processAllRules($ticket, $preparedData); - // echo "
"; - // print_r($ruledData); - // echo ""; - $data = $rule->parseNewData($ticket, $data, $ruledData); - - return $data; } diff --git a/src/v1/Views/footer.html.twig b/src/v1/Views/footer.html.twig index 59c7d7db12..d8b7b3aff3 100644 --- a/src/v1/Views/footer.html.twig +++ b/src/v1/Views/footer.html.twig @@ -15,19 +15,18 @@ encodeParameters: false, cache: false, url: '{url}?q={query}&itemtype={itemtype}', - } + } }); $('.remotedropdownrulecondition') .dropdown({ - // minCharacters: 2, saveRemoteData: false, preserveHTML : false, apiSettings: { encodeParameters: false, cache: false, - url: '{url}?q={query}&itemtype={itemtype}&criteria={criteria}', - } + url: '{url}?itemtype={itemtype}&definitionname={definitionname}', + } }); diff --git a/src/v1/Views/subitem/Rules/newaction.html.twig b/src/v1/Views/subitem/Rules/newaction.html.twig new file mode 100644 index 0000000000..154ae700fd --- /dev/null +++ b/src/v1/Views/subitem/Rules/newaction.html.twig @@ -0,0 +1,95 @@ +{{ include('header.html.twig') }} +{{ include('headerForm.html.twig') }} + + {# `action_type` varchar(255) DEFAULT NULL, + `field` varchar(255) DEFAULT NULL, + `value` longtext DEFAULT NULL, #} + +