-
Notifications
You must be signed in to change notification settings - Fork 0
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
Dennis Eichhorn
committed
Feb 4, 2024
1 parent
ff5cad2
commit d332790
Showing
5 changed files
with
162 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Jingga | ||
* | ||
* PHP Version 8.1 | ||
* | ||
* @package Modules\Media\Admin\Install | ||
* @copyright Dennis Eichhorn | ||
* @license OMS License 2.0 | ||
* @version 1.0.0 | ||
* @link https://jingga.app | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Modules\Media\Admin\Install; | ||
|
||
use phpOMS\Application\ApplicationAbstract; | ||
|
||
/** | ||
* Search class. | ||
* | ||
* @package Modules\Media\Admin\Install | ||
* @license OMS License 2.0 | ||
* @link https://jingga.app | ||
* @since 1.0.0 | ||
*/ | ||
final class Search | ||
{ | ||
/** | ||
* Install navigation providing | ||
* | ||
* @param ApplicationAbstract $app Application | ||
* @param string $path Module path | ||
* | ||
* @return void | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public static function install(ApplicationAbstract $app, string $path) : void | ||
{ | ||
\Modules\Search\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/SearchCommands.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,32 @@ | ||
<?php | ||
/** | ||
* Jingga | ||
* | ||
* PHP Version 8.1 | ||
* | ||
* @package Modules\Media | ||
* @copyright Dennis Eichhorn | ||
* @license OMS License 2.0 | ||
* @version 1.0.0 | ||
* @link https://jingga.app | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Modules\Media\Controller\SearchController; | ||
use Modules\Media\Models\PermissionCategory; | ||
use phpOMS\Account\PermissionType; | ||
use phpOMS\Router\RouteVerb; | ||
|
||
return [ | ||
'^(?!:).+.*?' => [ | ||
[ | ||
'dest' => '\Modules\Media\Controller\SearchController:searchGeneral', | ||
'verb' => RouteVerb::ANY, | ||
'permission' => [ | ||
'module' => SearchController::NAME, | ||
'type' => PermissionType::READ, | ||
'state' => PermissionCategory::MEDIA, | ||
], | ||
], | ||
], | ||
]; |
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,76 @@ | ||
<?php | ||
/** | ||
* Jingga | ||
* | ||
* PHP Version 8.1 | ||
* | ||
* @package Modules\Media | ||
* @copyright Dennis Eichhorn | ||
* @license OMS License 2.0 | ||
* @version 1.0.0 | ||
* @link https://jingga.app | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Modules\Media\Controller; | ||
|
||
use Modules\Media\Models\MediaMapper; | ||
use phpOMS\DataStorage\Database\Query\OrderType; | ||
use phpOMS\Message\RequestAbstract; | ||
use phpOMS\Message\ResponseAbstract; | ||
use phpOMS\System\MimeType; | ||
|
||
/** | ||
* Search class. | ||
* | ||
* @package Modules\Media | ||
* @license OMS License 2.0 | ||
* @link https://jingga.app | ||
* @since 1.0.0 | ||
*/ | ||
final class SearchController extends Controller | ||
{ | ||
/** | ||
* Api method to search for tags | ||
* | ||
* @param RequestAbstract $request Request | ||
* @param ResponseAbstract $response Response | ||
* @param array $data Generic data | ||
* | ||
* @return void | ||
* | ||
* @api | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public function searchGeneral(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void | ||
{ | ||
/** @var \Modules\Media\Models\Media[] $media */ | ||
$media = MediaMapper::getAll() | ||
->with('tags') | ||
->with('tags/title') | ||
->where('name', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE') | ||
->where('tags/title/language', $response->header->l11n->language) | ||
->sort('createdAt', OrderType::DESC) | ||
->limit(8) | ||
->execute(); | ||
|
||
$results = []; | ||
foreach ($media as $file) { | ||
$results[] = [ | ||
'title' => $file->name . ' (' . $file->extension . ')', | ||
'summary' => '', | ||
'link' => '{/base}/media/view?id=' . $file->id, | ||
'account' => '', | ||
'createdAt' => $file->createdAt, | ||
'image' => '', | ||
'tags' => $file->tags, | ||
'type' => 'list_links', | ||
'module' => 'Media', | ||
]; | ||
} | ||
|
||
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); | ||
$response->add($request->uri->__toString(), $results); | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"id": "{id}", | ||
"title": "{title}", | ||
"content": "{content}", | ||
"extension": "{extension}", | ||
"path": "{path}", | ||
"types": ["{types}"], | ||
"tags": ["{tags}"] | ||
} |
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 |
---|---|---|
|
@@ -24,7 +24,8 @@ | |
}, | ||
"providing": { | ||
"Navigation": "*", | ||
"Media": "*" | ||
"Media": "*", | ||
"Search": "*" | ||
}, | ||
"load": [ | ||
{ | ||
|