$optionsPhrase = DbHelper::comboboxDataOfTable('words', 'name', 'id', $fields['phrase_id'], __('<Please select>'));
$optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner_id'], __('<Please select>'));
$optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby_id'], __('<Please select>'));
- $context = new ContextLaraKnife($request, $fields);
+ $context = new ContextLaraKnife($request, $fields);
$rc = view('phrase.create', [
'context' => $context,
'optionsLanguage' => $optionsLanguage,
'optionsPhrase' => $optionsPhrase,
'optionsOwner' => $optionsOwner,
'optionsVerifiedby' => $optionsVerifiedby,
- ]);
+ ]);
}
return $rc;
}
$rc = redirect('/phrase-index');
} else {
$fields = $request->all();
- if (count($fields) === 0) {
+ if (count($fields) === 1){
$fields = [
'phrase' => '',
- 'language_scope' => '',
- 'word_id' => '',
- 'phrase_id' => '',
- 'owner_id' => '',
- 'verifiedby_id' => ''
- ];
+ 'language' => $request->language,
+ 'lastLanguage' => '',
+ 'translation' => ''
+ ];
+ } elseif (count($fields) === 0) {
+ $fields = [
+ 'phrase' => '',
+ 'language' => SProperty::idOfLocalization(),
+ 'lastLanguage' => '',
+ 'translation' => ''
+ ];
}
- $optionsLanguage = SProperty::optionsByScope('language', $phrase->language_scope, '');
- $optionsWord = DbHelper::comboboxDataOfTable('words', 'name', 'id', $fields['word_id'], __('<Please select>'));
- $optionsPhrase = DbHelper::comboboxDataOfTable('words', 'name', 'id', $fields['phrase_id'], __('<Please select>'));
- $optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner_id'], __('<Please select>'));
- $optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby_id'], __('<Please select>'));
- $context = new ContextLaraKnife($request, null, $phrase);
+ if ($fields['lastLanguage'] != $fields['language']){
+ $phraseTranslation = Phrase::where(['language_scope' => $fields['language'], 'phrase_id' => $phrase->id])->first();
+ if ($phraseTranslation != null){
+ $fields['translation'] = $phraseTranslation->phrase;
+ }
+ }
+ $fields['lastLanguage'] = $fields['language'];
+ $optionsLanguage = SProperty::optionsByScope('localization', $fields['language'], '');
+ $context = new ContextLaraKnife($request, $fields, $phrase);
$rc = view('phrase.edit', [
'context' => $context,
'optionsLanguage' => $optionsLanguage,
- 'optionsWord' => $optionsWord,
- 'optionsPhrase' => $optionsPhrase,
- 'optionsOwner' => $optionsOwner,
- 'optionsVerifiedby' => $optionsVerifiedby,
- ]);
+ ]);
}
return $rc;
}
} else {
$sql = 'SELECT t0.*,'
. 't1.name as language_scope, '
- . 't2.name as word_id, '
- . 't3.name as phrase_id, '
- . 't4.name as owner_id, '
- . 't5.name as verifiedby_id '
+ . '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.word_id'
- . ' LEFT JOIN sproperties t3 ON t3.id=t0.phrase_id'
- . ' LEFT JOIN sproperties t4 ON t4.id=t0.owner_id'
- . ' LEFT JOIN sproperties t5 ON t5.id=t0.verifiedby_id'
- ;
+ . ' LEFT JOIN sproperties t2 ON t2.id=t0.owner_id'
+ . ' LEFT JOIN sproperties t3 ON t3.id=t0.verifiedby_id'
+ ;
$parameters = [];
$fields = $request->all();
if (count($fields) == 0) {
$fields = [
- 'language' => '',
- 'word' => '',
- 'phrase' => '',
- 'owner' => '',
- 'verifiedby' => '',
- 'phrase' => '',
- '_sortParams' => 'id:asc'
- . ';phrase:desc'
+ 'language' => '',
+ 'word' => '',
+ 'phrase' => '',
+ 'owner' => '',
+ 'verifiedby' => '',
+ '_sortParams' => 't0.phrase:asc;t0.id:desc'
];
} else {
$conditions = [];
ViewHelper::addConditionComparism($conditions, $parameters, 'language_scope', 'language');
- ViewHelper::addConditionComparism($conditions, $parameters, 'word_id', 'word');
- ViewHelper::addConditionComparism($conditions, $parameters, 'phrase_id', 'phrase');
ViewHelper::addConditionComparism($conditions, $parameters, 'owner_id', 'owner');
ViewHelper::addConditionComparism($conditions, $parameters, 'verifiedby_id', 'verifiedby');
- ViewHelper::addConditionPattern($conditions, $parameters, 'phrase');
+ ViewHelper::addConditionPattern($conditions, $parameters, 'phrase', 'text');
$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');
- $optionsWord = DbHelper::comboboxDataOfTable('words', 'name', 'id', $fields['word'], __('<Please select>'));
- $optionsPhrase = DbHelper::comboboxDataOfTable('words', 'name', 'id', $fields['phrase'], __('<Please select>'));
$optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner'], __('<Please select>'));
$optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby'], __('<Please select>'));
$context = new ContextLaraKnife($request, $fields);
'context' => $context,
'records' => $records,
'optionsLanguage' => $optionsLanguage,
- 'optionsWord' => $optionsWord,
- 'optionsPhrase' => $optionsPhrase,
'optionsOwner' => $optionsOwner,
'optionsVerifiedby' => $optionsVerifiedby,
'pagination' => $pagination
* Returns the validation rules.
* @return array<string, string> The validation rules.
*/
- private function rules(bool $isCreate=false): array
+ private function rules(bool $isCreate = false): array
{
$rc = [
'phrase' => 'required',
- 'language_scope' => 'required',
- 'word_id' => 'required',
- 'phrase_id' => 'required',
- 'owner_id' => 'required',
- 'verifiedby_id' => 'required'
+ 'translation' => 'required',
];
+ if ($isCreate){
+ $rc['language'] = 'required';
+ }
return $rc;
}
public static function routes()
{
Route::get('/phrase-index', [PhraseController::class, 'index'])->middleware('auth');
Route::post('/phrase-index', [PhraseController::class, 'index'])->middleware('auth');
- Route::get('/phrase-create', [PhraseController::class, 'create'])->middleware('auth');
- Route::put('/phrase-store', [PhraseController::class, 'store'])->middleware('auth');
+ //Route::get('/phrase-create', [PhraseController::class, 'create'])->middleware('auth');
+ //Route::put('/phrase-store', [PhraseController::class, 'store'])->middleware('auth');
Route::post('/phrase-edit/{phrase}', [PhraseController::class, 'edit'])->middleware('auth');
Route::get('/phrase-edit/{phrase}', [PhraseController::class, 'edit'])->middleware('auth');
Route::post('/phrase-update/{phrase}', [PhraseController::class, 'update'])->middleware('auth');
if ($request->btnSubmit === 'btnCancel') {
$rc = redirect('/phrase-index')->middleware('auth');
} else {
+ $fields = $request->all();
$optionsLanguage = SProperty::optionsByScope('language', $phrase->language_scope, '');
- $optionsWord = DbHelper::comboboxDataOfTable('words', 'name', 'id', $fields['word_id'], __('<Please select>'));
- $optionsPhrase = DbHelper::comboboxDataOfTable('words', 'name', 'id', $fields['phrase_id'], __('<Please select>'));
$optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner_id'], __('<Please select>'));
$optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby_id'], __('<Please select>'));
$context = new ContextLaraKnife($request, null, $phrase);
$rc = view('phrase.show', [
'context' => $context,
'optionsLanguage' => $optionsLanguage,
- 'optionsWord' => $optionsWord,
- 'optionsPhrase' => $optionsPhrase,
'optionsOwner' => $optionsOwner,
'optionsVerifiedby' => $optionsVerifiedby,
'mode' => 'delete'
- ]);
+ ]);
}
return $rc;
}
$rc = back()->withErrors($validator)->withInput();
} else {
$validated = $validator->validated();
- $validated['phrase'] = strip_tags($validated['phrase']);
+ $validated['phrase'] = strip_tags($validated['phrase']);
+ $validated['translation'] = strip_tags($validated['translation']);
Phrase::create($validated);
}
}
- if ($rc == null){
+ if ($rc == null) {
$rc = redirect('/phrase-index');
}
return $rc;
public function update(Phrase $phrase, Request $request)
{
$rc = null;
- if ($request->btnSubmit === 'btnStore') {
+ if ($request->btnSubmit === 'btnInternal'){
+ // Language combobox has been changed:
+ $url = "/phrase-edit/$phrase->id?language=" . $request->language;
+ $rc = redirect($url);
+ } elseif ($request->btnSubmit === 'btnStore') {
+ $id = $phrase->id;
$fields = $request->all();
$validator = Validator::make($fields, $this->rules(false));
if ($validator->fails()) {
+ $errors = $validator->errors();
$rc = back()->withErrors($validator)->withInput();
} else {
$validated = $validator->validated();
$validated['phrase'] = strip_tags($validated['phrase']);
- $phrase->update($validated);
+ $validated['translation'] = strip_tags($validated['translation']);
+ // Phrase has been changed?
+ $phraseDb = Phrase::find($id);
+ if ($phrase->phrase !== $phraseDb->phrase) {
+ // Invalidate all verifications:
+ DB::update("update phrases set validatedby_id=None where phrase_id=$id;");
+ // Store new phrase:
+ $phrase->update(['phrase' => $validated['phrase'], 'verifiedby_id' => null]);
+ }
+ // Does translation already exists?
+ $phraseTranslation = Phrase::where(['language_scope' => $fields['language'], 'phrase_id' => $phrase->id])->first();
+ if ($phraseTranslation == null) {
+ // Store the new record:
+ Phrase::create([
+ 'phrase_id' => $id,
+ 'phrase' => $validated['translation'],
+ 'owner_id' => auth()->id(),
+ 'language_scope' => $fields['language']
+ ]);
+ } else {
+ // Update only if changed:
+ if ($phraseTranslation->phrase !== $validated['translation']){
+ $phraseTranslation->update(['phrase' => $validated['translation'], 'verifiedby_id' => null]);
+ }
+ }
+ $rc = redirect("/phrase-edit/$phrase->id?language=" . $fields['language']);
}
}
- if ($rc == null){
- $rc = redirect('/phrase-index');
+ if ($rc == null) {
+ $rc = redirect("/phrase-index");
}
return $rc;
}
},
{
"name": "laravel/framework",
- "version": "v11.2.0",
+ "version": "v11.3.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
- "reference": "a1750156b671f37cba702380107e2d22161c31e3"
+ "reference": "cbcb0ee3da8c5f98497d9a282609732251a7dd1e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/laravel/framework/zipball/a1750156b671f37cba702380107e2d22161c31e3",
- "reference": "a1750156b671f37cba702380107e2d22161c31e3",
+ "url": "https://api.github.com/repos/laravel/framework/zipball/cbcb0ee3da8c5f98497d9a282609732251a7dd1e",
+ "reference": "cbcb0ee3da8c5f98497d9a282609732251a7dd1e",
"shasum": ""
},
"require": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2024-04-02T14:01:33+00:00"
+ "time": "2024-04-09T15:19:11+00:00"
},
{
"name": "laravel/prompts",
- "version": "v0.1.17",
+ "version": "v0.1.18",
"source": {
"type": "git",
"url": "https://github.com/laravel/prompts.git",
- "reference": "8ee9f87f7f9eadcbe21e9e72cd4176b2f06cd5b5"
+ "reference": "3b5e6b03f1f1175574b5a32331d99c9819da9848"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/laravel/prompts/zipball/8ee9f87f7f9eadcbe21e9e72cd4176b2f06cd5b5",
- "reference": "8ee9f87f7f9eadcbe21e9e72cd4176b2f06cd5b5",
+ "url": "https://api.github.com/repos/laravel/prompts/zipball/3b5e6b03f1f1175574b5a32331d99c9819da9848",
+ "reference": "3b5e6b03f1f1175574b5a32331d99c9819da9848",
"shasum": ""
},
"require": {
],
"support": {
"issues": "https://github.com/laravel/prompts/issues",
- "source": "https://github.com/laravel/prompts/tree/v0.1.17"
+ "source": "https://github.com/laravel/prompts/tree/v0.1.18"
},
- "time": "2024-03-13T16:05:43+00:00"
+ "time": "2024-04-04T17:41:50+00:00"
},
{
"name": "laravel/serializable-closure",
},
{
"name": "league/flysystem",
- "version": "3.26.0",
+ "version": "3.27.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem.git",
- "reference": "072735c56cc0da00e10716dd90d5a7f7b40b36be"
+ "reference": "4729745b1ab737908c7d055148c9a6b3e959832f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/072735c56cc0da00e10716dd90d5a7f7b40b36be",
- "reference": "072735c56cc0da00e10716dd90d5a7f7b40b36be",
+ "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/4729745b1ab737908c7d055148c9a6b3e959832f",
+ "reference": "4729745b1ab737908c7d055148c9a6b3e959832f",
"shasum": ""
},
"require": {
],
"support": {
"issues": "https://github.com/thephpleague/flysystem/issues",
- "source": "https://github.com/thephpleague/flysystem/tree/3.26.0"
+ "source": "https://github.com/thephpleague/flysystem/tree/3.27.0"
},
"funding": [
{
"type": "github"
}
],
- "time": "2024-03-25T11:49:53+00:00"
+ "time": "2024-04-07T19:17:50+00:00"
},
{
"name": "league/flysystem-local",