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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ permissions:
jobs:
generate-ci-matrix:
name: "Generate CI matrix"
uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1"
uses: "stonebuzz/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@glpi13"
with:
glpi-version: "12.0.x"
glpi-version: "13.0.x"
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
needs: "generate-ci-matrix"
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-ci-matrix.outputs.matrix) }}
uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1"
uses: "stonebuzz/plugin-ci-workflows/.github/workflows/continuous-integration.yml@glpi13"
with:
plugin-key: "advancedforms"
glpi-version: "${{ matrix.glpi-version }}"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- "Email followup" destination field to disable the followup per actor source, with a command to import it from Formcreator
- Add "Allow specific languages" form access policy
- Add "GLPI system information" and "GLPI core or plugins concerned" question types
- GLPI 13 compatibility

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"require": {
"php": ">=8.2"
"php": ">=8.3"
},
"config": {
"autoloader-suffix": "PluginAdvancedforms",
"optimize-autoloader": true,
"platform": {
"php": "8.2.99"
"php": "8.3.99"
},
"sort-packages": true
}
Expand Down
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@

// Minimal GLPI version, inclusive
/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define("PLUGIN_ADVANCEDFORMS_MIN_GLPI_VERSION", "12.0.0");
define("PLUGIN_ADVANCEDFORMS_MIN_GLPI_VERSION", "13.0.0");

// Maximum GLPI version, exclusive
/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define("PLUGIN_ADVANCEDFORMS_MAX_GLPI_VERSION", "12.0.99");
define("PLUGIN_ADVANCEDFORMS_MAX_GLPI_VERSION", "13.0.99");

/**
* Init hooks of the plugin.
Expand Down
26 changes: 13 additions & 13 deletions src/Console/ImportFormcreatorActorsNotificationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,42 +67,42 @@
final class ImportFormcreatorActorsNotificationCommand extends AbstractCommand
{
/** One config row per imported destination */
public const IMPORTED_DESTINATIONS_CONFIG_CONTEXT = 'advancedforms:formcreator_actors_notification';
public const string IMPORTED_DESTINATIONS_CONFIG_CONTEXT = 'advancedforms:formcreator_actors_notification';

private const ACTORS_TABLE = 'glpi_plugin_formcreator_targets_actors';
private const string ACTORS_TABLE = 'glpi_plugin_formcreator_targets_actors';

private const FORMS_TABLE = 'glpi_plugin_formcreator_forms';
private const string FORMS_TABLE = 'glpi_plugin_formcreator_forms';

private const QUESTIONS_TABLE = 'glpi_plugin_formcreator_questions';
private const string QUESTIONS_TABLE = 'glpi_plugin_formcreator_questions';

