Skip to content

Commit

Permalink
Merge branch 'release/2.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Feb 12, 2018
2 parents 0072d44 + 0e83d60 commit 59c931c
Show file tree
Hide file tree
Showing 51 changed files with 702 additions and 366 deletions.
34 changes: 19 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,36 @@ env:
global:
- GLPI_SOURCE="https://github.com/glpi-project/glpi -b 9.2/bugfixes"
- PHPUNIT_ARGS="--verbose --debug"
- CS=7.2
matrix:
- GLPI_BRANCH=9.2.1
- GLPI_BRANCH=9.2/bugfixes
- GLPI_BRANCH=master

php:
- 5.6
- 7.0
- 7.1
- 7.2
- nightly

allow_failures:
- php: nightly

before_script:
- mysql -u root -e 'create database glpitest;'
- git clone https://github.com/glpi-project/glpi --depth 1 -b 9.2/bugfixes ../glpi && cd ../glpi
- git clone --depth=1 $GLPI_SOURCE -b $GLPI_BRANCH ../glpi && cd ../glpi
- mv ../formcreator plugins/formcreator
- composer install --no-dev
- php tools/cliinstall.php --db=glpitest --user=root --tests
- if [ -e scripts/cliinstall.php ] ; then php scripts/cliinstall.php --db=glpitest --user=root --tests ; fi
- if [ -e tools/cliinstall.php ] ; then php tools/cliinstall.php --db=glpitest --user=root --tests ; fi
- cd plugins/formcreator
- rm composer.lock
- composer install

script:
- vendor/bin/phpunit $PHPUNIT_ARGS
- if [[ "$CS" == "true" ]]; then vendor/bin/robo --no-interaction code:cs; fi

matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
env: CS=true
- php: nightly

allow_failures:
- php: nightly
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "$CS" ]] ; then vendor/bin/robo --no-interaction code:cs; fi

cache:
directories:
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
<a name="2.6.2"></a>
## [2.6.2](https://github.com-btry/pluginsGLPI/formcreator/compare/2.6.1...2.6.2) (2018-02-12)


### Bug Fixes

