$rc = redirect('/phrase-index');
} else {
$fields = $request->all();
- if (count($fields) === 1){
+ if (count($fields) === 1) {
$fields = [
'phrase' => '',
'language' => $request->language,
'translation' => ''
];
}
- if ($fields['lastLanguage'] != $fields['language']){
+ if ($fields['lastLanguage'] != $fields['language']) {
$phraseTranslation = Phrase::where(['language_scope' => $fields['language'], 'phrase_id' => $phrase->id])->first();
- if ($phraseTranslation != null){
+ if ($phraseTranslation != null) {
$fields['translation'] = $phraseTranslation->phrase;
}
}
if ($request->btnSubmit === 'btnNew') {
return redirect('/phrase-create');
} else {
- $sql = 'SELECT t0.*,'
- . 't1.name as language_scope, '
- . 't2.name as owner_id, '
- . 't3.name as verifiedby_id '
- . ' FROM phrases t0'
- . ' LEFT JOIN sproperties t1 ON t1.id=t0.language_scope'
- . ' LEFT JOIN sproperties t2 ON t2.id=t0.owner_id'
- . ' LEFT JOIN sproperties t3 ON t3.id=t0.verifiedby_id'
- ;
- $parameters = [];
$fields = $request->all();
+ $lang = count($fields) == 0 ? SProperty::idOfLocalization() : $fields['language'];
+ $sql = "
+SELECT t0.*,
+ t1.name as language_scope,
+ (select phrase from phrases t4 where t4.phrase_id=t0.id and t4.language_scope=$lang) as translation
+FROM phrases t0
+LEFT JOIN sproperties t1 ON t1.id=t0.language_scope
+LEFT JOIN users t2 ON t2.id=t0.owner_id
+";
+ $parameters = [];
+ $conditions = [];
if (count($fields) == 0) {
$fields = [
- 'language' => '',
+ 'language' => SProperty::idOfLocalization(),
'word' => '',
'phrase' => '',
'owner' => '',
- 'verifiedby' => '',
+ 'verified' => '',
'_sortParams' => 't0.phrase:asc;t0.id:desc'
];
} else {
- $conditions = [];
- ViewHelper::addConditionComparism($conditions, $parameters, 'language_scope', 'language');
- ViewHelper::addConditionComparism($conditions, $parameters, 'owner_id', 'owner');
- ViewHelper::addConditionComparism($conditions, $parameters, 'verifiedby_id', 'verifiedby');
- ViewHelper::addConditionPattern($conditions, $parameters, 'phrase', 'text');
- $sql = DbHelper::addConditions($sql, $conditions);
+ ViewHelper::addConditionComparism($conditions, $parameters, 't0.owner_id', 'owner');
+ $lang = $fields['language'];
+ if ($fields['verified'] != null) {
+ // 1: not verified 2: verified
+ $not = $fields['verified'] == 1 ? '' : ' NOT';
+ array_push($conditions, "EXISTS(SELECT id FROM phrases ph WHERE ph.id=t0.phrase_id AND ph.language_scope=$lang AND ph.verifiedby_id IS$not NULL)");
+ }
+ ViewHelper::addConditionPattern($conditions, $parameters, 't0.phrase', 'text');
}
+ ViewHelper::addConditionConstComparison($conditions, $parameters, 't0.language_scope', 1202);
+ $sql = DbHelper::addConditions($sql, $conditions);
$sql = DbHelper::addOrderBy($sql, $fields['_sortParams']);
$pagination = new Pagination($sql, $parameters, $fields);
$records = $pagination->records;
- $optionsLanguage = SProperty::optionsByScope('language', $fields['language'], 'all');
- $optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner'], __('<Please select>'));
- $optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby'], __('<Please select>'));
+ $optionsLanguage = SProperty::optionsByScope('localization', $fields['language']);
+ $optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner'], __('<All>'));
+ $optionsVerified = [
+ ['text' => __('<All>'), 'value' => '', 'active' => $fields['verified'] == ''],
+ ['text' => __('Not verified'), 'value' => 1, 'active' => $fields['verified'] == 1],
+ ['text' => __('Verified'), 'value' => 2, 'active' => $fields['verified'] == 2]
+ ];
$context = new ContextLaraKnife($request, $fields);
+ $context->setCombobox('language', 'Language', $optionsLanguage, '', 'lkn-autoupdate');
return view('phrase.index', [
'context' => $context,
'records' => $records,
- 'optionsLanguage' => $optionsLanguage,
'optionsOwner' => $optionsOwner,
- 'optionsVerifiedby' => $optionsVerifiedby,
+ 'optionsVerified' => $optionsVerified,
'pagination' => $pagination
]);
}
'phrase' => 'required',
'translation' => 'required',
];
- if ($isCreate){
+ if ($isCreate) {
$rc['language'] = 'required';
}
return $rc;
public function update(Phrase $phrase, Request $request)
{
$rc = null;
- if ($request->btnSubmit === 'btnInternal'){
+ if ($request->btnSubmit === 'btnInternal') {
// Language combobox has been changed:
$url = "/phrase-edit/$phrase->id?language=" . $request->language;
$rc = redirect($url);
]);
} else {
// Update only if changed:
- if ($phraseTranslation->phrase !== $validated['translation']){
+ if ($phraseTranslation->phrase !== $validated['translation']) {
$phraseTranslation->update(['phrase' => $validated['translation'], 'verifiedby_id' => null]);
}
}
"dist": {
"type": "path",
"url": "../laraknife",
- "reference": "75f027bc39816f480246d553ef5b996fed7a775e"
+ "reference": "47a41b7a9e0479870ed354c33653009296af812d"
},
"require-dev": {
"phpunit/phpunit": "11.0.x-dev"
},
{
"name": "laravel/framework",
- "version": "v11.3.0",
+ "version": "v11.3.1",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
- "reference": "cbcb0ee3da8c5f98497d9a282609732251a7dd1e"
+ "reference": "3b87d0767e9cbddec46480d883010ba720e50dea"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/laravel/framework/zipball/cbcb0ee3da8c5f98497d9a282609732251a7dd1e",
- "reference": "cbcb0ee3da8c5f98497d9a282609732251a7dd1e",
+ "url": "https://api.github.com/repos/laravel/framework/zipball/3b87d0767e9cbddec46480d883010ba720e50dea",
+ "reference": "3b87d0767e9cbddec46480d883010ba720e50dea",
"shasum": ""
},
"require": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2024-04-09T15:19:11+00:00"
+ "time": "2024-04-10T15:13:49+00:00"
},
{
"name": "laravel/prompts",
<x-laraknife.panels.index title="{{ __('Phrases') }}">
<x-laraknife.panels.filter legend="{{ $pagination->legendText() }}">
<x-laraknife.forms.combobox position="first" name="owner" label="Owner" :options="$optionsOwner" class="lkn-autoupdate" width2="4" />
- <x-laraknife.forms.combobox position="last" name="verifiedby" label="Verifiedby" :options="$optionsVerifiedby" class="lkn-autoupdate" width2="4" />
- <x-laraknife.forms.string position="first" name="text" label="Text" value="{{ $context->valueOf('text') }}" width2="4" />
- <x-laraknife.forms.combobox position="last" name="language" label="Language" :options="$optionsLanguage" class="lkn-autoupdate" width2="4" />
+ <x-laraknife.forms.combobox position="last" name="verified" label="Verified" :options="$optionsVerified" class="lkn-autoupdate" width2="4" />
+ <x-laraknife.forms.string position="alone" name="text" label="Text" value="{{ $context->valueOf('text') }}" width2="4" />
</x-laraknife.panels.filter>
<x-laraknife.panels.sortable-table :context="$context" :pagination="$pagination">
<thead>
<tr>
<th></th>
<th sortId="phrase">{{__('Phrase')}}</th>
- <th sortId="language_scope">{{__('Language')}}</th>
- <th sortId="owner_id">{{__('Owner')}}</th>
- <th sortId="verifiedby_id">{{__('Verifiedby')}}</th>
+ <th sortId="translation">{{__('Translation')}}</th>
<th></th>
</tr>
</thead>
<tr>
<td><x-laraknife.icons.change-record module="phrase" no="{{ $phrase->id }}" /></td>
<td>{{$phrase->phrase}}</td>
- <td> {{ __($phrase->language_scope) }}</td>
- <td>{{$phrase->owner_id}}</td>
- <td>{{$phrase->verifiedby_id}}</td>
+ <td> {{ __($phrase->translation) }}</td>
<td><x-laraknife.icons.delete-record module="phrase" no="{{ $phrase->id }}" /></td>
</tr>
@endforeach