-
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
209 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
phpmyfaq/src/phpMyFAQ/Api/Controller/CategoryController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* The Category Controller for the REST API | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <thorsten@phpmyfaq.de> | ||
* @copyright 2023 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2023-07-29 | ||
*/ | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Category; | ||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Language; | ||
use phpMyFAQ\User\CurrentUser; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class CategoryController | ||
{ | ||
public function list(): JsonResponse | ||
{ | ||
$response = new JsonResponse(); | ||
$faqConfig = Configuration::getConfigurationInstance(); | ||
$language = new Language($faqConfig); | ||
$currentLanguage = $language->setLanguageByAcceptLanguage(); | ||
|
||
$user = CurrentUser::getCurrentUser($faqConfig); | ||
[ $currentUser, $currentGroups ] = CurrentUser::getCurrentUserGroupId($user); | ||
|
||
$category = new Category($faqConfig, $currentGroups, true); | ||
$category->setUser($currentUser); | ||
$category->setGroups($currentGroups); | ||
$category->setLanguage($currentLanguage); | ||
$result = array_values($category->getAllCategories()); | ||
|
||
if (count($result) === 0) { | ||
$response->setStatusCode(Response::HTTP_NOT_FOUND); | ||
} else { | ||
$response->setStatusCode(Response::HTTP_OK); | ||
} | ||
$response->setData($result); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/** | ||
* The Group Controller for the REST API | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <thorsten@phpmyfaq.de> | ||
* @copyright 2023 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2023-07-29 | ||
*/ | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Permission\MediumPermission; | ||
use phpMyFAQ\User\CurrentUser; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class GroupController | ||
{ | ||
public function list(): JsonResponse | ||
{ | ||
$response = new JsonResponse(); | ||
$faqConfig = Configuration::getConfigurationInstance(); | ||
$user = CurrentUser::getCurrentUser($faqConfig); | ||
|
||
$groupPermission = new MediumPermission($faqConfig); | ||
$result = $groupPermission->getAllGroups($user); | ||
if ((is_countable($result) ? count($result) : 0) === 0) { | ||
$response->setStatusCode(Response::HTTP_NOT_FOUND); | ||
} | ||
$response->setData($result); | ||
|
||
return $response; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
phpmyfaq/src/phpMyFAQ/Api/Controller/OpenQuestionController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Question; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class OpenQuestionController | ||
{ | ||
public function list(): JsonResponse | ||
{ | ||
$response = new JsonResponse(); | ||
$faqConfig = Configuration::getConfigurationInstance(); | ||
|
||
$questions = new Question($faqConfig); | ||
$result = $questions->getAllOpenQuestions(); | ||
if ((is_countable($result) ? count($result) : 0) === 0) { | ||
$response->setStatusCode(Response::HTTP_NOT_FOUND); | ||
} | ||
$response->setData($result); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Tags; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class TagController | ||
{ | ||
public function list(): JsonResponse | ||
{ | ||
$response = new JsonResponse(); | ||
$faqConfig = Configuration::getConfigurationInstance(); | ||
|
||
$tags = new Tags($faqConfig); | ||
$result = $tags->getPopularTagsAsArray(16); | ||
if ((is_countable($result) ? count($result) : 0) === 0) { | ||
$response->setStatusCode(Response::HTTP_NOT_FOUND); | ||
} | ||
$response->setData($result); | ||
|
||
return $response; | ||
} | ||
} |