From b6381f74f0ca758e5e3289be92f51c0904f36788 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Wed, 6 Mar 2024 12:50:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D1=80=D0=B5=D0=B9=D1=82=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=BE=D0=BB=D1=8E=20identifier=20=D0=B2=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Model/GetItemByIdentifierTrait.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 com_oauthserver/administrator/src/Model/GetItemByIdentifierTrait.php diff --git a/com_oauthserver/administrator/src/Model/GetItemByIdentifierTrait.php b/com_oauthserver/administrator/src/Model/GetItemByIdentifierTrait.php new file mode 100644 index 0000000..1576af8 --- /dev/null +++ b/com_oauthserver/administrator/src/Model/GetItemByIdentifierTrait.php @@ -0,0 +1,49 @@ +getState($this->getName() . '.identifier'); + /** @var \Joomla\CMS\Table\Table $table */ + $table = $this->getTable(); + + if (!empty($identifier)) { + $return = $table->load(['identifier' => $identifier]); + + if ($return === false) { + if (method_exists($table, 'getError') && $table->getError()) { + throw new \RuntimeException($table->getError()); + } + throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_NOT_EXIST')); + } + } + + // Convert to the CMSObject before adding other data. + $properties = $table->getProperties(true); + $all_properties = $table->getProperties(false); + + if (!empty($all_properties['_jsonEncode'])) { + foreach ($all_properties['$_jsonEncode'] as $prop) { + if (array_key_exists($prop, $properties) && is_string($properties[$prop])) { + $properties[$prop] = json_decode($properties[$prop]); + } + } + } + + return ArrayHelper::toObject($properties, CMSObject::class, true); + } +} \ No newline at end of file