Skip to content

Commit

Permalink
Init module files da legacy demo-farm-add-ons.
Browse files Browse the repository at this point in the history
  • Loading branch information
pMononoke committed Sep 4, 2023
1 parent 8c51942 commit f7fb400
Show file tree
Hide file tree
Showing 24 changed files with 799 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"forward-command": false,
"target-directory": "tools"
},
"oe-module-demo-farm-add-ons": {
"oe-module-marketplace": {
"openemr-supported-version": [
"v7_0_1_1",
"v7_0_1"
Expand Down
46 changes: 46 additions & 0 deletions config/di/monolog.php
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;
// }),
];
}
22 changes: 22 additions & 0 deletions config/di/service.php
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(),
];
29 changes: 29 additions & 0 deletions config/di/twig.php
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,
];
1 change: 1 addition & 0 deletions info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Module Marketplace
12 changes: 12 additions & 0 deletions moduleSettings.php
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' => []
]
;
37 changes: 37 additions & 0 deletions openemr.bootstrap.php
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');
8 changes: 8 additions & 0 deletions public/.htaccess
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]
78 changes: 78 additions & 0 deletions public/index.php
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))();
}
53 changes: 53 additions & 0 deletions src/Adapter/Http/Web/DefaultController.php
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);
}
}
46 changes: 46 additions & 0 deletions src/Adapter/Http/Web/NotFoundController.php
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>
';
}
}
28 changes: 28 additions & 0 deletions src/Adapter/Http/Web/Templates/base.html.twig
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>
11 changes: 11 additions & 0 deletions src/Adapter/Http/Web/Templates/packagist/_form.html.twig
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>

Loading

0 comments on commit f7fb400

Please sign in to comment.