Skip to content

Commit c1d2f89

Browse files
committed
use translation-ids for user relation types
1 parent 2e7d393 commit c1d2f89

File tree

4 files changed

+55
-30
lines changed

4 files changed

+55
-30
lines changed

install/install_steps/start_installation.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@
169169
// create user relation types
170170
$sql = 'INSERT INTO '.TBL_USER_RELATION_TYPES.'
171171
(urt_id, urt_uuid, urt_name, urt_name_male, urt_name_female, urt_id_inverse, urt_usr_id_create, urt_timestamp_create)
172-
VALUES (1, \'' . Uuid::uuid4() . '\', \''.$gL10n->get('INS_PARENT').'\', \''.$gL10n->get('INS_FATHER').'\', \''.$gL10n->get('INS_MOTHER').'\', null, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
173-
, (2, \'' . Uuid::uuid4() . '\', \''.$gL10n->get('INS_CHILD').'\', \''.$gL10n->get('INS_SON').'\', \''.$gL10n->get('INS_DAUGHTER').'\', 1, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
174-
, (3, \'' . Uuid::uuid4() . '\', \''.$gL10n->get('INS_SIBLING').'\', \''.$gL10n->get('INS_BROTHER').'\', \''.$gL10n->get('INS_SISTER').'\', 3, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
175-
, (4, \'' . Uuid::uuid4() . '\', \''.$gL10n->get('INS_SPOUSE').'\', \''.$gL10n->get('INS_HUSBAND').'\', \''.$gL10n->get('INS_WIFE').'\', 4, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
176-
, (5, \'' . Uuid::uuid4() . '\', \''.$gL10n->get('INS_COHABITANT').'\', \''.$gL10n->get('INS_COHABITANT_MALE').'\', \''.$gL10n->get('INS_COHABITANT_FEMALE').'\', 5, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
177-
, (6, \'' . Uuid::uuid4() . '\', \''.$gL10n->get('SYS_COMPANION').'\', \''.$gL10n->get('SYS_BOYFRIEND').'\', \''.$gL10n->get('SYS_GIRLFRIEND').'\', 6, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
178-
, (7, \'' . Uuid::uuid4() . '\', \''.$gL10n->get('SYS_SUPERIOR').'\', \''.$gL10n->get('SYS_SUPERIOR_MALE').'\', \''.$gL10n->get('SYS_SUPERIOR_FEMALE').'\', null, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
179-
, (8, \'' . Uuid::uuid4() . '\', \''.$gL10n->get('INS_SUBORDINATE').'\', \''.$gL10n->get('INS_SUBORDINATE_MALE').'\', \''.$gL10n->get('INS_SUBORDINATE_FEMALE').'\', 7, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')';
172+
VALUES (1, \'' . Uuid::uuid4() . '\', \'INS_PARENT\', \'INS_FATHER\', \'INS_MOTHER\', null, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
173+
, (2, \'' . Uuid::uuid4() . '\', \'INS_CHILD\', \'INS_SON\', \'INS_DAUGHTER\', 1, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
174+
, (3, \'' . Uuid::uuid4() . '\', \'INS_SIBLING\', \'INS_BROTHER\', \'INS_SISTER\', 3, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
175+
, (4, \'' . Uuid::uuid4() . '\', \'INS_SPOUSE\', \'INS_HUSBAND\', \'INS_WIFE\', 4, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
176+
, (5, \'' . Uuid::uuid4() . '\', \'INS_COHABITANT\', \'INS_COHABITANT_MALE\', \'INS_COHABITANT_FEMALE\', 5, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
177+
, (6, \'' . Uuid::uuid4() . '\', \'SYS_COMPANION\', \'SYS_BOYFRIEND\', \'SYS_GIRLFRIEND\', 6, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
178+
, (7, \'' . Uuid::uuid4() . '\', \'SYS_SUPERIOR\', \'SYS_SUPERIOR_MALE\', \'SYS_SUPERIOR_FEMALE\', null, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')
179+
, (8, \'' . Uuid::uuid4() . '\', \'INS_SUBORDINATE\', \'INS_SUBORDINATE_MALE\', \'INS_SUBORDINATE_FEMALE\', 7, '.$gCurrentUserId.', \''. DATETIME_NOW.'\')';
180180
$db->query($sql); // TODO add more params
181181

182182
$sql = 'UPDATE '.TBL_USER_RELATION_TYPES.'

modules/userrelations/relationtypes_new.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,19 @@ function updateRelationType(element, duration) {
9898
$form->addInput(
9999
'urt_name',
100100
$gL10n->get('SYS_NAME'),
101-
$relationType1->getValue('urt_name'),
101+
htmlentities($relationType1->getValue('urt_name', 'database'), ENT_QUOTES),
102102
array('maxLength' => 100, 'property' => FormPresenter::FIELD_REQUIRED)
103103
);
104104
$form->addInput(
105105
'urt_name_male',
106106
$gL10n->get('SYS_MALE'),
107-
($relationType1->getValue('urt_name_male') !== $relationType1->getValue('urt_name')) ? $relationType1->getValue('urt_name_male') : '',
107+
($relationType1->getValue('urt_name_male', 'database') !== $relationType1->getValue('urt_name', 'database')) ? htmlentities($relationType1->getValue('urt_name_male', 'database'), ENT_QUOTES) : '',
108108
array('maxLength' => 100)
109109
);
110110
$form->addInput(
111111
'urt_name_female',
112112
$gL10n->get('SYS_FEMALE'),
113-
($relationType1->getValue('urt_name_female') !== $relationType1->getValue('urt_name')) ? $relationType1->getValue('urt_name_female') : '',
113+
($relationType1->getValue('urt_name_female', 'database') !== $relationType1->getValue('urt_name', 'database')) ? htmlentities($relationType1->getValue('urt_name_female', 'database'), ENT_QUOTES) : '',
114114
array('maxLength' => 100)
115115
);
116116
$form->addCheckbox(
@@ -138,19 +138,19 @@ function updateRelationType(element, duration) {
138138
$form->addInput(
139139
'urt_name_inverse',
140140
$gL10n->get('SYS_NAME'),
141-
$relationType2->getValue('urt_name'),
141+
htmlentities($relationType2->getValue('urt_name', 'database'), ENT_QUOTES),
142142
array('maxLength' => 100)
143143
);
144144
$form->addInput(
145145
'urt_name_male_inverse',
146146
$gL10n->get('SYS_MALE'),
147-
($relationType2->getValue('urt_name_male') !== $relationType2->getValue('urt_name')) ? $relationType2->getValue('urt_name_male') : '',
147+
($relationType2->getValue('urt_name_male', 'database') !== $relationType2->getValue('urt_name', 'database')) ? htmlentities($relationType2->getValue('urt_name_male', 'database'), ENT_QUOTES) : '',
148148
array('maxLength' => 100)
149149
);
150150
$form->addInput(
151151
'urt_name_female_inverse',
152152
$gL10n->get('SYS_FEMALE'),
153-
($relationType2->getValue('urt_name_female') !== $relationType2->getValue('urt_name')) ? $relationType2->getValue('urt_name_female') : '',
153+
($relationType2->getValue('urt_name_female', 'database') !== $relationType2->getValue('urt_name', 'database')) ? htmlentities($relationType2->getValue('urt_name_female', 'database'), ENT_QUOTES) : '',
154154
array('maxLength' => 100)
155155
);
156156
$form->addCheckbox(

src/Categories/Entity/Category.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ public function getNumberElements(): int
179179

180180
/**
181181
* Get the value of a column of the database table.
182-
* If the value was manipulated before with **setValue** than the manipulated value is returned.
182+
* If the value was manipulated before with **setValue** then the manipulated value is returned.
183183
* @param string $columnName The name of the database column whose value should be read
184-
* @param string $format For date or timestamp columns the format should be the date/time format e.g. **d.m.Y = '02.04.2011'**.
185-
* For text columns the format can be **database** that would return the original database value without any transformations
184+
* @param string $format For date or timestamp columns, the format should be the date/time format e.g. **d.m.Y = '02.04.2011'**.
185+
* For text columns, the format can be **database** that would return the original database value without any transformations
186186
* @return mixed Returns the value of the database column.
187-
* If the value was manipulated before with **setValue** than the manipulated value is returned.
187+
* If the value was manipulated before with **setValue** then the manipulated value is returned.
188188
* @throws Exception
189189
*/
190190
public function getValue(string $columnName, string $format = ''): mixed
@@ -198,7 +198,7 @@ public function getValue(string $columnName, string $format = ''): mixed
198198
$value = parent::getValue($columnName, $format);
199199
}
200200

201-
// if text is a translation-id then translate it
201+
// if a text is a translation-id, then translate it
202202
if ($columnName === 'cat_name' && $format !== 'database' && Language::isTranslationStringId($value)) {
203203
$value = $gL10n->get($value);
204204
}
@@ -209,7 +209,7 @@ public function getValue(string $columnName, string $format = ''): mixed
209209
/**
210210
* This method checks if the current user is allowed to edit this category. Therefore,
211211
* the category must be visible to the user and must be of the current organization.
212-
* If this is a global category than the current organization must be the parent organization.
212+
* If this is a global category, then the current organization must be the parent organization.
213213
* @return bool Return true if the current user is allowed to edit this category
214214
* @throws Exception
215215
*/

src/Users/Entity/UserRelationType.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
namespace Admidio\Users\Entity;
34

45
use Admidio\Infrastructure\Database;
56
use Admidio\Infrastructure\Exception;
67
use Admidio\Infrastructure\Entity\Entity;
78
use Admidio\Changelog\Entity\LogChanges;
9+
use Admidio\Infrastructure\Language;
810

911
/**
1012
* @brief Class manages access to database table adm_user_relation_types
@@ -13,18 +15,17 @@
1315
* @see https://www.admidio.org/
1416
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
1517
*/
16-
1718
class UserRelationType extends Entity
1819
{
1920
public const USER_RELATION_TYPE_UNIDIRECTIONAL = 'unidirectional';
20-
public const USER_RELATION_TYPE_SYMMETRICAL = 'symmetrical';
21-
public const USER_RELATION_TYPE_ASYMMETRICAL = 'asymmetrical';
21+
public const USER_RELATION_TYPE_SYMMETRICAL = 'symmetrical';
22+
public const USER_RELATION_TYPE_ASYMMETRICAL = 'asymmetrical';
2223

2324
/**
2425
* Constructor that will create an object of a recordset of the table adm_user_relation_types.
25-
* If the id is set than the specific message will be loaded.
26+
* If the ID is set, then the specific message will be loaded.
2627
* @param Database $database Object of the class Database. This should be the default global object **$gDb**.
27-
* @param int $urtId The recordset of the relation type with this id will be loaded. If id isn't set than an empty object of the table is created.
28+
* @param int $urtId The recordset of the relation type with this id will be loaded. If id isn't set, then an empty object of the table is created.
2829
* @throws Exception
2930
*/
3031
public function __construct(Database $database, int $urtId = 0)
@@ -61,14 +62,39 @@ public function getRelationTypeString(): string
6162
if (!$this->isNewRecord()) {
6263
if (empty($this->getValue('urt_id_inverse'))) {
6364
return self::USER_RELATION_TYPE_UNIDIRECTIONAL;
64-
} elseif ((int) $this->getValue('urt_id_inverse') === (int) $this->getValue('urt_id')) {
65+
} elseif ((int)$this->getValue('urt_id_inverse') === (int)$this->getValue('urt_id')) {
6566
return self::USER_RELATION_TYPE_SYMMETRICAL;
6667
}
6768
}
6869

6970
return self::USER_RELATION_TYPE_ASYMMETRICAL;
7071
}
7172

73+
/**
74+
* Get the value of a column of the database table.
75+
* If the value was manipulated before with **setValue** then the manipulated value is returned.
76+
* @param string $columnName The name of the database column whose value should be read
77+
* @param string $format For date or timestamp columns, the format should be the date/time format e.g. **d.m.Y = '02.04.2011'**.
78+
* For text columns, the format can be **database** that would return the original database value without any transformations
79+
* @return mixed Returns the value of the database column.
80+
* If the value was manipulated before with **setValue** then the manipulated value is returned.
81+
* @throws Exception
82+
*/
83+
public function getValue(string $columnName, string $format = ''): mixed
84+
{
85+
global $gL10n;
86+
87+
$value = parent::getValue($columnName, $format);
88+
89+
// if a text is a translation-id, then translate it
90+
if (in_array($columnName, array('urt_name', 'urt_name_male', 'urt_name_female')) &&
91+
$format !== 'database' && Language::isTranslationStringId($value)) {
92+
$value = $gL10n->get($value);
93+
}
94+
95+
return $value;
96+
}
97+
7298
/**
7399
* @return bool
74100
* @throws Exception
@@ -98,14 +124,13 @@ public function isUnidirectional(): bool
98124

99125
/**
100126
* Adjust the changelog entry for this db record.
101-
*
102127
* For user relation types, we want to show the inverse relation as related.
103-
*
104128
* @param LogChanges $logEntry The log entry to adjust
105-
*
106129
* @return void
130+
* @throws Exception
107131
*/
108-
protected function adjustLogEntry(LogChanges $logEntry) {
132+
protected function adjustLogEntry(LogChanges $logEntry): void
133+
{
109134
$inverse = $this->getInverse();
110135
if ($inverse) {
111136
$logEntry->setLogRelated($inverse->getValue('urt_uuid'), $inverse->getValue('urt_name'));

0 commit comments

Comments
 (0)