Skip to content

Commit

Permalink
feat: adapt to new GLPI's autoload
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Dec 13, 2021
1 parent c6aefe1 commit 894df7c
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion inc/abstractquestionparameter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ abstract class PluginFormcreatorAbstractQuestionParameter
* - fieldName: name of the HTML input tag
* - label : label for the parameter
*/
public function __construct(PluginFormcreatorFieldInterface $field, array $options) {
public function setField(PluginFormcreatorFieldInterface $field, array $options) {
$fieldType = $field->getFieldTypeName();
$fieldName = $options['fieldName'];
$this->domId = $this->domId . "_{$fieldType}_{$fieldName}";
Expand Down
15 changes: 7 additions & 8 deletions inc/field/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,14 @@ public static function canRequire(): bool {
}

public function getEmptyParameters(): array {
$range = new PluginFormcreatorQuestionRange();
$range->setField($this, [
'fieldName' => 'range',
'label' => __('Range', 'formcreator'),
'fieldType' => ['text'],
]);
return [
'range' => new PluginFormcreatorQuestionRange(
$this,
[
'fieldName' => 'range',
'label' => __('Range', 'formcreator'),
'fieldType' => ['text'],
]
),
'range' => $range,
];
}

Expand Down
30 changes: 14 additions & 16 deletions inc/field/floatfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,21 @@ public function getEmptyParameters(): array {
$regexDoc .= '<a href="http://php.net/manual/reference.pcre.pattern.syntax.php" target="_blank">';
$regexDoc .= '(' . __('Regular expression', 'formcreator') . ')';
$regexDoc .= '</small>';
$range = new PluginFormcreatorQuestionRange();
$range->setField($this, [
'fieldName' => 'range',
'label' => __('Range', 'formcreator'),
'fieldType' => ['text'],
]);
$regex = new PluginFormcreatorQuestionRegex();
$regex->setField($this, [
'fieldName' => 'regex',
'label' => __('Additional validation', 'formcreator') . $regexDoc,
'fieldType' => ['text'],
]);
return [
'regex' => new PluginFormcreatorQuestionRegex(
$this,
[
'fieldName' => 'regex',
'label' => __('Additional validation', 'formcreator') . $regexDoc,
'fieldType' => ['text'],
]
),
'range' => new PluginFormcreatorQuestionRange(
$this,
[
'fieldName' => 'range',
'label' => __('Range', 'formcreator'),
'fieldType' => ['text'],
]
),
'regex' => $regex,
'range' => $range,
];
}

Expand Down
30 changes: 14 additions & 16 deletions inc/field/textfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,21 @@ public function getEmptyParameters(): array {
$regexDoc .= '<a href="http://php.net/manual/reference.pcre.pattern.syntax.php" target="_blank">';
$regexDoc .= '(' . __('Regular expression', 'formcreator') . ')';
$regexDoc .= '</small>';
$range = new PluginFormcreatorQuestionRange();
$range->setField($this, [
'fieldName' => 'range',
'label' => __('Range', 'formcreator'),
'fieldType' => ['text'],
]);
$regex = new PluginFormcreatorQuestionRegex();
$regex->setField($this, [
'fieldName' => 'regex',
'label' => __('Additional validation', 'formcreator') . $regexDoc,
'fieldType' => ['text'],
]);
return [
'regex' => new PluginFormcreatorQuestionRegex(
$this,
[
'fieldName' => 'regex',
'label' => __('Additional validation', 'formcreator') . $regexDoc,
'fieldType' => ['text'],
]
),
'range' => new PluginFormcreatorQuestionRange(
$this,
[
'fieldName' => 'range',
'label' => __('Range', 'formcreator'),
'fieldType' => ['text'],
]
),
'regex' => $regex,
'range' => $range,
];
}

Expand Down
8 changes: 4 additions & 4 deletions inc/form_validator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function showForForm(PluginFormcreatorForm $item, $options = []) {
],
];
$usersCondition = [
"$userTable.id" => new QuerySubquery($subQuery)
"$userTable.id" => new QuerySubQuery($subQuery)
];
$formValidator = new PluginFormcreatorForm_Validator();
$selectedValidatorUsers = [];
Expand Down Expand Up @@ -253,7 +253,7 @@ public function showForForm(PluginFormcreatorForm $item, $options = []) {
],
];
$groupsCondition = [
"$groupTable.id" => new QuerySubquery($subQuery),
"$groupTable.id" => new QuerySubQuery($subQuery),
];
$groups = $DB->request([
'SELECT' => ['id' ,'name'],
Expand Down Expand Up @@ -541,7 +541,7 @@ public static function dropdownValidatorUser(): string {
$profileFk = Profile::getForeignKeyField();
$profileRightTable = ProfileRight::getTable();
$usersCondition = [
"$userTable.id" => new QuerySubquery([
"$userTable.id" => new QuerySubQuery([
'SELECT' => "$profileUserTable.$userFk",
'FROM' => $profileUserTable,
'INNER JOIN' => [
Expand Down Expand Up @@ -606,7 +606,7 @@ public static function dropdownValidatorGroup(): string {
$profileRightTable = ProfileRight::getTable();
$groupUserTable = Group_User::getTable();
$groupsCondition = [
"$groupTable.id" => new QuerySubquery([
"$groupTable.id" => new QuerySubQuery([
'SELECT' => "$groupUserTable.$groupFk",
'FROM' => $groupUserTable,
'INNER JOIN' => [
Expand Down
10 changes: 5 additions & 5 deletions inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ public static function getSyncIssuesRequest() : AbstractQuery {
],
],
[
'TABLE' => new QuerySubquery([
'TABLE' => new QuerySubQuery([
'SELECT' => '*',
'FROM' => new QuerySubquery([
'FROM' => new QuerySubQuery([
'SELECT' => ['users_id', $ticketFk],
'DISTINCT' => true,
'FROM' => $ticketUserTable,
Expand Down Expand Up @@ -222,9 +222,9 @@ public static function getSyncIssuesRequest() : AbstractQuery {

// Union of the 3 previous queries
$union = new QueryUnion([
new QuerySubquery($query1),
new QuerySubquery($query2),
new QuerySubquery($query3)
new QuerySubQuery($query1),
new QuerySubQuery($query2),
new QuerySubQuery($query3)
], true);

return $union;
Expand Down
7 changes: 3 additions & 4 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,8 @@ public function prepareInputForAdd($input) {
// handle description field and its inline pictures
if (isset($input['_description'])) {
foreach ($input['_description'] as $id => $filename) {
// TODO :replace PluginFormcreatorCommon::getDuplicateOf by Document::getDuplicateOf
// when is merged https://github.com/glpi-project/glpi/pull/9335
if ($document = PluginFormcreatorCommon::getDuplicateOf(Session::getActiveEntity(), GLPI_TMP_DIR . '/' . $filename)) {
$document = new Document();
if ($document->getDuplicateOf(Session::getActiveEntity(), GLPI_TMP_DIR . '/' . $filename)) {
$this->value = str_replace('id="' . $input['_tag_description'] . '"', $document->fields['tag'], $this->value);
$input['_tag_description'][$id] = $document->fields['tag'];
}
Expand Down Expand Up @@ -720,7 +719,7 @@ public function post_purgeItem() {
'show_rule' => PluginFormcreatorCondition::SHOW_RULE_ALWAYS
],
[
'id' => new QuerySubquery([
'id' => new QuerySubQuery([
'SELECT' => self::getForeignKeyField(),
'FROM' => $condition_table,
'WHERE' => ['plugin_formcreator_questions_id' => $questionId]
Expand Down
4 changes: 2 additions & 2 deletions inc/questiondependency.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class PluginFormcreatorQuestionDependency
* - label : label for the parameter
* - fieldType: array of field types the dependency should filter
*/
public function __construct(PluginFormcreatorFieldInterface $field, array $options) {
parent::__construct($field, $options);
public function setField(PluginFormcreatorFieldInterface $field, array $options) {
parent::setField($field, $options);
$this->fieldtype = isset($options['fieldType']) ? $options['fieldType'] : [];
}

Expand Down
9 changes: 9 additions & 0 deletions inc/questionparameterinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
}

interface PluginFormcreatorQuestionParameterInterface {
/**
* set field and options related to this question parameter
*
* @param PluginFormcreatorFieldInterface $field
* @param array $options
* @return void
*/
public function setField(PluginFormcreatorFieldInterface $field, array $options);

/**
* Gets the HTML form part for the parameters
* @param PluginFormcreatorForm $form a form used as context when displaying parameters
Expand Down
31 changes: 15 additions & 16 deletions tests/fixture/PluginFormcreatorDependentField.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,22 @@ public static function canRequire(): bool {
}

public function getEmptyParameters(): array {
$firstname = new PluginFormcreatorQuestionDependency();
$firstname->setField($this, [
'fieldName' => 'firstname',
'label' => __('First name field', 'formcreator'),
'fieldType' => ['text'],
]);
$lastname = new PluginFormcreatorQuestionDependency();
$lastname->setField($this, [
'fieldName' => 'lastname',
'label' => __('Last name field', 'formcreator'),
'fieldType' => ['text'],
]);

return [
'firstname' => new PluginFormcreatorQuestionDependency(
$this,
[
'fieldName' => 'firstname',
'label' => __('First name field', 'formcreator'),
'fieldType' => ['text'],
]
),
'lastname' => new PluginFormcreatorQuestionDependency(
$this,
[
'fieldName' => 'lastname',
'label' => __('Last name field', 'formcreator'),
'fieldType' => ['text'],
]
),
'firstname' => $firstname,
'lastname' => $lastname,
];
}

Expand Down
2 changes: 0 additions & 2 deletions tests/src/CommonTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ protected function setupGLPIFramework() {

$DB = new DB();

include_once (GLPI_ROOT . "/inc/timer.class.php");

// Security of PHP_SELF
$_SERVER['PHP_SELF'] = Html::cleanParametersURL($_SERVER['PHP_SELF']);

Expand Down

0 comments on commit 894df7c

Please sign in to comment.