* **condition:** fix multiple condition process when a question is unanswered ([6bce6e7](https://github.com-btry/pluginsGLPI/formcreator/commit/6bce6e7))
* **condition:** questions conditions may lead to wring result in complex cases ([42cb852](https://github.com-btry/pluginsGLPI/formcreator/commit/42cb852)), closes [#880](https://github.com-btry/pluginsGLPI/formcreator/issues/880)
* **field:** fix quote escaping for file field ([0280acf](https://github.com-btry/pluginsGLPI/formcreator/commit/0280acf)), closes [#832](https://github.com-btry/pluginsGLPI/formcreator/issues/832)
* **field:** inability to save properties of a tag question ([faf304b](https://github.com-btry/pluginsGLPI/formcreator/commit/faf304b))
* **form_answer:** fix search option ([1c8f38f](https://github.com-btry/pluginsGLPI/formcreator/commit/1c8f38f)), closes [#602](https://github.com-btry/pluginsGLPI/formcreator/issues/602)
* **notification:** pending validation email for groups ([54c2a2e](https://github.com-btry/pluginsGLPI/formcreator/commit/54c2a2e)), closes [#871](https://github.com-btry/pluginsGLPI/formcreator/issues/871)
* **question:** fields hidden under condition not rendered in tickets ([9d87dd7](https://github.com-btry/pluginsGLPI/formcreator/commit/9d87dd7)), closes [#880](https://github.com-btry/pluginsGLPI/formcreator/issues/880)
* **target:** answer rendering issues ([6d73872](https://github.com-btry/pluginsGLPI/formcreator/commit/6d73872)), closes [#877](https://github.com-btry/pluginsGLPI/formcreator/issues/877) [#817](https://github.com-btry/pluginsGLPI/formcreator/issues/817)
* **target:** remove abusive encoding in target names ([a0dca23](https://github.com-btry/pluginsGLPI/formcreator/commit/a0dca23))



<a name="2.6.1"></a>
## [2.6.1](https://github.com-btry/pluginsGLPI/formcreator/compare/2.6.0...2.6.1) (2018-01-02)

Expand Down
4 changes: 2 additions & 2 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function archiveBuild() {

$this->updateChangelog();

$this->gitCommit(['package.json', 'composer.json'], "docs: bump version in JSON files");
$this->gitCommit(['CHANGELOG.md'], "docs(changelog): update changelog");
$this->gitCommit(['package.json', 'composer.json'], "build: bump version in JSON files");
$this->gitCommit(['CHANGELOG.md'], "build(changelog): update changelog");

$pluginName = $this->getPluginName();
$pluginPath = $this->getProjectPath();
Expand Down
1 change: 0 additions & 1 deletion ajax/showfields.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
$visibility = PluginFormcreatorFields::updateVisibility($currentValues);
echo json_encode($visibility);
exit();

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"glpi-project/tools": "^0.1.0",
"glpi-project/coding-standard": "0.5.0"
},
"version": "2.6.1"
"version": "2.6.2"
}
3 changes: 2 additions & 1 deletion inc/category.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ public function getAdditionalFields() {

/**
* @param integer $rootId id of the subtree root
* @param boolean $helpdeskHome
* @return array Tree of form categories as nested array
*/
public static function getCategoryTree($rootId = 0, $helpdeskHome = false) {
$cat_table = getTableForItemType('PluginFormcreatorCategory');
$form_table = getTableForItemType('PluginFormcreatorForm');
$table_fp = getTableForItemType('PluginFormcreatorForm_Profile');
if ($helpdeskHome) {
$helpdesk ="AND $form_table.`helpdesk_home` = 1";
$helpdesk = "AND $form_table.`helpdesk_home` = 1";
} else {
$helpdesk = '';
}
Expand Down
16 changes: 16 additions & 0 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,20 @@ public static function getFormcreatorRequestTypeId() {

return $requesttypes_id;
}

/**
* Get the maximum value of a column for a given itemtype
* @param CommonDBTM $item
* @param string $condition
* @param string $fieldName
* @return NULL|integer
*/
public static function getMax(CommonDBTM $item, $condition, $fieldName) {
$rows = $item->find($condition, "`$fieldName` DESC", '1');
$line = array_pop($rows);
if ($line === null) {
return null;
}
return (int) $line[$fieldName];
}
}
20 changes: 18 additions & 2 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ abstract class PluginFormcreatorField implements PluginFormcreatorFieldInterface

protected $fields = [];

/**
* @param unknown $fields
* @param array $data
*/
public function __construct($fields, $data = []) {
$this->fields = $fields;
$this->fields['answer'] = $data;
Expand All @@ -25,9 +29,22 @@ public function __construct($fields, $data = []) {
* @return array input data to save as is
*/
public function prepareQuestionInputForSave($input) {
return $input;
return $input;
}

/**
* Prepares a answer value for output in a target object
* @param string|array $input the answer to format for a target (ticket or change)
* @return string
*/
public function prepareQuestionInputForTarget($input) {
return Toolbox::addslashes_deep($input);
}

/**
* Output HTML to display the field
* @param boolean $canEdit is the field editable ?
*/
public function show($canEdit = true) {
$required = ($canEdit && $this->fields['required']) ? ' required' : '';

Expand Down Expand Up @@ -62,7 +79,6 @@ public function show($canEdit = true) {

/**
* Outputs the HTML representing the field
*
* @param string $canEdit
*/
public function displayField($canEdit = true) {
Expand Down
4 changes: 2 additions & 2 deletions inc/fieldinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
die("Sorry. You can't access this file directly");
}

interface PluginFormcreatorFieldInterface
{
interface PluginFormcreatorFieldInterface {
public static function getName();
public static function getPrefs();
public static function getJSFields();
public function prepareQuestionInputForSave($input);
public function prepareQuestionInputForTarget($input);
}
35 changes: 2 additions & 33 deletions inc/fields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class PluginFormcreatorFields
{
/**
* Retrive all field types and file path
*
* @return Array field_type => File_path
*/
public static function getTypes() {
Expand All @@ -29,7 +28,6 @@ public static function getTypes() {

/**
* Get type and name of all field types
*
* @return Array field_type => Name
*/
public static function getNames() {
Expand All @@ -43,7 +41,7 @@ public static function getNames() {

// Get localized names of field types
foreach (array_keys($tab_field_types) as $field_type) {
$classname = 'PluginFormcreator' . ucfirst($field_type) . 'Field';
$classname = 'PluginFormcreator' . ucfirst($field_type) . 'Field';

if ($classname == 'tagField' &&(!$plugin->isInstalled('tag') || !$plugin->isActivated('tag'))) {
continue;
Expand All @@ -57,29 +55,6 @@ public static function getNames() {
return $tab_field_types_name;
}

/**
* Get field value to display
*
* @param String $field Field object to display
* @param String $value the value to display
*
* @return String
*/
public static function getValue($field, $value) {
$class_file = dirname(__FILE__).'/fields/'.$field['fieldtype'].'field.class.php';
if (is_file($class_file)) {
include_once ($class_file);

$classname = 'PluginFormcreator'.ucfirst($field['fieldtype']).'Field';
if (class_exists($classname)) {
$obj = new $classname($field, $value);
return $obj->getAnswer();
}
}
return $value;
}


public static function printAllTabFieldsForJS() {
$tabFieldsForJS = '';
// Get field types and file path
Expand All @@ -97,7 +72,6 @@ public static function printAllTabFieldsForJS() {
}

/**
*
* @param unknown $field
* @param unknown $data
* @param string $edit
Expand Down Expand Up @@ -181,12 +155,7 @@ public static function isVisible($id, $values) {
$nextLogic = 'OR';
}
if (!isset($values[$condition['field']])) {
unset($evalQuestion[$id]);
return false;
}
if (!self::isVisible($condition['field'], $values)) {
unset($evalQuestion[$id]);
return false;
$values[$condition['field']] = '';
}

switch ($condition['operator']) {
Expand Down
43 changes: 43 additions & 0 deletions inc/fields/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ public static function getName() {
return __('Checkboxes', 'formcreator');
}

public function getValue() {
if (isset($this->fields['answer'])) {
if (!is_array($this->fields['answer']) && is_array(json_decode($this->fields['answer']))) {
return json_decode($this->fields['answer']);
}
return $this->fields['answer'];
} else {
return explode("\r\n", $this->fields['default_values']);
}
}

public function prepareQuestionInputForSave($input) {
if (isset($input['values'])) {
if (empty($input['values'])) {
Expand All @@ -117,6 +128,38 @@ public function prepareQuestionInputForSave($input) {
return $input;
}

public function prepareQuestionInputForTarget($input) {
global $CFG_GLPI;

$value = [];
$values = $this->getAvailableValues();

if (empty($input)) {
return '';
}

if (is_array($input)) {
$tab_values = $input;
} else if (is_array(json_decode($input))) {
$tab_values = json_decode($input);
} else {
$tab_values = [$input];
}

foreach ($tab_values as $input) {
if (in_array($input, $values)) {
$value[] = addslashes($input);
}
}

if ($CFG_GLPI['use_rich_text']) {
$value = '<br />' . implode('<br />', $value);
} else {
$value = '\r\n' . implode('\r\n', $value);
}
return $value;
}

public static function getPrefs() {
return [
'required' => 1,
Expand Down
23 changes: 20 additions & 3 deletions inc/fields/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,35 @@ public function displayField($canEdit = true) {

public function getAnswer() {
$value = $this->getValue();
$DbUtil = new DbUtils();
if ($this->fields['values'] == 'User') {
return getUserName($value);
return $DbUtil->getUserName($value);
} else {
$decodedValues = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY);
if (!isset($decodedValues['itemtype'])) {
return Dropdown::getDropdownName(getTableForItemType($this->fields['values']), $value);
return Dropdown::getDropdownName($DbUtil->getTableForItemType($this->fields['values']), $value);
} else {
return Dropdown::getDropdownName(getTableForItemType($decodedValues['itemtype']), $value);
return Dropdown::getDropdownName($DbUtil->getTableForItemType($decodedValues['itemtype']), $value);
}
}
}

public function prepareQuestionInputForTarget($input) {
$DbUtil = new DbUtils();
if ($this->fields['values'] == User::class) {
$value = $DbUtil->getUserName($input);
} else {
$decodedValues = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY);
if (!isset($decodedValues['itemtype'])) {
$value = Dropdown::getDropdownName($DbUtil->getTableForItemType($this->fields['values']), $input);
} else {
$value = Dropdown::getDropdownName($DbUtil->getTableForItemType($decodedValues['itemtype']), $input);
}
}

return addslashes($value);
}

public static function getName() {
return _n('Dropdown', 'Dropdowns', 1);
}
Expand Down
5 changes: 5 additions & 0 deletions inc/fields/hiddenfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public static function getName() {
return _n('Hidden field', 'Hidden fields', 1);
}

public function prepareQuestionInputForTarget($input) {
$input = str_replace("\n", '\r\n', addslashes($input));
return $input;
}

public static function getPrefs() {
return [
'required' => 0,
Expand Down
Loading

0 comments on commit 59c931c

Please sign in to comment.