From 1b706dea64aaa0c001169182838babd7e3a66909 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 12 May 2024 00:03:33 +0000 Subject: [PATCH] bug fixes --- .github/workflows/greetings.yml | 2 +- Admin/Installer.php | 2 +- Controller/ApiController.php | 33 +++++++++++-- Models/Account.php | 46 +++++++++++++++++++ Models/AccountMapper.php | 8 ++-- Models/Contact.php | 34 ++++++++++++++ .../group-selector-popup.tpl.php | 2 +- Theme/Backend/Lang/de.lang.php | 2 +- Theme/Backend/Lang/en.lang.php | 2 +- 9 files changed, 117 insertions(+), 14 deletions(-) diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index adb8716..75cb759 100755 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -9,5 +9,5 @@ jobs: - uses: actions/first-interaction@v1 with: repo-token: ${{ secrets.GITHUB_TOKEN }} - issue-message: 'Thank you for createing this issue. We will check it as soon as possible.' + issue-message: 'Thank you for creating this issue. We will check it as soon as possible.' pr-message: 'Thank you for your pull request. We will check it as soon as possible.' diff --git a/Admin/Installer.php b/Admin/Installer.php index 359ce73..15b45da 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -163,7 +163,7 @@ final class Installer extends InstallerAbstract ->into('language'); $querySqlite = new Builder($sqlite); - $languages = $querySqlite->select('*')->from('language')->execute(); + $languages = $querySqlite->select('*')->from('language')->execute()->fetchAll(); if ($languages === null) { return; diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 0f4169e..15d3c8a 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -1569,15 +1569,38 @@ final class ApiController extends Controller */ public function apiAccountFind(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void { + $fullName = $request->getDataString('search') ?? ''; + $names = \explode(' ', $fullName); + + $limit = $request->getDataInt('limit') ?? 50; + /** @var \Modules\Admin\Models\Account[] $accounts */ $accounts = AccountMapper::getAll() - ->where('login', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE') - ->where('email', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE', 'OR') - ->where('name1', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE', 'OR') - ->where('name2', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE', 'OR') - ->where('name3', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE', 'OR') + ->where('login', '%' . $fullName . '%', 'LIKE') + ->where('email', '%' . $fullName . '%', 'LIKE', 'OR') + ->where('name1', '%' . $fullName . '%', 'LIKE', 'OR') + ->where('name2', '%' . $fullName . '%', 'LIKE', 'OR') + ->where('name3', '%' . $fullName . '%', 'LIKE', 'OR') + ->limit($limit) ->executeGetArray(); + if (($count = \count($accounts)) < $limit) { + $mapper = AccountMapper::getAll(); + foreach ($names as $name) { + $mapper->where('login', '%' . $name . '%', 'LIKE', 'OR') + ->where('email', '%' . $name . '%', 'LIKE', 'OR') + ->where('name1', '%' . $name . '%', 'LIKE', 'OR') + ->where('name2', '%' . $name . '%', 'LIKE', 'OR') + ->where('name3', '%' . $name . '%', 'LIKE', 'OR'); + } + + /** @var \Modules\Admin\Models\Account[] $parts */ + $parts = $mapper->limit($limit - $count) + ->executeGetArray(); + + $accounts += $parts; + } + $response->header->set('Content-Type', MimeType::M_JSON, true); $response->set( $request->uri->__toString(), diff --git a/Models/Account.php b/Models/Account.php index 239e36e..ae3c4be 100755 --- a/Models/Account.php +++ b/Models/Account.php @@ -91,4 +91,50 @@ class Account extends \phpOMS\Account\Account return new NullContact(); } + + public static function fromJson(array $account) : self + { + $new = new self(); + $new->from($account); + + $new->tries = $account['tries'] ?? 0; + + foreach (($account['addresses'] ?? []) as $address) { + $new->addresses[] = \phpOMS\Stdlib\Base\Address::fromJson($address); + } + + foreach (($account['contacts'] ?? []) as $contact) { + $new->contacts[] = Contact::fromJson($contact); + } + + foreach (($account['parents'] ?? []) as $parent) { + $new->parents[] = self::fromJson($parent); + } + + return $new; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return \array_merge( + parent::toArray(), + [ + 'tries' => $this->tries, + 'addresses' => $this->addresses, + 'contacts' => $this->contacts, + 'parents' => $this->parents, + ] + ); + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return $this->toArray(); + } } diff --git a/Models/AccountMapper.php b/Models/AccountMapper.php index 7dc5ae6..c40fe70 100755 --- a/Models/AccountMapper.php +++ b/Models/AccountMapper.php @@ -174,8 +174,7 @@ class AccountMapper extends DataMapperFactory where `group`.group_status = 1; */ - /** @var \Modules\Admin\Models\Account $account */ - $account = self::get() + return self::get() ->with('groups') ->with('groups/permissions') ->with('permissions') @@ -184,8 +183,6 @@ class AccountMapper extends DataMapperFactory ->where('permissions/element', null) ->where('groups/permissions/element', null) ->execute(); - - return $account; } /** @@ -234,6 +231,7 @@ class AccountMapper extends DataMapperFactory } if (\password_verify($password, $result['account_password'] ?? '')) { + $query = new Builder(self::$db); $query->update('account') ->set([ 'account_lactive' => new \DateTime('now'), @@ -250,6 +248,7 @@ class AccountMapper extends DataMapperFactory && (new \DateTime('now'))->getTimestamp() < (new \DateTime($result['account_password_temp_limit']))->getTimestamp() && \password_verify($password, $result['account_password_temp'] ?? '') ) { + $query = new Builder(self::$db); $query->update('account') ->set([ 'account_password_temp' => '', @@ -262,6 +261,7 @@ class AccountMapper extends DataMapperFactory return $result['account_id']; } + $query = new Builder(self::$db); $query->update('account') ->set([ 'account_tries' => $result['account_tries'] + 1, diff --git a/Models/Contact.php b/Models/Contact.php index 879c8f2..aa652ba 100755 --- a/Models/Contact.php +++ b/Models/Contact.php @@ -59,4 +59,38 @@ class Contact * @since 1.0.0 */ public string $content = ''; + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return $this->toArray(); + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'type' => $this->type, + 'subtype' => $this->subtype, + 'title' => $this->title, + 'content' => $this->content, + ]; + } + + public static function fromJson(array $address) : self + { + $new = new self(); + $new->id = $address['id']; + $new->type = $address['type']; + $new->subtype = $address['subtype']; + $new->title = $address['title']; + $new->content = $address['content']; + + return $new; + } } diff --git a/Theme/Backend/Components/GroupTagSelector/group-selector-popup.tpl.php b/Theme/Backend/Components/GroupTagSelector/group-selector-popup.tpl.php index 5346acd..8f8648e 100755 --- a/Theme/Backend/Components/GroupTagSelector/group-selector-popup.tpl.php +++ b/Theme/Backend/Components/GroupTagSelector/group-selector-popup.tpl.php @@ -21,7 +21,7 @@ getHtml('Name'); ?> getHtml('Address'); ?> getHtml('City'); ?> - getHtml('Zip'); ?> + getHtml('Postal'); ?> getHtml('Country'); ?> [ 'Warnings' => 'Warnungen', 'Website' => 'Webseite', 'Weight' => 'Gewicht', - 'Zip' => 'Reißverschluss', + 'Postal' => 'Reißverschluss', 'active' => 'aktiv', 'available' => 'verfügbar', 'i:LoginRetries' => 'Betrag der erlaubten Wiederholungen (-1 = unbegrenzt)', diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 04e910b..4ce2c07 100755 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -198,7 +198,7 @@ return ['Admin' => [ 'Warnings' => 'Warnings', 'Website' => 'Website', 'Weight' => 'Weight', - 'Zip' => 'Zip', + 'Postal' => 'Postal', 'active' => 'active', 'available' => 'available', 'i:LoginRetries' => 'Amount of allowed retries (-1 = unlimited)',