Skip to content

Commit 6ee02b8

Browse files
authored
Merge pull request #86 from RealDekkia/master
Add new item field Date Interval
2 parents f1fcc12 + 52d1fb5 commit 6ee02b8

File tree

10 files changed

+199
-94
lines changed

10 files changed

+199
-94
lines changed

classes/items.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,9 @@ public function getProperty($fieldNameIntern, $column, $format = '')
145145
}
146146

147147
$value = $this->mItemFields[$fieldNameIntern]->getValue($column, $format);
148-
149-
if ($column === 'imf_value_list' && in_array($this->mItemFields[$fieldNameIntern]->getValue('imf_type'), ['DROPDOWN', 'RADIO_BUTTON'])) {
148+
if ($column === 'imf_value_list' && in_array($this->mItemFields[$fieldNameIntern]->getValue('imf_type'), ['DROPDOWN', 'RADIO_BUTTON', 'DATE_INTERVAL'])) {
150149
$value = $this->getListValue($fieldNameIntern, $value, $format);
151150
}
152-
153151
return $value;
154152
}
155153

@@ -291,12 +289,24 @@ public function getHtmlValue($fieldNameIntern, $value): string
291289

292290
case 'DROPDOWN':
293291
case 'RADIO_BUTTON':
292+
case 'DATE_INTERVAL':
294293
$arrListValuesWithItems = array(); // array with list values and items that represents the internal value
295294

296295
// first replace windows new line with unix new line and then create an array
297296
$valueFormatted = str_replace("\r\n", "\n", $this->mItemFields[$fieldNameIntern]->getValue('imf_value_list', 'database'));
298297
$arrListValues = explode("\n", $valueFormatted);
299298

