Skip to content

Commit 07a3dea

Browse files
committed
- fix: inventory module not visible for visitors when module is enabled
- code formatting improvements across multiple files (inventory module)
1 parent f8dfd03 commit 07a3dea

File tree

10 files changed

+322
-355
lines changed

10 files changed

+322
-355
lines changed

modules/inventory.php

Lines changed: 64 additions & 80 deletions
Large diffs are not rendered by default.

src/Inventory/Entity/Item.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
// Admidio namespaces
66
use Admidio\Infrastructure\Database;
77
use Admidio\Infrastructure\Entity\Entity;
8+
use Admidio\Infrastructure\Exception;
9+
use Admidio\Infrastructure\Language;
810
use Admidio\Inventory\ValueObjects\ItemsData;
9-
use Admidio\Inventory\Entity\ItemData;
10-
use Admidio\Inventory\Entity\SelectOptions;
1111
use Admidio\Changelog\Entity\LogChanges;
12-
use Admidio\Infrastructure\Language;
1312

1413
/**
1514
* @brief Class manages access to database table adm_files
@@ -68,20 +67,20 @@ public function __construct(Database $database, ?ItemsData $itemsData = null, in
6867

6968
$this->organizationId = $GLOBALS['gCurrentOrgId'];
7069
$this->itemId = $itemId;
71-
70+
7271
$this->connectAdditionalTable(TBL_CATEGORIES, 'cat_id', 'ini_cat_id');
7372

7473
parent::__construct($database, TBL_INVENTORY_ITEMS, 'ini', $itemId);
7574
}
76-
75+
7776
/**
7877
* Changes to user data could be sent as a notification email to a specific role if this
7978
* function is enabled in the settings. If you want to suppress this logic you can
8079
* explicit disable it with this method for this user. So no changes to this user object will
8180
* result in a notification email.
8281
* @return void
8382
*/
84-
public function disableChangeNotification()
83+
public function disableChangeNotification(): void
8584
{
8685
$this->changeNotificationEnabled = false;
8786
}
@@ -121,21 +120,23 @@ public function readDataByUuid(string $uuid): bool
121120
* Return a human-readable representation of this record.
122121
* If a column [prefix]_name exists, it is returned, otherwise the id.
123122
* This method can be overridden in child classes for custom behavior.
124-
*
123+
*
125124
* @return string The readable representation of the record (can also be a translatable identifier)
125+
* @throws Exception
126126
*/
127127
public function readableName(): string
128128
{
129129
global $gDb;
130130
// check if mItemsData is set
131131
$itemData = new ItemData($gDb, $this->mItemsData);
132132
$itemData->readDataByColumns(array('ind_ini_id' => $this->itemId, 'ind_inf_id' => $this->mItemsData->getProperty('ITEMNAME', 'inf_id')));
133-
return $itemData->getValue('ind_value');
133+
return $itemData->getValue('ind_value');
134134
}
135135

