Skip to content

Commit aedb202

Browse files
authored
Merge pull request #1886 from Admidio/imventory-date-intervall-field
Imventory date intervall field
2 parents 4dbfc28 + cfbd89b commit aedb202

File tree

17 files changed

+409
-203
lines changed

17 files changed

+409
-203
lines changed

install/db_scripts/db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ CREATE TABLE %PREFIX%_inventory_fields
10461046
inf_system boolean NOT NULL DEFAULT false,
10471047
inf_required_input smallint NOT NULL DEFAULT 0,
10481048
inf_sequence smallint NOT NULL,
1049+
inf_inf_uuid_connected varchar(36) NULL DEFAULT NULL,
10491050
inf_usr_id_create integer unsigned,
10501051
inf_timestamp_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
10511052
inf_usr_id_change integer unsigned,

install/db_scripts/update_5_0.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,5 +524,6 @@ WHERE usf_fn.usf_name_intern = 'FIRST_NAME' AND usf_ln.usf_name_intern = 'LAST_N
524524
<step id="1790" database="pgsql">ALTER TABLE %PREFIX%_inventory_item_borrow_data ALTER COLUMN inb_borrow_date TYPE timestamp;</step>
525525
<step id="1800" database="mysql">ALTER TABLE %PREFIX%_inventory_item_borrow_data MODIFY COLUMN inb_return_date timestamp NULL DEFAULT NULL;</step>
526526
<step id="1810" database="pgsql">ALTER TABLE %PREFIX%_inventory_item_borrow_data ALTER COLUMN inb_return_date TYPE timestamp;</step>
527+
<step id="1820">ALTER TABLE %PREFIX%_inventory_fields ADD COLUMN inf_inf_uuid_connected varchar(36) NULL DEFAULT NULL;</step>
527528
<step>stop</step>
528529
</update>

