Skip to content

Commit e5d3732

Browse files
committed
refactor: migrated translate category page to controller (#3257)
1 parent 02606e7 commit e5d3732

File tree

7 files changed

+141
-179
lines changed

7 files changed

+141
-179
lines changed

phpmyfaq/admin/category.translate.php

Lines changed: 0 additions & 92 deletions
This file was deleted.

phpmyfaq/admin/header.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@
180180
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('editconfig', 'system', 'ad_system_info', 'system');
181181

182182
switch ($action) {
183-
case 'translatecategory':
184183
case 'faqs-overview':
185184
case 'editentry':
186185
case 'copyentry':

phpmyfaq/admin/index.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,6 @@
268268
require 'faqs.editor.php';
269269
break;
270270
// category administration
271-
case 'translatecategory':
272-
require 'category.translate.php';
273-
break;
274271
case 'showcategory':
275272
require 'category.showstructure.php';
276273
break;
Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,99 @@
1-
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
2-
<h1 class="h2">
3-
<i aria-hidden="true" class="bi bi-folder"></i> {{ ad_categ_trans_1 }} {{ ad_categ_trans_2 }}:
4-
<em>{{ categoryName }}</em>
5-
</h1>
6-
</div>
7-
<div class="row">
8-
<div class="col-lg-12">
9-
<form action="?action=updatecategory" method="post" accept-charset="utf-8">
10-
<input type="hidden" name="id" value="{{ categoryId }}">
11-
<input type="hidden" name="parent_id" value="{{ category.parent_id }}">
12-
<input type="hidden" name="group_id" value="{{ category.group_id }}">
13-
<input type="hidden" name="showcat" value="{{ showcat }}">
14-
<input type="hidden" name="active" value="{{ category.active }}">
15-
{% if permLevel != basic %}
16-
<input type="hidden" name="restricted_groups[]" value="{{ groupPermission }}">
17-
{% else %}
18-
<input type="hidden" name="restricted_groups[]" value="-1">
19-
{% endif %}
20-
<input type="hidden" name="restricted_users" value="{{ userPermission }}">
21-
<input type="hidden" name="csrf" id="csrf" value="{{ csrf }}">
1+
{% extends '@admin/index.twig' %}
222

23-
<div class="row mb-2">
24-
<label class="col-lg-2 col-form-label" for="name">{{ 'categoryNameLabel' | translate }}:</label>
25-
<div class="col-lg-4">
26-
<input type="text" name="name" class="form-control" id="name">
3+
{% block content %}
4+
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
5+
<h1 class="h2">
6+
<i aria-hidden="true" class="bi bi-folder"></i> {{ ad_categ_trans_1 }} {{ ad_categ_trans_2 }}:
7+
<em>{{ categoryName }}</em>
8+
</h1>
9+
</div>
10+
<div class="row">
11+
<div class="col-lg-12">
12+
<form action="./category/update" method="post" accept-charset="utf-8">
13+
<input type="hidden" name="id" value="{{ categoryId }}">
14+
<input type="hidden" name="parent_id" value="{{ category.parent_id }}">
15+
<input type="hidden" name="group_id" value="{{ category.group_id }}">
16+
<input type="hidden" name="active" value="{{ category.active }}">
17+
{% if permLevel != basic %}
18+
<input type="hidden" name="restricted_groups[]" value="{{ groupPermission }}">
19+
{% else %}
20+
<input type="hidden" name="restricted_groups[]" value="-1">
21+
{% endif %}
22+
<input type="hidden" name="restricted_users" value="{{ userPermission }}">
23+
{{ csrfInputToken | raw }}
24+
25+
<div class="row mb-2">
26+
<label class="col-lg-2 col-form-label" for="name">{{ 'categoryNameLabel' | translate }}:</label>
27+
<div class="col-lg-4">
28+
<input type="text" name="name" class="form-control" id="name">
29+
</div>
2730
</div>
28-
</div>
2931

30-
<div class="row mb-2">
31-
<label class="col-lg-2 col-form-label" for="catlang">{{ ad_categ_lang }}:</label>
32-
<div class="col-lg-4">
33-
<select name="catlang" id="catlang" class="form-select">
34-
{{ langToTranslate|raw }}
35-
</select>
32+
<div class="row mb-2">
33+
<label class="col-lg-2 col-form-label" for="catlang">{{ ad_categ_lang }}:</label>
34+
<div class="col-lg-4">
35+
<select name="catlang" id="catlang" class="form-select">
36+
{{ langToTranslate|raw }}
37+
</select>
38+
</div>
3639
</div>
37-
</div>
3840

39-
<div class="row mb-2">
40-
<label class="col-lg-2 col-form-label">{{ 'categoryDescriptionLabel' | translate }}</label>
41-
<div class="col-lg-4">
42-
<textarea name="description" rows="3" class="form-control"></textarea>
41+
<div class="row mb-2">
42+
<label class="col-lg-2 col-form-label">{{ 'categoryDescriptionLabel' | translate }}</label>
43+
<div class="col-lg-4">
44+
<textarea name="description" rows="3" class="form-control"></textarea>
45+
</div>
4346
</div>
44-
</div>
4547

46-
<div class="row mb-2">
47-
<label class="col-lg-2 col-form-label">
48-
{{ 'categoryOwnerLabel' | translate }}
49-
</label>
50-
<div class="col-lg-4">
51-
<select name="user_id" class="form-control">
52-
{{ userOptions|raw }}
53-
</select>
48+
<div class="row mb-2">
49+
<label class="col-lg-2 col-form-label">
50+
{{ 'categoryOwnerLabel' | translate }}
51+
</label>
52+
<div class="col-lg-4">
53+
<select name="user_id" class="form-control">
54+
{{ userOptions|raw }}
55+
</select>
56+
</div>
5457
</div>
55-
</div>
5658

57-
<!-- SERP Title -->
58-
<div class="row mb-2">
59-
<label class="col-lg-2 col-form-label" for="serpTitle">{{ 'msgSerpTitle' | translate }}</label>
60-
<div class="col-lg-4">
61-
<input type="text" name="serpTitle" id="serpTitle" value="" class="form-control">
59+
<!-- SERP Title -->
60+
<div class="row mb-2">
61+
<label class="col-lg-2 col-form-label" for="serpTitle">{{ 'msgSerpTitle' | translate }}</label>
62+
<div class="col-lg-4">
63+
<input type="text" name="serpTitle" id="serpTitle" value="" class="form-control">
64+
</div>
6265
</div>
63-
</div>
6466

65-
<!-- SERP Description -->
66-
<div class="row mb-2">
67-
<label class="col-lg-2 col-form-label" for="serpDescription">{{ 'msgSerpDescription' | translate }}</label>
68-
<div class="col-lg-4">
69-
<textarea type="text" name="serpDescription" id="serpDescription" rows="5" class="form-control">
70-
</textarea>
67+
<!-- SERP Description -->
68+
<div class="row mb-2">
69+
<label class="col-lg-2 col-form-label" for="serpDescription">{{ 'msgSerpDescription' | translate }}</label>
70+
<div class="col-lg-4">
71+
<textarea type="text" name="serpDescription" id="serpDescription" rows="5" class="form-control">
72+
</textarea>
73+
</div>
7174
</div>
72-
</div>
7375

74-
<div class="row mb-2">
75-
<label class="col-lg-2 col-form-label">{{ ad_categ_transalready }}</label>
76-
<div class="col-lg-4">
77-
<ul class="list-unstyled">
78-
{% for language, description in langTranslated %}
79-
<input type="text" readonly class="form-control-plaintext" id="staticEmail"
80-
value="{{ language }}: {{ description }}">
81-
{% endfor %}
82-
</ul>
76+
<div class="row mb-2">
77+
<label class="col-lg-2 col-form-label">{{ ad_categ_transalready }}</label>
78+
<div class="col-lg-4">
79+
<ul class="list-unstyled">
80+
{% for language, description in langTranslated %}
81+
<input type="text" readonly class="form-control-plaintext" id="staticEmail"
82+
value="{{ language }}: {{ description }}">
83+
{% endfor %}
84+
</ul>
85+
</div>
8386
</div>
84-
</div>
8587

86-
<div class="row">
87-
<div class="offset-lg-2 col-lg-4">
88-
<button class="btn btn-primary" type="submit" name="submit">
89-
{{ ad_categ_translatecateg }}
90-
</button>
88+
<div class="row">
89+
<div class="offset-lg-2 col-lg-4">
90+
<button class="btn btn-primary" type="submit" name="submit">
91+
{{ ad_categ_translatecateg }}
92+
</button>
93+
</div>
9194
</div>
92-
</div>
9395

94-
</form>
96+
</form>
97+
</div>
9598
</div>
96-
</div>
99+
{% endblock %}

phpmyfaq/src/admin-routes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
'controller' => [CategoryController::class, 'edit'],
9393
'methods' => 'GET'
9494
],
95+
'admin.category.translate' => [
96+
'path' => '/category/translate/{categoryId}',
97+
'controller' => [CategoryController::class, 'translate'],
98+
'methods' => 'POST'
99+
],
95100
'admin.category.update' => [
96101
'path' => '/category/update',
97102
'controller' => [CategoryController::class, 'update'],

phpmyfaq/src/phpMyFAQ/Controller/Administration/AbstractAdministrationController.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,6 @@ protected function getHeader(Request $request): array
223223
);
224224

225225
switch ($action) {
226-
case 'category-overview':
227-
case 'savecategory':
228-
case 'translatecategory':
229-
case 'updatecategory':
230-
case 'showcategory':
231226
case 'faqs-overview':
232227
case 'editentry':
233228
case 'copyentry':

phpmyfaq/src/phpMyFAQ/Controller/Administration/CategoryController.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use phpMyFAQ\Enums\PermissionType;
1515
use phpMyFAQ\Enums\SeoType;
1616
use phpMyFAQ\Filter;
17+
use phpMyFAQ\Helper\UserHelper;
1718
use phpMyFAQ\Language\LanguageCodes;
1819
use phpMyFAQ\Session\Token;
1920
use phpMyFAQ\Translation;
@@ -399,6 +400,60 @@ public function edit(Request $request): Response
399400
);
400401
}
401402

