diff --git a/hook.php b/hook.php index 2ef1b94c5..d82c83aa7 100644 --- a/hook.php +++ b/hook.php @@ -102,7 +102,7 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link $ref_table, $already_link_tables, $issueSo[9]['table'], - 'users_id_validator', + $issueSo[9]['linkfield'], 0, 0, $issueSo[9]['joinparams'] @@ -112,7 +112,7 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link $ref_table, $already_link_tables, $issueSo[11]['table'], - 'users_id_validate', + $issueSo[11]['linkfield'], 0, 0, $issueSo[11]['joinparams'] @@ -122,11 +122,41 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link $ref_table, $already_link_tables, $issueSo[16]['table'], - 'groups_id_validator', + $issueSo[16]['linkfield'], 0, 0, $issueSo[16]['joinparams'] ); + $join .= Search::addLeftJoin( + $itemtype, + $ref_table, + $already_link_tables, + $issueSo[42]['table'], + $issueSo[42]['linkfield'], + 0, + 0, + $issueSo[42]['joinparams'] + ); + $join .= Search::addLeftJoin( + $itemtype, + $ref_table, + $already_link_tables, + $issueSo[43]['table'], + $issueSo[43]['linkfield'], + 0, + 0, + $issueSo[43]['joinparams'] + ); + $join .= Search::addLeftJoin( + $itemtype, + $ref_table, + $already_link_tables, + $issueSo[44]['table'], + $issueSo[44]['linkfield'], + 0, + 0, + $issueSo[44]['joinparams'] + ); } break; @@ -185,6 +215,19 @@ function plugin_formcreator_addDefaultWhere($itemtype) { // condition where current user is a validator of a issue of type ticket $complexJoinId = Search::computeComplexJoinID($issueSearchOptions[11]['joinparams']); $condition .= " OR `glpi_users_users_id_validate_$complexJoinId`.`id` = '$currentUser'"; + + // condition where the current user is a requester of a ticket linked to a form answer typed issue + $complexJoinId = Search::computeComplexJoinID($issueSearchOptions[42]['joinparams']); + $condition .= " OR `glpi_users_$complexJoinId`.`id` = '$currentUser'"; + + // condition where the current user is a watcher of a ticket linked to a form answer typed issue + $complexJoinId = Search::computeComplexJoinID($issueSearchOptions[43]['joinparams']); + $condition .= " OR `glpi_users_$complexJoinId`.`id` = '$currentUser'"; + + // condition where the current user is assigned of a ticket linked to a form answer typed issue + $complexJoinId = Search::computeComplexJoinID($issueSearchOptions[44]['joinparams']); + $condition .= " OR `glpi_users_$complexJoinId`.`id` = '$currentUser'"; + // Add users_id_recipient $condition .= " OR `glpi_plugin_formcreator_issues`.`users_id_recipient` = $currentUser "; return "($condition)"; diff --git a/inc/formanswer.class.php b/inc/formanswer.class.php index d8072dace..fc46103ad 100644 --- a/inc/formanswer.class.php +++ b/inc/formanswer.class.php @@ -164,6 +164,40 @@ public function canViewItem() { } } + // Check if the current user is a requester of a ticket linked to a form answer typed + // Matches search option 42, 43 and 44 of PluginFormcreatorIssue (requester, watcher, assigned) + $ticket_table = Ticket::getTable(); + $ticket_user_table = Ticket_User::getTable(); + $item_ticket_table = Item_Ticket::getTable(); + $request = [ + 'SELECT' => Ticket_User::getTableField(User::getForeignKeyField()), + 'FROM' => $ticket_user_table, + 'INNER JOIN' => [ + $ticket_table => [ + 'FKEY' => [ + $ticket_table => 'id', + $ticket_user_table => 'tickets_id', + ], + ], + $item_ticket_table => [ + 'FKEY' => [ + $item_ticket_table => 'tickets_id', + $ticket_table => 'id', + ['AND' => [ + Item_Ticket::getTableField('itemtype') => self::getType(), + ]], + ], + ], + + ] + ]; + + foreach ($DB->request($request) as $row) { + if ($row[User::getForeignKeyField()] == $currentUser) { + return true; + } + } + return false; } diff --git a/inc/issue.class.php b/inc/issue.class.php index 53a168dde..9856fd2c0 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -472,8 +472,8 @@ public function getTicketsForDisplay($options) { $item = $ticket; } } else { - // multiple tickets, ticket specified, then substitute the ticket to the form answer if (isset($options['tickets_id'])) { + // multiple tickets, ticket specified, then substitute the ticket to the form answer $ticket = Ticket::getById((int) $options['tickets_id']); if ($ticket) { $item = $ticket; @@ -645,17 +645,50 @@ public function rawSearchOptions() { 'massiveaction' => false, 'joinparams' => [ 'beforejoin' => [ - 'table' => TicketValidation::getTable(), - 'joinparams' => [ - 'jointype' => 'child', - 'beforejoin' => [ - 'table' => Ticket::getTable(), - 'joinparams' => [ - 'jointype' => 'itemtype_item_revert', - 'specific_itemtype' => Ticket::class, + [ + 'table' => TicketValidation::getTable(), + 'joinparams' => [ + 'jointype' => 'child', + 'beforejoin' => [ + 'table' => Ticket::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item_revert', + 'specific_itemtype' => Ticket::class, + ] ] ] - ] + ], + [ + 'table' => TicketValidation::getTable(), + 'joinparams' => [ + 'jointype' => 'child', + 'beforejoin' => [ + 'table' => Ticket::getTable(), + 'joinparams' => [ + 'jointype' => 'empty', + 'condition' => [ + new \QueryExpression( + '1=1' + ), + ], + 'beforejoin' => [ + 'table' => Item_Ticket::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item', + 'specific_itemtype' => PluginFormcreatorFormAnswer::class, + 'beforejoin' => [ + 'table' => PluginFormcreatorFormAnswer::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item_revert', + 'specific_itemtype' => PluginFormcreatorFormAnswer::class, + ], + ], + ], + ], + ], + ] + ] + ], ], ] ]; @@ -800,6 +833,149 @@ public function rawSearchOptions() { } } + $tab[] = [ + 'id' => '42', + 'table' => User::getTable(), + 'field' => 'name', + 'name' => __('Ticket requester', 'formcreator'), + 'massiveaction' => false, + 'datatype' => 'dropdown', + 'forcegroupby' => true, + 'joinparams' => [ + 'jointype' => 'empty', + 'beforejoin' => [ + 'table' => Ticket_User::getTable(), + 'joinparams' => [ + 'jointype' => 'child', + 'condition' => [ + 'NEWTABLE.type' => CommonITILActor::REQUESTER, + ], + 'beforejoin' => [ + 'table' => Ticket::getTable(), + 'joinparams' => [ + 'jointype' => 'empty', + 'condition' => [ + new \QueryExpression( + '1=1' + ), + ], + 'beforejoin' => [ + 'table' => Item_Ticket::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item', + 'specific_itemtype' => PluginFormcreatorFormAnswer::class, + 'beforejoin' => [ + 'table' => PluginFormcreatorFormAnswer::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item_revert', + 'specific_itemtype' => PluginFormcreatorFormAnswer::class, + ], + ], + ], + ], + ], + ], + ], + ], + ], + ]; + + $tab[] = [ + 'id' => '43', + 'table' => User::getTable(), + 'field' => 'name', + 'name' => __('Ticket observer', 'formcreator'), + 'massiveaction' => false, + 'nosearch' => true, + 'datatype' => 'dropdown', + 'forcegroupby' => true, + 'joinparams' => [ + 'jointype' => 'empty', + 'beforejoin' => [ + 'table' => Ticket_User::getTable(), + 'joinparams' => [ + 'jointype' => 'child', + 'condition' => [ + 'NEWTABLE.type' => CommonITILActor::OBSERVER, + ], + 'beforejoin' => [ + 'table' => Ticket::getTable(), + 'joinparams' => [ + 'jointype' => 'empty', + 'condition' => [ + new \QueryExpression( + '1=1' + ), + ], + 'beforejoin' => [ + 'table' => Item_Ticket::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item', + 'specific_itemtype' => PluginFormcreatorFormAnswer::class, + 'beforejoin' => [ + 'table' => PluginFormcreatorFormAnswer::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item_revert', + 'specific_itemtype' => PluginFormcreatorFormAnswer::class, + ], + ], + ], + ], + ], + ], + ], + ], + ], + ]; + + $tab[] = [ + 'id' => '44', + 'table' => User::getTable(), + 'field' => 'name', + 'name' => __('Ticket technician', 'formcreator'), + 'massiveaction' => false, + 'nosearch' => true, + 'datatype' => 'dropdown', + 'forcegroupby' => true, + 'joinparams' => [ + 'jointype' => 'empty', + 'beforejoin' => [ + 'table' => Ticket_User::getTable(), + 'joinparams' => [ + 'jointype' => 'child', + 'condition' => [ + 'NEWTABLE.type' => CommonITILActor::ASSIGN, + ], + 'beforejoin' => [ + 'table' => Ticket::getTable(), + 'joinparams' => [ + 'jointype' => 'empty', + 'condition' => [ + new \QueryExpression( + '1=1' + ), + ], + 'beforejoin' => [ + 'table' => Item_Ticket::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item', + 'specific_itemtype' => PluginFormcreatorFormAnswer::class, + 'beforejoin' => [ + 'table' => PluginFormcreatorFormAnswer::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item_revert', + 'specific_itemtype' => PluginFormcreatorFormAnswer::class, + ], + ], + ], + ], + ], + ], + ], + ], + ], + ]; + return $tab; }