299+
//Clean up control-chars from maintenance scheudule
300+
if($imfType == 'DATE_INTERVAL'){
301+
$cleanArrListValues = array();
302+
foreach ($arrListValues as $line) {
303+
if(substr($line,0,1) != '#'){
304+
array_push($cleanArrListValues, explode('|', $line)[0]);
305+
}
306+
}
307+
$arrListValues = $cleanArrListValues;
308+
}
309+
300310
foreach ($arrListValues as $index => $listValue) {
301311
// if value is imagefile or imageurl then show image
302312
if ($imfType === 'RADIO_BUTTON' && (Image::isFontAwesomeIcon($listValue)

fields/fields.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ function moveCategory(direction, imfID) {
151151
'TEXT' => $gL10n->get('SYS_TEXT') . ' (100)',
152152
'TEXT_BIG' => $gL10n->get('SYS_TEXT') . ' (4000)',
153153
'NUMBER' => $gL10n->get('SYS_NUMBER'),
154-
'DECIMAL' => $gL10n->get('SYS_DECIMAL_NUMBER')
154+
'DECIMAL' => $gL10n->get('SYS_DECIMAL_NUMBER'),
155+
'DATE_INTERVAL' => $gL10n->get('PLG_INVENTORY_MANAGER_DATE_INTERVAL')
155156
);
156157

157158
$imfSystem = $itemField->getValue('imf_system') == 1

fields/fields_delete.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function setValueList() {
6868
'RADIO_BUTTON' => $gL10n->get('SYS_RADIO_BUTTON'),
6969
'TEXT' => $gL10n->get('SYS_TEXT') . ' (100 ' . $gL10n->get('SYS_CHARACTERS') . ')',
7070
'TEXT_BIG' => $gL10n->get('SYS_TEXT') . ' (4000 ' . $gL10n->get('SYS_CHARACTERS') . ')',
71+
'DATE_INTERVAL' => $gL10n->get('PLG_INVENTORY_MANAGER_DATE_INTERVAL')
7172
);
7273
asort($itemFieldText);
7374

fields/fields_edit_new.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,25 @@
6767

6868
$page->addJavascript('
6969
function setValueList() {
70-
if ($("#imf_type").val() === "DROPDOWN" || $("#imf_type").val() === "RADIO_BUTTON") {
70+
if ($("#imf_type").val() === "DROPDOWN" || $("#imf_type").val() === "RADIO_BUTTON" || $("#imf_type").val() === "DATE_INTERVAL") {
7171
$("#imf_value_list_group").show("slow");
7272
$("#imf_value_list").attr("required", "required");
73+
if ($("#imf_type").val() === "DATE_INTERVAL") {
74+
$("#imf_date_interval_field_group").show("slow");
75+
$("#imf_date_interval_field").attr("required", "required");
76+
}
7377
} else {
7478
$("#imf_value_list").removeAttr("required");
7579
$("#imf_value_list_group").hide();
80+
$("#imf_date_interval_field").removeAttr("required");
81+
$("#imf_date_interval_field_group").hide();
82+
}
83+
84+
var valueListTooltipContainer = document.getElementById("imf_value_list_group").getElementsByTagName("label")[0].getElementsByTagName("i")[0];
85+
if($("#imf_type").val() === "DATE_INTERVAL"){
86+
valueListTooltipContainer.setAttribute("data-content","' . $gL10n->get('PLG_INVENTORY_MANAGER_DATE_INTERVAL_DESC') . '");
87+
}else{
88+
valueListTooltipContainer.setAttribute("data-content","' . $gL10n->get('ORG_VALUE_LIST_DESC') . '");
7689
}
7790
}
7891
@@ -108,7 +121,7 @@ function setValueList() {
108121
'RADIO_BUTTON' => $gL10n->get('SYS_RADIO_BUTTON'),
109122
'TEXT' => $gL10n->get('SYS_TEXT') . ' (100 ' . $gL10n->get('SYS_CHARACTERS') . ')',
110123
'TEXT_BIG' => $gL10n->get('SYS_TEXT') . ' (4000 ' . $gL10n->get('SYS_CHARACTERS') . ')',
111-
);
124+
'DATE_INTERVAL' => $gL10n->get('PLG_INVENTORY_MANAGER_DATE_INTERVAL'));
112125
asort($itemFieldText);
113126

114127
//bei Systemfeldern darf der Datentyp nicht mehr veraendert werden
@@ -118,6 +131,14 @@ function setValueList() {
118131
)
119132
);
120133

134+
$sql = "SELECT imf_id, imf_name FROM " . TBL_INVENTORY_MANAGER_FIELDS . " WHERE imf_type = 'DATE'";
135+
$form->addSelectBoxFromSql('imf_date_interval_field', $gL10n->get('PLG_INVENTORY_MANAGER_DATE_INTERVAL_FIELD'), $gDb, $sql, array(
136+
'property' => HtmlForm::FIELD_REQUIRED,
137+
'defaultValue' => $itemField->getValue('imf_date_interval_field'),
138+
'helpTextIdLabel' => 'PLG_INVENTORY_MANAGER_DATE_INTERVAL_FIELD_DESC'
139+
)
140+
);
141+
121142
$form->addMultilineTextInput('imf_value_list', $gL10n->get('ORG_VALUE_LIST'), (string)$itemField->getValue('imf_value_list', 'database'), 6, array(
122143
'property' => HtmlForm::FIELD_REQUIRED,
123144
'helpTextIdLabel' => 'ORG_VALUE_LIST_DESC'

inventory_manager.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,12 @@
470470
$imfNameIntern = $itemField->getValue('imf_name_intern');
471471
$columnHeader = convlanguagePIM($items->getProperty($imfNameIntern, 'imf_name'));
472472

473-
if ($disableBorrowing == 1 && ($imfNameIntern === 'LAST_RECEIVER' || $imfNameIntern === 'RECEIVED_ON' || $imfNameIntern === 'RECEIVED_BACK_ON')) {
473+
if($items->getProperty($imfNameIntern, 'imf_type') === 'DATE_INTERVAL'){
474+
// modify column Header for DATE_INTERVAL fields
475+
$columnHeader .= ' ' . $gL10n->get('PLG_INVENTORY_MANAGER_DATE_INTERVAL_DAYS_REMAINING');
476+
}
477+
478+
if ($disableBorrowing == 1 && ($imfNameIntern === 'LAST_RECEIVER' || $imfNameIntern === 'RECEIVED_ON' || $imfNameIntern === 'RECEIVED_BACK_ON')) {
474479
break;
475480
}
476481

@@ -629,6 +634,52 @@
629634
elseif (in_array($items->getProperty($imfNameIntern, 'imf_type'), array('DROPDOWN', 'RADIO_BUTTON'))) {
630635
$content = $items->getHtmlValue($imfNameIntern, $content);
631636
}
637+
elseif ($items->getProperty($imfNameIntern, 'imf_type') == 'DATE_INTERVAL') {
638+
$selectedInterval = $content;
639+
$content = '';
640+
641+
$intervalValues = $items->getProperty($imfNameIntern, 'imf_value_list');
642+
$dateIntervalFieldId = $items->getProperty($imfNameIntern, 'imf_date_interval_field', 'database');
643+
if (isset($items->mItemData[$dateIntervalFieldId])) {
644+
$dateInternalFieldName = $items->mItemData[$dateIntervalFieldId]->getValue('imf_name_intern');
645+
$filteredSelectionItems = array();
646+
647+
foreach ($intervalValues as $value) {
648+
$filteredSelectionItems[] = trim(explode('|', $value)[1]);
649+
}
650+
//use part after # as internal_name for last test date
651+
$compDate1 = date_create($items->getValue($dateInternalFieldName, 'database'));
652+
$compDate2 = date_create();
653+
654+
//Calculate future test date
655+
$dateAdditionSplit = array();
656+
if (isset($filteredSelectionItems[$selectedInterval-1])) {
657+
preg_match("/^\s*(\d*)([wymd])\s*$/", $filteredSelectionItems[$selectedInterval-1], $dateAdditionSplit);
658+
}
659+
660+
if(isset($dateAdditionSplit[1]) && isset($dateAdditionSplit[2]) && is_numeric($dateAdditionSplit[1])){
661+
switch ($dateAdditionSplit[2]) {
662+
case 'w':
663+
date_add($compDate1, new DateInterval('P' . $dateAdditionSplit[1] . 'W'));
664+
break;
665+
case 'm':
666+
date_add($compDate1, new DateInterval('P' . $dateAdditionSplit[1] . 'M'));
667+
break;
668+
case 'y':
669+
date_add($compDate1, new DateInterval('P' . $dateAdditionSplit[1] . 'Y'));
670+
break;
671+
case 'd':
672+
default:
673+
date_add($compDate1, new DateInterval('P' . $dateAdditionSplit[1] . 'D'));
674+
break;
675+
}
676+
677+
//Compare last test date with future date and output days
678+
$dateDiff = date_diff($compDate2, $compDate1);
679+
$content = $dateDiff->format('%R%a');
680+
}
681+
}
682+
}
632683

633684
$columnValues[] = ($strikethrough && $getMode != 'csv' && $getMode != 'ods' && $getMode != 'xlsx') ? '<s>' . $content . '</s>' : $content;
634685
$columnNumber++;

items/items_edit_new.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ function validateReceivedOnAndBackOn() {
262262
break;
263263

264264
case 'DROPDOWN':
265+
case'DATE_INTERVAL':
265266
$form->addSelectBox(
266267
'imf-' . $items->getProperty($imfNameIntern, 'imf_id'),
267268
convlanguagePIM($items->getProperty($imfNameIntern, 'imf_name')),

0 commit comments

Comments
 (0)