136136
/**
137137
* Get the status of the item.
138138
* @return int The status of the item.
139+
* @throws Exception
139140
*/
140141
public function getStatus(): int
141142
{
@@ -145,6 +146,7 @@ public function getStatus(): int
145146
/**
146147
* Check if the item is retired.
147148
* @return bool Returns true if the item is retired, false otherwise.
149+
* @throws Exception
148150
*/
149151
public function isRetired(): bool
150152
{
@@ -160,6 +162,7 @@ public function isRetired(): bool
160162
/**
161163
* Check if the item is in use.
162164
* @return bool Returns true if the item is in use, false otherwise.
165+
* @throws Exception
163166
*/
164167
public function isInUse(): bool
165168
{
@@ -171,7 +174,7 @@ public function isInUse(): bool
171174
}
172175
return false;
173176
}
174-
177+
175178
/**
176179
* Retrieve the list of database fields that are ignored for the changelog.
177180
* Some tables contain columns _usr_id_create, timestamp_create, etc. We do not want
@@ -199,9 +202,8 @@ protected function adjustLogEntry(LogChanges $logEntry): void
199202
$itemName = $this->mItemsData->getValue('ITEMNAME', 'database');
200203
if (isset($_POST['INF-ITEMNAME']) && $itemName === '') {
201204
$itemName = $_POST['INF-ITEMNAME'];
202-
}
203-
elseif (!isset( $_POST['INF-ITEMNAME']) && $itemName === '') {
204-
$itemName = $logEntry->getValue('log_record_name');
205+
} elseif (!isset($_POST['INF-ITEMNAME']) && $itemName === '') {
206+
$itemName = $logEntry->getValue('log_record_name');
205207
}
206208

207209
// If the item status is changed convert the status id to the actual status text

src/Inventory/Entity/ItemBorrowData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(Database $database, ?ItemsData $itemsData = null, in
4848
parent::__construct($database, TBL_INVENTORY_ITEM_BORROW_DATA, 'inb', $id);
4949
}
5050

51-
public function updateRecordId(int $recordId) : void
51+
public function updateRecordId(int $recordId): void
5252
{
5353
if ($recordId !== 0) {
5454
$this->setValue('inb_id', $recordId);

src/Inventory/Entity/ItemData.php

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ public function __construct(Database $database, ?ItemsData $itemsData = null, in
5454
/**
5555
* Since creation means setting value from NULL to something, deletion mean setting the field to empty,
5656
* we need one generic change log function that is called on creation, deletion and modification.
57-
*
57+
*
5858
* The log entries are: record ID for ind_id, but uuid and link point to User id.
5959
* log_field is the inf_id and log_field_name is the fields external name.
60-
*
60+
*
6161
* @param string $oldval previous value before the change (can be null)
6262
* @param string $newval new value after the change (can be null)
6363
* @return true returns **true** if no error occurred
6464
*/
65-
protected function logItemfieldChange(?string $oldval = null, ?string $newval = null) : bool {
65+
protected function logItemfieldChange(?string $oldval = null, ?string $newval = null): bool
66+
{
6667
global $gDb, $gProfileFields;
6768

6869
if ($oldval === $newval) {
@@ -87,36 +88,30 @@ protected function logItemfieldChange(?string $oldval = null, ?string $newval =
8788
if ($infType === 'CATEGORY') {
8889
// Category changes are logged in the inventory items table
8990
return true;
90-
}
91-
elseif ($infType === 'DROPDOWN' || $infType === 'DROPDOWN_MULTISELECT' || $infType === 'RADIOBUTTON') {
91+
} elseif ($infType === 'DROPDOWN' || $infType === 'DROPDOWN_MULTISELECT' || $infType === 'RADIOBUTTON') {
9292
$vallist = $this->mItemsData->getProperty($fieldNameIntern, 'ifo_inf_options');
9393
if (isset($vallist[$oldval])) {
9494
$oldval = $vallist[$oldval];
9595
}
9696
if (isset($vallist[$newval])) {
9797
$newval = $vallist[$newval];
9898
}
99-
}
100-
elseif ($infType === 'CHECKBOX') {
99+
} elseif ($infType === 'CHECKBOX') {
101100
$fieldName = $fieldName . '_bool';
102-
}
103-
elseif ($infType === 'TEXT') {
101+
} elseif ($infType === 'TEXT') {
104102
if ($fieldNameIntern === 'ITEMNAME' && $itemName === '') {
105103
$itemName = $newval;
106-
}
107-
elseif ($fieldNameIntern === 'KEEPER') {
104+
} elseif ($fieldNameIntern === 'KEEPER') {
108105
$fieldName = $fieldName . '_usr';
109-
}
110-
elseif ($fieldNameIntern === 'LAST_RECEIVER') {
106+
} elseif ($fieldNameIntern === 'LAST_RECEIVER') {
111107
$user = new User($this->db, $gProfileFields);
112108
if (is_numeric($oldval) && is_numeric($newval)) {
113109
$foundOld = $user->readDataById($oldval);
114110
$foundNew = $user->readDataById($newval);
115111
if ($foundOld && $foundNew) {
116112
$fieldName = $fieldName . '_usr';
117113
}
118-
}
119-
elseif (is_numeric($oldval)) {
114+
} elseif (is_numeric($oldval)) {
120115
if ($user->readDataById($oldval)) {
121116
$oldval = '<a href="' . SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_MODULES . '/profile/profile.php', array('user_uuid' => $user->getValue('usr_uuid'))) . '">' . $user->getValue('LAST_NAME') . ', ' . $user->getValue('FIRST_NAME') . '</a>';
122117
}
@@ -126,17 +121,13 @@ protected function logItemfieldChange(?string $oldval = null, ?string $newval =
126121
}
127122
}
128123
}
129-
}
130-
elseif ($infType === 'DATE') {
124+
} elseif ($infType === 'DATE') {
131125
$fieldName = $fieldName . '_date';
132-
}
133-
elseif ($infType === 'EMAIL') {
126+
} elseif ($infType === 'EMAIL') {
134127
$fieldName = $fieldName . '_mail';
135-
}
136-
elseif ($infType === 'URL') {
128+
} elseif ($infType === 'URL') {
137129
$fieldName = $fieldName . '_url';
138-
}
139-
elseif ($infType === 'ICON') {
130+
} elseif ($infType === 'ICON') {
140131
$fieldName = $fieldName . '_icon';
141132
}
142133

@@ -152,16 +143,19 @@ protected function logItemfieldChange(?string $oldval = null, ?string $newval =
152143
* Logs creation of the DB record -> For user fields, no need to log anything as
153144
* the actual value change from NULL to something will be logged as a modification
154145
* immediately after creation, anyway.
155-
*
146+
*
156147
* @return true Returns **true** if no error occurred
157148
* @throws Exception
158149
*/
159-
public function logCreation(): bool { return true; }
150+
public function logCreation(): bool
151+
{
152+
return true;
153+
}
160154

161155
/**
162156
* Logs deletion of the DB record
163157
* Deletion actually means setting the user field to an empty value, so log a change to empty instead of deletion!
164-
*
158+
*
165159
* @return true Returns **true** if no error occurred
166160
*/
167161
public function logDeletion(): bool

src/Inventory/Entity/ItemField.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function delete(): bool
7575
$sql = 'DELETE FROM ' . TBL_INVENTORY_ITEM_DATA . '
7676
WHERE ind_inf_id = ? -- $infId';
7777
$this->db->queryPrepared($sql, array($infId));
78-
78+
7979
// delete all data of this field in the field select options table
8080
$sql = 'DELETE FROM ' . TBL_INVENTORY_FIELD_OPTIONS . '
8181
WHERE ifo_inf_id = ? -- $infId';
@@ -120,13 +120,13 @@ private function getNewNameIntern(string $name, int $index): string
120120

121121
/**
122122
* Returns the item value for this column
123-
*
123+
*
124124
* format = 'html' : returns the value in html-format if this is necessary for that field type
125125
* format = 'database' : returns the value that is stored in database with no format applied
126-
* @param string $fieldNameIntern Expects the @b inf_name_intern of table @b adm_inventory_fields
127-
* @param string $format Returns the field value in a special format @b text, @b html, @b database
126+
* @param string $fieldNameIntern Expects the @b inf_name_intern of table @b adm_inventory_fields
127+
* @param string $format Returns the field value in a special format @b text, @b html, @b database
128128
* or datetime (detailed description in method description)
129-
* @param bool $withObsoleteEnries If set to **false** then the obsolete entries of the inventory field will not be considered.
129+
* @param bool $withObsoleteEnries If set to **false** then the obsolete entries of the inventory field will not be considered.
130130
* @return mixed Returns the value for the column
131131
*/
132132
public function getValue($fieldNameIntern, $format = '', bool $withObsoleteEnries = true): mixed
@@ -162,7 +162,7 @@ public function getValue($fieldNameIntern, $format = '', bool $withObsoleteEnrie
162162
break;
163163

164164
case 'ifo_inf_options':
165-
if ($this->dbColumns['inf_type'] === 'DROPDOWN' || $this->dbColumns['inf_type'] === 'DROPDOWN_MULTISELECT' || $this->dbColumns['inf_type'] === 'RADIO_BUTTON') {
165+
if ($this->dbColumns['inf_type'] === 'DROPDOWN' || $this->dbColumns['inf_type'] === 'DROPDOWN_MULTISELECT' || $this->dbColumns['inf_type'] === 'RADIO_BUTTON') {
166166
$arrOptionValuesWithKeys = array(); // array with option values and keys that represents the internal value
167167
$arrOptions = $value;
168168

@@ -320,7 +320,8 @@ public function getIgnoredLogColumns(): array
320320
*/
321321
protected function adjustLogEntry(LogChanges $logEntry): void
322322
{
323-
/* $fotEntry = new ItemField($this->db, (int)$this->getValue('fot_fop_id_first_post'));
324-
$logEntry->setLogRelated($fotEntry->getValue('fop_uuid'), $fotEntry->getValue('fop_text'));
325-
*/ }
323+
/* $fotEntry = new ItemField($this->db, (int)$this->getValue('fot_fop_id_first_post'));
324+
$logEntry->setLogRelated($fotEntry->getValue('fop_uuid'), $fotEntry->getValue('fop_text'));
325+
*/
326+
}
326327
}

0 commit comments

Comments
 (0)