-
-
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
7 changed files
with
142 additions
and
40 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
41 changes: 41 additions & 0 deletions
41
phpmyfaq/src/phpMyFAQ/Api/Controller/AttachmentController.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,41 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Attachment\AttachmentException; | ||
use phpMyFAQ\Attachment\AttachmentFactory; | ||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Filter; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class AttachmentController | ||
{ | ||
public function list(Request $request): JsonResponse | ||
{ | ||
$response = new JsonResponse(); | ||
$faqConfig = Configuration::getConfigurationInstance(); | ||
|
||
$recordId = Filter::filterVar($request->get('recordId'), FILTER_VALIDATE_INT); | ||
|
||
$attachments = $result = []; | ||
try { | ||
$attachments = AttachmentFactory::fetchByRecordId($faqConfig, $recordId); | ||
} catch (AttachmentException) { | ||
$result = []; | ||
} | ||
foreach ($attachments as $attachment) { | ||
$result[] = [ | ||
'filename' => $attachment->getFilename(), | ||
'url' => $faqConfig->getDefaultUrl() . $attachment->buildUrl(), | ||
]; | ||
} | ||
if (count($result) === 0) { | ||
$response->setStatusCode(Response::HTTP_NOT_FOUND); | ||
} | ||
$response->setData($result); | ||
|
||
return $response; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
phpmyfaq/src/phpMyFAQ/Api/Controller/CommentController.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,46 @@ | ||
<?php | ||
|
||
/** | ||
* The Comemnt 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-30 | ||
*/ | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Comments; | ||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Entity\CommentType; | ||
use phpMyFAQ\Filter; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class CommentController | ||
{ | ||
public function list(Request $request): JsonResponse | ||
{ | ||
$response = new JsonResponse(); | ||
$faqConfig = Configuration::getConfigurationInstance(); | ||
|
||
$recordId = Filter::filterVar($request->get('recordId'), FILTER_VALIDATE_INT); | ||
|
||
$comment = new Comments($faqConfig); | ||
$result = $comment->getCommentsData($recordId, CommentType::FAQ); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\News; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class NewsController | ||
{ | ||
public function list(): JsonResponse | ||
{ | ||
$response = new JsonResponse(); | ||
$faqConfig = Configuration::getConfigurationInstance(); | ||
|
||
$news = new News($faqConfig); | ||
$result = $news->getLatestData(false, true, true); | ||
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