languages/en.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@
533533
<string name="SYS_DOWNLOAD_PHOTO">Download photo</string>
534534
<string name="SYS_DOWNLOAD_ZIP_ERROR">An error occurred when creating the zip file.</string>
535535
<string name="SYS_DQUOTE">Double quote (")</string>
536+
<string name="SYS_DROPDOWN_DATE_INTERVAL_LISTBOX">Drop-down list box (date interval)</string>
536537
<string name="SYS_DROPDOWN_LISTBOX">Drop-down list box</string>
537538
<string name="SYS_DROPDOWN_MULTISELECT_LISTBOX">Drop-down list box (multi-select)</string>
538539
<string name="SYS_DUPLICATE">Duplicate</string>
@@ -789,7 +790,9 @@
789790
<string name="SYS_INVENTORY_BORROW_DATE_DESC">The borrowing date of the item to the last recipient</string>
790791
<string name="SYS_INVENTORY_BORROW_DATE_WARNING">The borrowing date of the item must be before the return date!</string>
791792
<string name="SYS_INVENTORY_CATEGORY_DESC">The category of an item</string>
792-
<string name="SYS_INVENTORY_COPY_PREFERENCES">Settings for copying a item:</string>
793+
<string name="SYS_INVENTORY_CONNECTED_FIELD">Connected field</string>
794+
<string name="SYS_INVENTORY_COPY_PREFERENCES">Settings for copying an item:</string>
795+
<string name="SYS_INVENTORY_DATE_INTERVAL_LIST_DESC">In this table, you can enter the entries for the date intervals. A table row can be added here for each subsequent entry in the drop-down list box.\nThe list entry is not stored as text later, but the selected position from the list. If you change the text in a row, all users will immediately see the new text.\nThe date interval must be written in the same row separated by the |-symbol after the title. e.g. Yearly | 1y \nIf no unit is specified, days are assumed. \nPossible units: d: days, w: weeks, m: months, y: years</string>
793796
<string name="SYS_INVENTORY_DATETIME_FORMAT">Date representation</string>
794797
<string name="SYS_INVENTORY_DATETIME_FORMAT_DESC">Selection of the date format to be used for displaying date and time information in the inventory manager. (Default: Date (DD.MM.YYYY))</string>
795798
<string name="SYS_INVENTORY_DECIMAL_PLACES">Decimal steps</string>

modules/inventory.php

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
$postCopyNumber = admFuncVariableIsValid($_POST, 'item_copy_number', 'numeric', array('defaultValue' => 1));
4848
$postCopyField = admFuncVariableIsValid($_POST, 'item_copy_field', 'int', array('defaultValue' => 0));
4949
$postRedirect = admFuncVariableIsValid($_POST, 'redirect', 'numeric', array('defaultValue' => 1));
50-
$postImported = admFuncVariableIsValid($_POST, 'imported', 'numeric', array('defaultValue' => 0));
50+
$postImported = admFuncVariableIsValid($_POST, 'imported', 'bool', array('defaultValue' => false));
5151
$getCopy = admFuncVariableIsValid($_GET, 'copy', 'bool', array('defaultValue' => false));
5252
$getRetired = admFuncVariableIsValid($_GET, 'item_retired', 'bool', array('defaultValue' => false));
5353
$getRedirectToImport = admFuncVariableIsValid($_GET, 'redirect_to_import', 'bool', array('defaultValue' => false));
@@ -113,8 +113,8 @@
113113
break;
114114

115115
case 'field_save':
116-
$itemFieldsModule = new ItemFieldService($gDb, $getinfUUID);
117-
$itemFieldsModule->save();
116+
$itemFieldService = new ItemFieldService($gDb, $getinfUUID);
117+
$itemFieldService->save();
118118

119119
$gNavigation->deleteLastUrl();
120120
echo json_encode(array('status' => 'success', 'url' => $gNavigation->getUrl()));
@@ -124,8 +124,8 @@
124124
// check the CSRF token of the form against the session token
125125
SecurityUtils::validateCsrfToken($_POST['adm_csrf_token']);
126126

127-
$itemFieldsModule = new ItemFieldService($gDb, $getinfUUID);
128-
$itemFieldsModule->delete();
127+
$itemFieldService = new ItemFieldService($gDb, $getinfUUID);
128+
$itemFieldService->delete();
129129

130130
echo json_encode(array('status' => 'success', 'message' => $gL10n->get('SYS_INVENTORY_ITEMFIELD_DELETED')));
131131
break;
@@ -137,9 +137,9 @@
137137
$status = 'error';
138138
// check if the option entry has any dependencies in the database
139139
if ($getOptionID > 0) {
140-
$itemFieldsModule = new ItemFieldService($gDb, $getinfUUID);
140+
$itemFieldService = new ItemFieldService($gDb, $getinfUUID);
141141

142-
$option = new SelectOptions($gDb, $itemFieldsModule->getFieldID());
142+
$option = new SelectOptions($gDb, $itemFieldService->getFieldID());
143143
if ($option->isOptionUsed($getOptionID)) {
144144
// if the option is used in a profile field, then it cannot be deleted
145145
$status = 'used';
@@ -158,9 +158,9 @@
158158
$status = 'error';
159159
// check if the option entry has any dependencies in the database
160160
if ($getOptionID > 0) {
161-
$itemFieldsModule = new ItemFieldService($gDb, $getinfUUID);
161+
$itemFieldService = new ItemFieldService($gDb, $getinfUUID);
162162

163-
$option = new SelectOptions($gDb, $itemFieldsModule->getFieldID());
163+
$option = new SelectOptions($gDb, $itemFieldService->getFieldID());
164164
// delete the option entry
165165
$option->deleteOption($getOptionID);
166166
$status = 'success';
@@ -176,13 +176,13 @@
176176
// check the CSRF token of the form against the session token
177177
SecurityUtils::validateCsrfToken($_POST['adm_csrf_token']);
178178

179-
$itemFieldsModule = new ItemFieldService($gDb, $getinfUUID);
179+
$itemFieldService = new ItemFieldService($gDb, $getinfUUID);
180180

181181
if (!empty($getOrder)) {
182182
// set new order (drag and drop)
183-
$ret = $itemFieldsModule->setSequence(explode(',', $getOrder));
183+
$ret = $itemFieldService->setSequence(explode(',', $getOrder));
184184
} else {
185-
$ret = $itemFieldsModule->moveSequence($postDirection);
185+
$ret = $itemFieldService->moveSequence($postDirection);
186186
}
187187

188188
echo json_encode(array('status' => ($ret ? 'success' : 'error')));
@@ -248,12 +248,12 @@
248248

249249
if (count($getItemUUIDs) > 0) {
250250
foreach ($getItemUUIDs as $itemUuid) {
251-
$itemModule = new ItemService($gDb, $itemUuid, $postCopyField, $postCopyNumber, $postImported);
252-
$itemModule->save(true);
251+
$itemService = new ItemService($gDb, $itemUuid, $postCopyField, $postCopyNumber, $postImported);
252+
$itemService->save(true);
253253
}
254254
} else {
255-
$itemModule = new ItemService($gDb, $getiniUUID, $postCopyField, $postCopyNumber, $postImported);
256-
$itemModule->save();
255+
$itemService = new ItemService($gDb, $getiniUUID, $postCopyField, $postCopyNumber, $postImported);
256+
$itemService->save();
257257
}
258258

259259
$gNavigation->deleteLastUrl();
@@ -349,13 +349,13 @@
349349
SecurityUtils::validateCsrfToken($_POST['adm_csrf_token']);
350350
if (count($getItemUUIDs) > 0) {
351351
foreach ($getItemUUIDs as $itemUuid) {
352-
$itemModule = new ItemService($gDb, $itemUuid);
353-
$itemModule->retireItem();
352+
$itemService = new ItemService($gDb, $itemUuid);
353+
$itemService->retireItem();
354354
}
355355
echo json_encode(array('status' => 'success', 'message' => $gL10n->get('SYS_INVENTORY_SELECTION_RETIRED')));
356356
} else {
357-
$itemModule = new ItemService($gDb, $getiniUUID);
358-
$itemModule->retireItem();
357+
$itemService = new ItemService($gDb, $getiniUUID);
358+
$itemService->retireItem();
359359
echo json_encode(array('status' => 'success', 'message' => $gL10n->get('SYS_INVENTORY_ITEM_RETIRED')));
360360
}
361361

@@ -366,13 +366,13 @@
366366
SecurityUtils::validateCsrfToken($_POST['adm_csrf_token']);
367367
if (count($getItemUUIDs) > 0) {
368368
foreach ($getItemUUIDs as $itemUuid) {
369-
$itemModule = new ItemService($gDb, $itemUuid);
370-
$itemModule->reinstateItem();
369+
$itemService = new ItemService($gDb, $itemUuid);
370+
$itemService->reinstateItem();
371371
}
372372
echo json_encode(array('status' => 'success', 'message' => $gL10n->get('SYS_INVENTORY_SELECTION_REINSTATED')));
373373
} else {
374-
$itemModule = new ItemService($gDb, $getiniUUID);
375-
$itemModule->reinstateItem();
374+
$itemService = new ItemService($gDb, $getiniUUID);
375+
$itemService->reinstateItem();
376376
echo json_encode(array('status' => 'success', 'message' => $gL10n->get('SYS_INVENTORY_ITEM_REINSTATED')));
377377
}
378378

@@ -384,22 +384,22 @@
384384

385385
if (count($getItemUUIDs) > 0) {
386386
foreach ($getItemUUIDs as $itemUuid) {
387-
$itemModule = new ItemService($gDb, $itemUuid);
388-
$itemModule->delete();
387+
$itemService = new ItemService($gDb, $itemUuid);
388+
$itemService->delete();
389389
}
390390
echo json_encode(array('status' => 'success', 'message' => $gL10n->get('SYS_INVENTORY_SELECTION_DELETED')));
391391
} else {
392-
$itemModule = new ItemService($gDb, $getiniUUID);
393-
$itemModule->delete();
392+
$itemService = new ItemService($gDb, $getiniUUID);
393+
$itemService->delete();
394394

395395
echo json_encode(array('status' => 'success', 'message' => $gL10n->get('SYS_INVENTORY_ITEM_DELETED')));
396396
}
397397
break;
398398
#endregion
399399
#region item pictures
400400
case 'item_picture_show':
401-
$itemModule = new ItemService($gDb, $getiniUUID);
402-
$itemModule->showItemPicture($getNewPicture);
401+
$itemService = new ItemService($gDb, $getiniUUID);
402+
$itemService->showItemPicture($getNewPicture);
403403
break;
404404

405405
case 'item_picture_show_modal':
@@ -426,8 +426,8 @@
426426
break;
427427

428428
case 'item_picture_upload':
429-
$itemModule = new ItemService($gDb, $getiniUUID);
430-
$itemModule->uploadItemPicture();
429+
$itemService = new ItemService($gDb, $getiniUUID);
430+
$itemService->uploadItemPicture();
431431

432432
echo json_encode(array('status' => 'success', 'url' => SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_MODULES . '/inventory.php', array('mode' => 'item_picture_review', 'item_uuid' => $getiniUUID))));
433433
break;
@@ -443,8 +443,8 @@
443443
break;
444444

445445
case 'item_picture_save':
446-
$itemModule = new ItemService($gDb, $getiniUUID);
447-
$itemModule->saveItemPicture();
446+
$itemService = new ItemService($gDb, $getiniUUID);
447+
$itemService->saveItemPicture();
448448

449449
// back to the home page
450450
// if url stack is bigger than 2 then delete until the edit page is reached
@@ -458,8 +458,8 @@
458458
// check the CSRF token of the form against the session token
459459
SecurityUtils::validateCsrfToken($_POST['adm_csrf_token']);
460460

461-
$itemModule = new ItemService($gDb, $getiniUUID);
462-
$itemModule->deleteItemPicture();
461+
$itemService = new ItemService($gDb, $getiniUUID);
462+
$itemService->deleteItemPicture();
463463

464464
echo json_encode(array('status' => 'success', 'message' => $gL10n->get('SYS_INVENTORY_ITEM_PICTURE_DELETED'), 'url' => $gNavigation->getUrl()));
465465
break;
@@ -483,8 +483,8 @@
483483
break;
484484

485485
case 'import_read_file':
486-
$import = new ImportService();
487-
$import->readImportFile();
486+
$importService = new ImportService();
487+
$importService->readImportFile();
488488
echo json_encode(array('status' => 'success', 'url' => SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_MODULES . '/inventory.php', array('mode' => 'import_assign_fields'))));
489489
break;
490490

@@ -499,8 +499,8 @@
499499
break;
500500

501501
case 'import_items':
502-
$import = new ImportService();
503-
$retStr = $import->importItems();
502+
$importService = new ImportService();
503+
$retStr = $importService->importItems();
504504

505505
$gNavigation->deleteLastUrl();
506506

src/Inventory/Entity/Item.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ class Item extends Entity
5353
* Constructor that will create an object of a recordset of the users table.
5454
* If the id is set than this recordset will be loaded.
5555
* @param Database $database Object of the class Database. This should be the default global object **$gDb**.
56-
* @param ItemsData|null $itemFields An object of the ItemsData class with the profile field structure
57-
* of the current organization.
56+
* @param ItemsData|null $itemsData object with current item field structure
5857
* @param int $itemId The id of the item which should be loaded. If id isn't set than an empty
5958
* object with no specific item is created.
6059
* @throws Exception

src/Inventory/Entity/ItemBorrowData.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Admidio\Infrastructure\Entity\Entity;
99
use Admidio\Inventory\ValueObjects\ItemsData;
1010
use Admidio\Changelog\Entity\LogChanges;
11-
use Admidio\Inventory\Entity\Item;
1211

1312
/**
1413
* @brief Class manages access to database table adm_files
@@ -48,6 +47,14 @@ public function __construct(Database $database, ?ItemsData $itemsData = null, in
4847
parent::__construct($database, TBL_INVENTORY_ITEM_BORROW_DATA, 'inb', $id);
4948
}
5049

50+
/**
51+
* Update the record ID of this entity.
52+
* This method is used when the record ID is generated outside of this entity,
53+
* for example, after inserting a new record into the database.
54+
* @param int $recordId The new record ID to set.
55+
* @return void
56+
* @throws Exception
57+
*/
5158
public function updateRecordId(int $recordId): void
5259
{
5360
if ($recordId !== 0) {

src/Inventory/Entity/ItemData.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function logItemfieldChange(?string $oldval = null, ?string $newval =
8888
if ($infType === 'CATEGORY') {
8989
// Category changes are logged in the inventory items table
9090
return true;
91-
} elseif ($infType === 'DROPDOWN' || $infType === 'DROPDOWN_MULTISELECT' || $infType === 'RADIOBUTTON') {
91+
} elseif (in_array($infType, array('DROPDOWN', 'DROPDOWN_MULTISELECT', 'DROPDOWN_DATE_INTERVAL', 'RADIOBUTTON'))) {
9292
$vallist = $this->mItemsData->getProperty($fieldNameIntern, 'ifo_inf_options');
9393
if (isset($vallist[$oldval])) {
9494
$oldval = $vallist[$oldval];
@@ -156,6 +156,7 @@ public function logCreation(): bool
156156
* Deletion actually means setting the user field to an empty value, so log a change to empty instead of deletion!
157157
*
158158
* @return bool Returns **true** if no error occurred
159+
* @throws Exception
159160
*/
160161
public function logDeletion(): bool
161162
{
@@ -168,6 +169,7 @@ public function logDeletion(): bool
168169
* Logs all modifications of the DB record
169170
* @param array $logChanges Array of all changes, generated by the save method
170171
* @return bool Returns **true** if no error occurred
172+
* @throws Exception
171173
*/
172174
public function logModifications(array $logChanges): bool
173175
{

0 commit comments

Comments
 (0)