Skip to content

Commit

Permalink
pkp#10506 Refactor UserGroup to use Eloquent
Browse files Browse the repository at this point in the history
  • Loading branch information
Hafsa-Naeem committed Oct 15, 2024
1 parent ba75bb8 commit 35b9299
Show file tree
Hide file tree
Showing 6 changed files with 686 additions and 937 deletions.
13 changes: 13 additions & 0 deletions classes/core/SettingsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use stdClass;
use PKP\facades\Locale;

class SettingsBuilder extends Builder
{
Expand Down Expand Up @@ -110,6 +111,10 @@ public function insertGetId(array $values, $sequence = null)
$settingValues->each(function (mixed $settingValue, string $settingName) use ($id, &$rows) {
$settingName = Str::camel($settingName);
if ($this->isMultilingual($settingName)) {
// if non-localized data passed, set the locale to default one
if (is_string($settingValue)) {
$settingValue = $this->localizeNonLocalizedData($settingValue);
}
foreach ($settingValue as $locale => $localizedValue) {
$rows[] = [
$this->model->getKeyName() => $id, 'locale' => $locale, 'setting_name' => $settingName, 'setting_value' => $localizedValue
Expand All @@ -127,6 +132,14 @@ public function insertGetId(array $values, $sequence = null)
return $id;
}

/**
* Wrap a non localized value with the default locale
*/
protected function localizeNonLocalizedData(string $value): array
{
return [Locale::getLocale() => $value];
}

/**
* Delete model with settings
*/
Expand Down
364 changes: 0 additions & 364 deletions classes/userGroup/Collector.php

This file was deleted.

Loading

0 comments on commit 35b9299

Please sign in to comment.