403+
/**
404+
* @throws Exception
405+
* @throws LoaderError
406+
* @throws \Exception
407+
*/
408+
#[Route('/category/translate/:categoryId', name: 'admin.category.translate', methods: ['GET'])]
409+
public function translate(Request $request): Response
410+
{
411+
$this->userHasPermission(PermissionType::CATEGORY_EDIT);
412+
413+
[ $currentAdminUser, $currentAdminGroups ] = CurrentUser::getCurrentUserGroupId($this->currentUser);
414+
415+
$session = $this->container->get('session');
416+
417+
$categoryPermission = new Permission($this->configuration);
418+
$userHelper = new UserHelper($this->currentUser);
419+
420+
$category = new Category($this->configuration, [], false);
421+
$category->setUser($currentAdminUser);
422+
$category->setGroups($currentAdminGroups);
423+
424+
$id = Filter::filterVar($request->get('categoryId'), FILTER_VALIDATE_INT);
425+
426+
$userPermission = $categoryPermission->get(Permission::USER, [$id]);
427+
$groupPermission = $categoryPermission->get(Permission::GROUP, [$id]);
428+
429+
return $this->render(
430+
'@admin/content/category.translate.twig',
431+
[
432+
... $this->getHeader($request),
433+
... $this->getFooter(),
434+
'categoryName' => $category->categoryName[$id]['name'],
435+
'ad_categ_trans_1' => Translation::get('ad_categ_trans_1'),
436+
'ad_categ_trans_2' => Translation::get('ad_categ_trans_2'),
437+
'categoryId' => $id,
438+
'category' => $category->categoryName[$id],
439+
'permLevel' => $this->configuration->get('security.permLevel'),
440+
'groupPermission' => $groupPermission[0],
441+
'userPermission' => $userPermission[0],
442+
'csrfInputToken' => Token::getInstance($session)->getTokenInput('update-category'),
443+
'categoryNameLabel' => Translation::get('categoryNameLabel'),
444+
'ad_categ_lang' => Translation::get('ad_categ_lang'),
445+
'langToTranslate' => $category->getCategoryLanguagesToTranslate($id, 'de'),
446+
'categoryDescriptionLabel' => Translation::get('categoryDescriptionLabel'),
447+
'categoryOwnerLabel' => Translation::get('categoryOwnerLabel'),
448+
'userOptions' => $userHelper->getAllUserOptions((int) $category->categoryName[$id]['user_id']),
449+
'ad_categ_transalready' => Translation::get('ad_categ_transalready'),
450+
'langTranslated' => $category->getCategoryLanguagesTranslated($id),
451+
'ad_categ_translatecateg' => Translation::get('ad_categ_translatecateg')
452+
453+
],
454+
);
455+
}
456+
402457
/**
403458
* @throws Exception
404459
* @throws LoaderError

0 commit comments

Comments
 (0)