/** Formcreator target itemtype => [target table, destination type] */
private const TARGETS = [
private const array TARGETS = [
'PluginFormcreatorTargetTicket' => ['glpi_plugin_formcreator_targettickets', FormDestinationTicket::class],
'PluginFormcreatorTargetChange' => ['glpi_plugin_formcreator_targetchanges', FormDestinationChange::class],
'PluginFormcreatorTargetProblem' => ['glpi_plugin_formcreator_targetproblems', FormDestinationProblem::class],
];

/** PluginFormcreatorTarget_Actor::ACTOR_ROLE_* => actor role */
private const ROLES = [
private const array ROLES = [
1 => 'requester',
2 => 'observer',
3 => 'assign',
];

// PluginFormcreatorTarget_Actor::ACTOR_TYPE_* having an email followup
private const ACTOR_TYPE_CREATOR = 1;
private const int ACTOR_TYPE_CREATOR = 1;

private const ACTOR_TYPE_PERSON = 3;
private const int ACTOR_TYPE_PERSON = 3;

private const ACTOR_TYPE_QUESTION_PERSON = 4;
private const int ACTOR_TYPE_QUESTION_PERSON = 4;

private const ACTOR_TYPE_SUPPLIER = 7;
private const int ACTOR_TYPE_SUPPLIER = 7;

private const ACTOR_TYPE_QUESTION_SUPPLIER = 8;
private const int ACTOR_TYPE_QUESTION_SUPPLIER = 8;

private const ACTOR_TYPE_QUESTION_ACTORS = 9;
private const int ACTOR_TYPE_QUESTION_ACTORS = 9;

private const QUESTION_ACTOR_TYPES = [
private const array QUESTION_ACTOR_TYPES = [
self::ACTOR_TYPE_QUESTION_PERSON,
self::ACTOR_TYPE_QUESTION_SUPPLIER,
self::ACTOR_TYPE_QUESTION_ACTORS,
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/GetReservationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace GlpiPlugin\Advancedforms\Controller;

use Session;
use Glpi\Http\Firewall;
use Glpi\Security\Attribute\SecurityStrategy;
use Reservation;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function __invoke(Request $request): Response

// No lower bound given by the caller: only return current/future slots,
// never the item's whole reservation history.
$now = $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s');
$now = Session::getCurrentTime() ?? date('Y-m-d H:i:s');
$where = [
'reservationitems_id' => $reservationitems_id,
'end' => ['>', $begin !== '' ? $begin : $now],
Expand Down
5 changes: 3 additions & 2 deletions src/Model/AccessControl/LanguageAccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace GlpiPlugin\Advancedforms\Model\AccessControl;

use Session;
use Dropdown;
use Glpi\Application\View\TemplateRenderer;
use Glpi\DBAL\JsonFieldInterface;
Expand All @@ -49,7 +50,7 @@

final class LanguageAccessControl implements ControlTypeInterface
{
public const INPUT_NAME = '_advancedforms_languages';
public const string INPUT_NAME = '_advancedforms_languages';

#[Override]
public function getLabel(): string
Expand Down Expand Up @@ -134,7 +135,7 @@ public function canAnswer(

// Deny (not Abstain) so the language restricts every other policy:
// "All users" + this policy means "all users using a listed language".
$language = $_SESSION['glpilanguage'] ?? null;
$language = Session::getLanguage();
if (!in_array($language, $config->getLanguages(), true)) {
return AccessVote::Deny;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/AccessControl/LanguageAccessControlConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

final readonly class LanguageAccessControlConfig implements JsonFieldInterface
{
public const KEY_LANGUAGES = 'languages';
public const string KEY_LANGUAGES = 'languages';

/** @param string[] $languages GLPI language codes (see LanguageRegistry) */
public function __construct(
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Destination/ActorNotificationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
final class ActorNotificationField extends AbstractConfigField
{
/** Strategies with a single toggle for all the actors they find. */
private const STRATEGY_LEVEL_SOURCES = [
private const array STRATEGY_LEVEL_SOURCES = [
ITILActorFieldStrategy::FORM_FILLER,
ITILActorFieldStrategy::FORM_FILLER_SUPERVISOR,
ITILActorFieldStrategy::LAST_VALID_ANSWER,
Expand All @@ -83,7 +83,7 @@ final class ActorNotificationField extends AbstractConfigField
];

/** Groups have no email followup on an ITIL object. */
private const NOTIFIABLE_ITEMTYPES = [User::class, Supplier::class];
private const array NOTIFIABLE_ITEMTYPES = [User::class, Supplier::class];

#[Override]
public function getLabel(): string
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Destination/ActorNotificationFieldConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
#[HasFieldWithQuestionId(self::DISABLED_QUESTION_IDS, is_array: true, list_of_strategies_field: self::ROLES)]
final class ActorNotificationFieldConfig implements JsonFieldInterface
{
public const ROLES = 'roles';
public const string ROLES = 'roles';

public const DISABLED_STRATEGIES = 'disabled_strategies';
public const string DISABLED_STRATEGIES = 'disabled_strategies';

public const DISABLED_ACTORS = 'disabled_actors';
public const string DISABLED_ACTORS = 'disabled_actors';

public const DISABLED_QUESTION_IDS = 'disabled_question_ids';
public const string DISABLED_QUESTION_IDS = 'disabled_question_ids';

/** @var array<string, ITILActorFieldConfig> */
private array $actors_configs = [];
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Destination/PreReservationFieldConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
#[HasFieldWithQuestionId(self::SPECIFIC_QUESTION_ID)]
final readonly class PreReservationFieldConfig implements JsonFieldInterface, ConfigFieldWithStrategiesInterface
{
public const STRATEGY = 'strategy';
public const string STRATEGY = 'strategy';

public const SPECIFIC_QUESTION_ID = 'specific_question_id';
public const string SPECIFIC_QUESTION_ID = 'specific_question_id';

public const REQUIRE_APPROVAL = 'require_approval';
public const string REQUIRE_APPROVAL = 'require_approval';

public function __construct(
private PreReservationFieldStrategy $strategy,
Expand Down
6 changes: 3 additions & 3 deletions src/Model/QuestionType/GlpiScopeQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ final class GlpiScopeQuestion extends AbstractQuestionType implements
ConfigurableItemInterface,
QuestionTypeValidationInterface
{
public const CORE_VALUE = 'GLPI';
public const string CORE_VALUE = 'GLPI';

private const MAX_VALUES = 50;
private const int MAX_VALUES = 50;

private const MAX_VALUE_LENGTH = 255;
private const int MAX_VALUE_LENGTH = 255;

#[Override]
public function getCategory(): QuestionTypeCategoryInterface
Expand Down
6 changes: 3 additions & 3 deletions src/Model/QuestionType/LdapQuestionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
final readonly class LdapQuestionConfig implements JsonFieldInterface
{
// Unique reference to hardcoded name used for serialization
public const AUTHLDAP_ID = "authldap_id";
public const string AUTHLDAP_ID = "authldap_id";

public const LDAP_FILTER = "ldap_filter";
public const string LDAP_FILTER = "ldap_filter";

public const LDAP_ATTRIBUTE_ID = "ldap_attribute_id";
public const string LDAP_ATTRIBUTE_ID = "ldap_attribute_id";

public function __construct(
private int $authldap_id = 0,
Expand Down
3 changes: 2 additions & 1 deletion src/Model/QuestionType/ReservationQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace GlpiPlugin\Advancedforms\Model\QuestionType;

use Session;
use Glpi\Application\View\TemplateRenderer;
use Glpi\DBAL\JsonFieldInterface;
use Glpi\Form\Destination\CommonITILField\Category;
Expand Down Expand Up @@ -161,7 +162,7 @@ public function renderEndUserTemplate(Question $question): string
'allowed_itemtypes' => $config->getAllowedItemtypes(),
'show_calendar' => $config->isCalendarEnabled(),
// Server/session time: the calendar runs in UTC mode, like core planning.
'now' => $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s'),
'now' => Session::getCurrentTime() ?? date('Y-m-d H:i:s'),
]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Model/QuestionType/ReservationQuestionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
final readonly class ReservationQuestionConfig implements JsonFieldInterface
{
// Unique reference to hardcoded name used for serialization
public const ALLOWED_ITEMTYPES = 'allowed_itemtypes';
public const string ALLOWED_ITEMTYPES = 'allowed_itemtypes';

public const SHOW_CALENDAR = 'show_calendar';
public const string SHOW_CALENDAR = 'show_calendar';

/** @param array<string> $allowed_itemtypes */
public function __construct(
Expand Down
12 changes: 6 additions & 6 deletions src/Model/QuestionType/TableQuestionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@

final readonly class TableQuestionConfig implements JsonFieldInterface
{
public const COLUMNS = 'columns';
public const string COLUMNS = 'columns';

// Column sub-keys
public const COL_NAME = 'name';
public const string COL_NAME = 'name';

public const COL_QUESTION_TYPE = 'question_type';
public const string COL_QUESTION_TYPE = 'question_type';

public const COL_REQUIRED = 'required';
public const string COL_REQUIRED = 'required';

public const COL_ITEMTYPE = 'itemtype';
public const string COL_ITEMTYPE = 'itemtype';

public const COL_PATTERN = 'pattern';
public const string COL_PATTERN = 'pattern';

/**
* @param array<array{name: string, question_type: string, required: bool, itemtype: string, pattern: string}> $columns
Expand Down
22 changes: 12 additions & 10 deletions src/Model/QuestionType/TreeCascadeDropdownQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
use DBmysql;
use CommonTreeDropdown;
use DropdownTranslation;
use Glpi\DBAL\QueryExpression;
use Glpi\DBAL\QueryFunction;
use Glpi\DBAL\QueryIdentifier;
use Glpi\DBAL\QueryValue;
use Glpi\Application\View\TemplateRenderer;
use Glpi\DBAL\JsonFieldInterface;
use Glpi\Form\Condition\ConditionHandler\ItemAsTextConditionHandler;
Expand Down Expand Up @@ -443,7 +445,6 @@ private function getValidItemsForLevel(string $itemtype, array $base_where, arra
public static function getTranslatedItemsCriteria(string $itemtype, array $where): array
{
$table = $itemtype::getTable();
$name_field = DBmysql::quoteName($table . '.name');

$criteria = [
'SELECT' => [$table . '.id', $table . '.name'],
Expand All @@ -456,14 +457,15 @@ public static function getTranslatedItemsCriteria(string $itemtype, array $where
return $criteria;
}

$translated_name = sprintf(
"COALESCE(NULLIF(%s, ''), %s)",
DBmysql::quoteName('namet.value'),
$name_field,
);
$criteria['SELECT'] = [
$table . '.id',
new QueryExpression($translated_name . ' AS ' . DBmysql::quoteName('name')),
QueryFunction::coalesce(
[
QueryFunction::nullif(new QueryIdentifier('namet.value'), new QueryValue('')),
new QueryIdentifier($table . '.name'),
],
'name',
),
];
$criteria['LEFT JOIN'] = [
'glpi_dropdowntranslations AS namet' => [
Expand All @@ -473,14 +475,14 @@ public static function getTranslatedItemsCriteria(string $itemtype, array $where
[
'AND' => [
'namet.itemtype' => $itemtype,
'namet.language' => $_SESSION['glpilanguage'],
'namet.language' => Session::getLanguage(),
'namet.field' => 'name',
],
],
],
],
];
$criteria['ORDER'] = [new QueryExpression($translated_name . ' ASC')];
$criteria['ORDER'] = ['name ASC'];

return $criteria;
}
Expand Down
Loading
Loading