-
-
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.
Init module files da legacy demo-farm-add-ons.
- Loading branch information
Showing
24 changed files
with
799 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
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 | ||
|
||
declare(strict_types=1); | ||
|
||
use Monolog\Formatter\LineFormatter; | ||
use Monolog\Handler\StreamHandler; | ||
use Monolog\Logger; | ||
use Psr\Log\LoggerInterface; | ||
|
||
if (\OpenEMR\Modules\DemoFarmAddOns\Module::isStandAlone()) { | ||
/** | ||
* Logging in module 'var' directory when the module | ||
* is executed as stand-alone mode | ||
*/ | ||
return [ | ||
// LoggerInterface::class => DI\factory(function () { | ||
// $logger = new Logger('module-todo-list'); | ||
// $moduleProjectDir = \dirname(__DIR__, 3); | ||
// $fileHandler = new StreamHandler($moduleProjectDir . '/var/log/module.log', Logger::DEBUG); | ||
// $fileHandler->setFormatter(new LineFormatter()); | ||
// $logger->pushHandler($fileHandler); | ||
// | ||
// return $logger; | ||
// }), | ||
// 'logger' => DI\get(LoggerInterface::class), | ||
]; | ||
} else { | ||
/** | ||
* Logging in epenemr 'Documents' directory when the module | ||
* is executed inside openemr | ||
* TODO: change path, use openemr Documents dir | ||
* or change module folder permission after installation | ||
* chown apache:root -R interface/modules/custom_modules/oe-module-todo-list/ | ||
*/ | ||
return [ | ||
// Psr\Log\LoggerInterface::class => DI\factory(function () { | ||
// $logger = new Logger('module-todo-list'); | ||
// $moduleProjectDir = \dirname(__DIR__, 3); | ||
// $fileHandler = new StreamHandler($moduleProjectDir . '/var/log/module.log', Logger::DEBUG); | ||
// $fileHandler->setFormatter(new LineFormatter()); | ||
// $logger->pushHandler($fileHandler); | ||
// | ||
// return $logger; | ||
// }), | ||
]; | ||
} |
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,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Http\Discovery\HttpClientDiscovery; | ||
|
||
|
||
use OpenEMR\Modules\Marketplace\Adapter\Http\Web\DefaultController; | ||
use OpenEMR\Modules\Marketplace\Adapter\Http\Web\NotFoundController; | ||
use OpenEMR\Modules\Marketplace\Finder\ModuleFinder; | ||
use OpenEMR\Modules\Marketplace\Finder\PackagistModuleFinder; | ||
use Twig\Environment; | ||
|
||
return [ | ||
PackagistModuleFinder::class => DI\create() | ||
->constructor(DI\factory([HttpClientDiscovery::class, 'find'])), | ||
|
||
ModuleFinder::class => DI\create(PackagistModuleFinder::class), | ||
|
||
DefaultController::class => DI\create() | ||
->constructor(DI\get(ModuleFinder::class), DI\get(Environment::class)), | ||
|
||
NotFoundController::class => new NotFoundController(), | ||
]; |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
use src\Module; | ||
use Twig\Environment; | ||
use Twig\Loader\FilesystemLoader; | ||
|
||
$loader = new FilesystemLoader([ | ||
Module::mainDir() . '/src/Adapter/Http/Web/Templates', | ||
]); | ||
|
||
$twigOptions = []; | ||
|
||
$TwigEnvironment = new Environment($loader, $twigOptions); | ||
|
||
$TwigEnvironment->addGlobal('module', [ | ||
'name' => Module::MODULE_NAME, | ||
'version' => Module::MODULE_VERSION, | ||
'source_code' => Module::MODULE_SOURCE_CODE, | ||
'vendor_name' => Module::VENDOR_NAME, | ||
'vendor_url' => Module::VENDOR_URL, | ||
'isStandAlone' => Module::isStandAlone(), | ||
]); | ||
|
||
return [ | ||
Environment::class => $TwigEnvironment, | ||
]; |
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 @@ | ||
Module Marketplace |
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,12 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* @see pag. 16 - https://www.open-emr.org/wiki/images/6/61/ModuleInstaller-DeveloperGuide.pdf - custom module section. | ||
*/ | ||
|
||
$MODULESETTINGS = | ||
[ | ||
'ACL' => [], | ||
'hooks' => [] | ||
] | ||
; |
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,37 @@ | ||
<?php | ||
|
||
use OpenEMR\Menu\MenuEvent; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
function oe_module_marketplace_add_menu_item(MenuEvent $event) | ||
{ | ||
$menu = $event->getMenu(); | ||
|
||
$menuItem = new stdClass(); | ||
$menuItem->requirement = 0; | ||
$menuItem->target = 'mod'; | ||
$menuItem->menu_id = 'mod0'; | ||
$menuItem->label = xlt("Modules Marketplace"); | ||
$menuItem->url = "/interface/modules/custom_modules/oe-module-marketplace/public/index.php"; | ||
$menuItem->children = []; | ||
$menuItem->acl_req = []; | ||
$menuItem->global_req = [""]; | ||
|
||
foreach ($menu as $item) { | ||
if ($item->menu_id == 'modimg') { | ||
$item->children[] = $menuItem; | ||
break; | ||
} | ||
} | ||
|
||
$event->setMenu($menu); | ||
|
||
return $event; | ||
} | ||
/** | ||
* @var EventDispatcherInterface $eventDispatcher | ||
* @var array $module | ||
* @global $eventDispatcher @see ModulesApplication::loadCustomModule | ||
* @global $module @see ModulesApplication::loadCustomModule | ||
*/ | ||
$eventDispatcher->addListener(MenuEvent::MENU_UPDATE, 'oe_module_marketplace_add_menu_item'); |
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,8 @@ | ||
## | ||
## ACCESS RULES FOR DEMO FARM MODULE | ||
RewriteEngine On | ||
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 | ||
RewriteCond %{REQUEST_FILENAME} !-f | ||
RewriteCond %{REQUEST_FILENAME} !-d | ||
RewriteCond %{REQUEST_FILENAME} !-l | ||
RewriteRule (.*) index.php?_REWRITE_COMMAND=$1 [QSA,L] |
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,78 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* This file is required, see official guidelines. | ||
* The guide not clarifying the content and the supposed intent. | ||
* | ||
* @see pag. 15 - https://www.open-emr.org/wiki/images/6/61/ModuleInstaller-DeveloperGuide.pdf - custom module section. | ||
*/ | ||
|
||
use Laminas\HttpHandlerRunner\Emitter\SapiStreamEmitter; | ||
use Nyholm\Psr7\Factory\Psr17Factory; | ||
use Nyholm\Psr7Server\ServerRequestCreator; | ||
|
||
|
||
use OpenEMR\Modules\Marketplace\Adapter\Http\Web\DefaultController; | ||
use OpenEMR\Modules\Marketplace\Adapter\Http\Web\NotFoundController; | ||
use OpenEMR\Modules\Marketplace\Finder\PackagistModuleFinder; | ||
use Psr\Container\ContainerInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use src\Module; | ||
use Twig\Environment; | ||
|
||
require __DIR__ . '/../src/Module.php'; | ||
|
||
if (Module::isStandAlone()) { | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
} else { | ||
require __DIR__ . '/../../../../../vendor/autoload.php'; | ||
} | ||
|
||
|
||
$module = Module::bootstrap(); | ||
|
||
$psr17Factory = new Psr17Factory(); | ||
$serverRequestFactory = new ServerRequestCreator( | ||
$psr17Factory, // serverRequestFactory | ||
$psr17Factory, // uriFactory | ||
$psr17Factory, // uploadedFileFactory | ||
$psr17Factory // streamFactory | ||
); | ||
|
||
$request = $serverRequestFactory->fromGlobals(); | ||
|
||
/** | ||
* Integrating with Legacy Sessions here, if needed. | ||
*/ | ||
|
||
|
||
$response = routerMatch($request, $module->getContainer()); | ||
|
||
(new SapiStreamEmitter())->emit($response); | ||
|
||
|
||
/** | ||
* | ||
* Naive router | ||
*/ | ||
function routerMatch(ServerRequestInterface $request, ContainerInterface $container): ResponseInterface | ||
{ | ||
/** if ($request->getUri()->getPath() === '/interface/modules/custom_modules/oe-module-marketplace/api/search/' || | ||
$request->getUri()->getPath() === '/interface/modules/custom_modules/oe-module-marketplace/api/search') { | ||
return (new ApiController($container->get(PackagistModuleFinder::class)))($request); | ||
}*/ | ||
|
||
if ($request->getUri()->getPath() === '/interface/modules/custom_modules/oe-module-marketplace/public/index.php' || | ||
$request->getUri()->getPath() === '/interface/modules/custom_modules/oe-module-marketplace/public' || | ||
$request->getUri()->getPath() === '/interface/modules/custom_modules/oe-module-marketplace/public/' || | ||
$request->getUri()->getPath() === '/') { | ||
|
||
|
||
// TODO use container | ||
return (new DefaultController($container->get(PackagistModuleFinder::class), $container->get(Environment::class)))($request); | ||
//return ($container->get(DefaultController::class))($request); | ||
} | ||
|
||
return ($container->get(NotFoundController::class))(); | ||
} |
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,53 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenEMR\Modules\Marketplace\Adapter\Http\Web; | ||
|
||
use Nyholm\Psr7\Factory\Psr17Factory; | ||
|
||
use OpenEMR\Modules\Marketplace\Finder\ModuleFinder; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Twig\Environment; | ||
|
||
class DefaultController | ||
{ | ||
/** | ||
* @var ModuleFinder | ||
*/ | ||
private $moduleFinder; | ||
|
||
/** | ||
* @var Environment | ||
*/ | ||
private $twigEnvironment; | ||
|
||
public function __construct(ModuleFinder $moduleFinder, Environment $twigEnvironment) | ||
{ | ||
$this->moduleFinder = $moduleFinder; | ||
$this->twigEnvironment = $twigEnvironment; | ||
} | ||
|
||
public function __invoke(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
if ($request->getParsedBody() !== null) { | ||
$searchTerm = $request->getParsedBody()['searchTerm']; | ||
} else { | ||
$searchTerm = ''; | ||
} | ||
|
||
try { | ||
$collection = $this->moduleFinder->searchModule($searchTerm)->getItems(); | ||
$content = $this->twigEnvironment->render('packagist/default.html.twig', [ | ||
'items' => $collection, | ||
'searchTerm' => $searchTerm, | ||
]); | ||
} catch (\Exception $exception) { | ||
//TODO | ||
} | ||
|
||
$psr17Factory = new Psr17Factory(); | ||
$responseBody = $psr17Factory->createStream($content); | ||
|
||
return $psr17Factory->createResponse(200)->withBody($responseBody); | ||
} | ||
} |
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 declare(strict_types=1); | ||
|
||
namespace OpenEMR\Modules\Marketplace\Adapter\Http\Web; | ||
|
||
use Nyholm\Psr7\Factory\Psr17Factory; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class NotFoundController | ||
{ | ||
public function __invoke(): ResponseInterface | ||
{ | ||
$psr17Factory = new Psr17Factory(); | ||
$responseBody = $psr17Factory->createStream($this->content()); | ||
|
||
return $psr17Factory->createResponse(200)->withBody($responseBody); | ||
} | ||
|
||
private function content(): string | ||
{ | ||
return ' | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Demo Farm - Not Found</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
</head> | ||
<body> | ||
<div class="container-fluid main-container" style="margin-top:50px"> | ||
<div class="row justify-content-center"> | ||
<div class="col-md-10 col-md-offset-1 content"> | ||
<h3> | ||
404 Page Not Found. | ||
</h3> | ||
<a href="/interface/modules/custom_modules/oe-module-demo-farm-add-ons/index.php">back to index</a> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
'; | ||
} | ||
} |
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,28 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>{% block title %}Demo Farm {% endblock %}</title> | ||
|
||
{% block header %} {% endblock %} | ||
|
||
{% block module_stylesheets %} | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous"> | ||
{% endblock %} | ||
</head> | ||
<body> | ||
{% block body %}{% endblock %} | ||
|
||
{% block footer %}{% endblock %} | ||
|
||
{% block javascripts %} | ||
{% endblock %} | ||
|
||
|
||
{% block module_javascripts %} | ||
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script> | ||
{% endblock %} | ||
</body> | ||
</html> |
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,11 @@ | ||
<form id="searchForm" class="form form-inline" role="form" enctype="application/x-www-form-urlencoded" method="POST" action="/interface/modules/custom_modules/oe-module-demo-farm-add-ons"> | ||
<div class="row"> | ||
<div class="form-group"> | ||
<input class="form-control" type="text" value="{{ searchTerm }}" id="searchTerm" name="searchTerm"> | ||
</div> | ||
<div class="form-group mx-1"> | ||
<input type="submit" class="btn btn-info" value="Search" title="Search" /> | ||
</div> | ||
</div> | ||
</form> | ||
|
Oops, something went wrong.