impl. virtual path

This commit is contained in:
Dennis Eichhorn 2020-11-01 21:25:09 +01:00
parent 0ae12dd4a9
commit ea23ad2deb
5 changed files with 52 additions and 31 deletions

View File

@ -24,8 +24,8 @@
"type": "TEXT",
"null": false
},
"editor_doc_path": {
"name": "editor_doc_path",
"editor_doc_virtual": {
"name": "editor_doc_virtual",
"type": "VARCHAR(255)",
"null": false
},

View File

@ -24,6 +24,7 @@ use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Model\Message\FormValidation;
use phpOMS\Utils\Parser\Markdown\Markdown;
use phpOMS\Message\Http\HttpResponse;
/**
* Calendar controller class.
@ -106,11 +107,22 @@ final class ApiController extends Controller
$doc->setTitle((string) ($request->getData('title') ?? ''));
$doc->setPlain((string) ($request->getData('plain') ?? ''));
$doc->setContent(Markdown::parse((string) ($request->getData('plain') ?? '')));
$doc->setVirtualPath((string) ($request->getData('virtualpath') ?? '/'));
$doc->setCreatedBy(new NullAccount($request->getHeader()->getAccount()));
if (!empty($tags = $request->getDataJson('tag'))) {
if (!empty($tags = $request->getDataJson('tags'))) {
foreach ($tags as $tag) {
$doc->addTag(new NullTag((int) $tag));
if (!isset($tag['id'])) {
$request->setData('title', $tag['title'], true);
$request->setData('color', $tag['color'], true);
$request->setData('language', $tag['language'], true);
$internalResponse = new HttpResponse();
$this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse, null);
$doc->addTag($internalResponse->get($request->getUri()->__toString())['response']);
} else {
$doc->addTag(new NullTag((int) $tag['id']));
}
}
}

View File

@ -24,6 +24,8 @@ use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Views\View;
use Modules\Media\Models\Collection;
use Modules\Admin\Models\Account;
/**
* Calendar controller class.
@ -100,29 +102,15 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/Editor/Theme/Backend/editor-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005301001, $request, $response));
$path = (string) ($request->getData('path') ?? '/');
$collection = CollectionMapper::getByVirtualPath(\str_replace('+', ' ', $path));
$parent = CollectionMapper::getParentCollection(\str_replace('+', ' ', $path));
$path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/'));
$docs = EditorDocMapper::withConditional('language', $response->getHeader()->getL11n()->getLanguage())::getByVirtualPath($path, $request->getHeader()->getAccount());
list($collection, $parent) = CollectionMapper::getCollectionsByPath($path);
$view->addData('parent', $parent);
$view->addData('collections', $collection);
$view->addData('path', $path);
if ($request->getData('ptype') === 'p') {
$view->setData('docs',
EditorDocMapper::withConditional('language', $response->getHeader()->getL11n()->getLanguage())
::getBeforePivot((int) ($request->getData('id') ?? 0), null, 25)
);
} elseif ($request->getData('ptype') === 'n') {
$view->setData('docs',
EditorDocMapper::withConditional('language', $response->getHeader()->getL11n()->getLanguage())
::getAfterPivot((int) ($request->getData('id') ?? 0), null, 25)
);
} else {
$view->setData('docs',
EditorDocMapper::withConditional('language', $response->getHeader()->getL11n()->getLanguage())
::getAfterPivot(0, null, 25)
);
}
$view->addData('docs', $docs);
return $view;
}
@ -144,7 +132,7 @@ final class BackendController extends Controller
$view = new View($this->app->l11nManager, $request, $response);
/** @var \Modules\Editor\Models\EditorDoc $doc */
$doc = EditorDocMapper::get((int) $request->getData('id'));
$doc = EditorDocMapper::withConditional('language', $response->getHeader()->getL11n()->getLanguage())::get((int) $request->getData('id'));
$accountId = $request->getHeader()->getAccount();
if ($doc->getCreatedBy()->getId() !== $accountId

View File

@ -67,7 +67,7 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
private string $path = '';
private string $virtualPath = '/';
/**
* Created.
@ -237,9 +237,9 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface
*
* @since 1.0.0
*/
public function getPath() : string
public function getVirtualPath() : string
{
return $this->path;
return $this->virtualPath;
}
/**
@ -251,9 +251,9 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface
*
* @since 1.0.0
*/
public function setPath(string $path)
public function setVirtualPath(string $path)
{
$this->path = $path;
$this->virtualPath = $path;
}
/**

View File

@ -17,6 +17,7 @@ namespace Modules\Editor\Models;
use Modules\Admin\Models\AccountMapper;
use Modules\Tag\Models\TagMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\RelationType;
/**
* Editor doc mapper class.
@ -40,7 +41,7 @@ final class EditorDocMapper extends DataMapperAbstract
'editor_doc_title' => ['name' => 'editor_doc_title', 'type' => 'string', 'internal' => 'title'],
'editor_doc_plain' => ['name' => 'editor_doc_plain', 'type' => 'string', 'internal' => 'plain'],
'editor_doc_content' => ['name' => 'editor_doc_content', 'type' => 'string', 'internal' => 'content'],
'editor_doc_path' => ['name' => 'editor_doc_path', 'type' => 'string', 'internal' => 'path'],
'editor_doc_virtual' => ['name' => 'editor_doc_virtual', 'type' => 'string', 'internal' => 'virtualPath'],
'editor_doc_created_at' => ['name' => 'editor_doc_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
];
@ -95,4 +96,24 @@ final class EditorDocMapper extends DataMapperAbstract
* @since 1.0.0
*/
protected static string $createdAt = 'editor_doc_created_at';
/**
* Get editor doc based on virtual path.
*
* @param string $virtualPath Virtual path
* @param int $account Account id
*
* @return array
*
* @since 1.0.0
*/
public static function getByVirtualPath(string $virtualPath = '/', int $account = 0) : array
{
$depth = 3;
$query = self::getQuery();
$query->where(self::$table . '_' . $depth . '.editor_doc_virtual', '=', $virtualPath);
$query->where(self::$table . '_' . $depth . '.editor_doc_created_by', '=', $account);
return self::getAllByQuery($query, RelationType::ALL, $depth);
}
}