diff --git a/Admin/Installer.php b/Admin/Installer.php index b0ac664..5247af8 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -14,7 +14,12 @@ declare(strict_types=1); namespace Modules\Workflow\Admin; +use phpOMS\Application\ApplicationAbstract; +use phpOMS\Message\Http\HttpRequest; +use phpOMS\Message\Http\HttpResponse; use phpOMS\Module\InstallerAbstract; +use phpOMS\System\File\PathException; +use phpOMS\Uri\HttpUri; /** * Installer class. @@ -33,4 +38,99 @@ final class Installer extends InstallerAbstract * @since 1.0.0 */ public const PATH = __DIR__; + + /** + * Install data from providing modules. + * + * @param ApplicationAbstract $app Application + * @param array $data Additional data + * + * @return array + * + * @since 1.0.0 + */ + public static function installExternal(ApplicationAbstract $app, array $data) : array + { + if (!\is_file($data['path'] ?? '')) { + throw new PathException($data['path'] ?? ''); + } + + $workflowFile = \file_get_contents($data['path'] ?? ''); + if ($workflowFile === false) { + throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore + } + + $workflowData = \json_decode($workflowFile, true) ?? []; + if ($workflowData === false) { + throw new \Exception(); // @codeCoverageIgnore + } + + if (!\is_dir(__DIR__ . '/../../../temp')) { + \mkdir(__DIR__ . '/../../../temp'); + } + + $apiApp = new class() extends ApplicationAbstract + { + protected string $appName = 'Api'; + }; + + $apiApp->dbPool = $app->dbPool; + $apiApp->orgId = $app->orgId; + $apiApp->accountManager = $app->accountManager; + $apiApp->appSettings = $app->appSettings; + $apiApp->moduleManager = $app->moduleManager; + $apiApp->eventManager = $app->eventManager; + + foreach ($workflowData as $workflow) { + self::installWorkflow($apiApp, $workflow); + } + + return []; + } + + /** + * Install application page. + * + * @param ApplicationAbstract $app Application + * @param array $data Additional data + * + * @return void + * + * @since 1.0.0 + */ + private static function installWorkflow(ApplicationAbstract $app, array $data) : void + { + /** @var \Modules\Workflow\Controller\ApiController $module */ + $module = $app->moduleManager->get('Workflow'); + + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('name', $data['name']); + + $tempPath = __DIR__ . '/../../../temp/'; + + $workflowFiles = \scandir(__DIR__ . '/../../..' . $data['path']); + foreach ($workflowFiles as $filePath) { + if (!\is_file(__DIR__ . '/../../..' . $data['path'] . '/' . $filePath) || $filePath === '..' || $filePath === '.') { + continue; + } + + \copy( + __DIR__ . '/../../..' . $data['path'] . '/' . $filePath, + $tempPath . $filePath + ); + + $request->addFile([ + 'error' => \UPLOAD_ERR_OK, + 'type' => \substr($filePath, \strrpos($filePath, '.') + 1), + 'name' => $filePath, + 'tmp_name' => $tempPath . $filePath, + 'size' => \filesize($tempPath . $filePath), + ]); + } + + $module->apiTemplateCreate($request, $response); + } } diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 0b75fb2..9579418 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -98,7 +98,7 @@ final class ApiController extends Controller } $view = $this->createView($instance, $request, $response); - $this->setHelperResponseHeader($view, $instance->template->name, $request, $response); + $this->setWorkflowResponseHeader($view, $instance->template->name, $request, $response); $view->setData('path', __DIR__ . '/../../../'); $response->set('export', $view); @@ -137,7 +137,7 @@ final class ApiController extends Controller * * @since 1.0.0 */ - private function setHelperResponseHeader(View $view, string $name, RequestAbstract $request, ResponseAbstract $response) : void + private function setWorkflowResponseHeader(View $view, string $name, RequestAbstract $request, ResponseAbstract $response) : void { switch ($request->getData('type')) { case 'pdf': @@ -370,6 +370,13 @@ final class ApiController extends Controller $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Template', 'Template successfully created', $template); } + private function createTemplateDir(WorkflowTemplate $template) : string + { + return '/Modules/Workflow/' + . $template->getId() . ' ' + . $template->name; + } + /** * Validate template create request * @@ -470,6 +477,7 @@ final class ApiController extends Controller $count = \count($data); // @todo: if no Cli is available do it in the web app (maybe first web request and if this is also not allowed run it in here) + /* SystemUtils::runProc( 'php', __DIR__ . '/../../../cli.php' . ' ' @@ -479,5 +487,6 @@ final class ApiController extends Controller . '-d ' . \escapeshellarg(\json_encode($data)), true ); + */ } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 79971b6..5475a33 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace Modules\Workflow\Controller; +use Modules\Media\Models\CollectionMapper; +use Modules\Workflow\Models\WorkflowTemplateMapper; use phpOMS\Contract\RenderableInterface; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; @@ -47,6 +49,23 @@ final class BackendController extends Controller $view->setTemplate('/Modules/Workflow/Theme/Backend/workflow-template-list'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005501001, $request, $response)); + $path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/')); + $templates = WorkflowTemplateMapper::getAll() + ->with('createdBy') + ->with('tags') + ->with('tags/title') + ->where('virtualPath', $path) + ->where('tags/title/language', $response->getLanguage()) + ->execute(); + + list($collection, $parent) = CollectionMapper::getCollectionsByPath($path); + + $view->addData('parent', $parent); + $view->addData('collections', $collection); + $view->addData('path', $path); + $view->addData('reports', $templates); + $view->addData('account', $this->app->accountManager->get($request->header->account)); + return $view; } diff --git a/Models/PermissionCategory.php b/Models/PermissionCategory.php index 8cb3bd5..eca27ea 100755 --- a/Models/PermissionCategory.php +++ b/Models/PermissionCategory.php @@ -31,4 +31,6 @@ abstract class PermissionCategory extends Enum public const TEMPLATE = 2; public const EXPORT = 3; + + public const WORKFLOW = 4; } diff --git a/Theme/Backend/workflow-template-list.tpl.php b/Theme/Backend/workflow-template-list.tpl.php index a07341e..8e9a471 100755 --- a/Theme/Backend/workflow-template-list.tpl.php +++ b/Theme/Backend/workflow-template-list.tpl.php @@ -12,9 +12,154 @@ */ declare(strict_types=1); +use phpOMS\Uri\UriFactory; + /** - * @var \phpOMS\Views\View $this - * @var \Modules\Tasks\Models\Task[] $tasks + * @var \phpOMS\Views\View $this + * @var \Modules\Workflow\Models\Template[] $templates */ -$tasks = $this->getData('tasks'); -echo $this->getData('nav')->render(); +$templates = $this->getData('reports'); + +/** @var \Modules\Admin\Models\Account $account */ +$account = $this->getData('account'); + +$accountDir = $account->getId() . ' ' . $account->login; + +/** @var \Modules\Media\Models\Collection[] */ +$collections = $this->getData('collections'); +$mediaPath = \urldecode($this->getData('path') ?? '/'); + +$previous = empty($templates) ? '{/prefix}workflow/template/list' : '{/prefix}workflow/template/list?{?}&id=' . \reset($templates)->getId() . '&ptype=p'; +$next = empty($templates) ? '{/prefix}workflow/template/list' : '{/prefix}workflow/template/list?{?}&id=' . \end($templates)->getId() . '&ptype=n'; + +echo $this->getData('nav')->render(); ?> +
+
+
+ +
+
+
+ +
+
+
+
getHtml('Workflows'); ?>
+
+ + + + + + + + + +
+ + getHtml('Name'); ?> + + + + getHtml('Creator'); ?> + + + + getHtml('Created'); ?> + + + +
+ + .. + + + + + + $value) : ++$count; + $url = UriFactory::build('{/prefix}workflow/template/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->name); + ?> +
+ + printHtml($value->name); ?> + printHtml($this->renderUserName('%3$s %2$s %1$s', [$value->createdBy->name1, $value->createdBy->name2, $value->createdBy->name3, $value->createdBy->login ?? ''])); ?> + printHtml($value->createdAt->format('Y-m-d')); ?> + + $template) : ++$count; + $url = UriFactory::build('{/prefix}workflow/template/view?{?}&id=' . $template->getId()); ?> +
+ + printHtml($template->name); ?> + printHtml($this->renderUserName('%3$s %2$s %1$s', [$template->createdBy->name1, $template->createdBy->name2, $template->createdBy->name3, $template->createdBy->login ?? ''])); ?> + printHtml($template->createdAt->format('Y-m-d')); ?> + + +
getHtml('Empty', '0', '0'); ?> + +
+
+ +
+
+