many fixes and expands and module expansions

This commit is contained in:
Dennis Eichhorn 2021-04-04 17:10:52 +02:00
parent e2aaeef8da
commit f7c6dcce70
9 changed files with 251 additions and 53 deletions

View File

@ -9,13 +9,8 @@
"primary": true,
"autoincrement": true
},
"comments_list_active": {
"name": "comments_list_active",
"type": "TINYINT",
"null": false
},
"comments_list_allow_comment": {
"name": "comments_list_allow_comment",
"comments_list_status": {
"name": "comments_list_status",
"type": "TINYINT",
"null": false
},
@ -28,6 +23,11 @@
"name": "comments_list_allow_edit",
"type": "TINYINT",
"null": false
},
"comments_list_allow_files": {
"name": "comments_list_allow_files",
"type": "TINYINT",
"null": false
}
}
},
@ -89,5 +89,62 @@
"null": false
}
}
},
"comments_comment_media": {
"name": "comments_comment_media",
"fields": {
"comments_comment_media_id": {
"name": "comments_comment_media_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"comments_comment_media_src": {
"name": "comments_comment_media_src",
"type": "INT",
"null": false,
"foreignTable": "comments_comment",
"foreignKey": "comments_comment_id"
},
"comments_comment_media_dst": {
"name": "comments_comment_media_dst",
"type": "INT",
"null": false,
"foreignTable": "media",
"foreignKey": "media_id"
}
}
},
"comments_comment_vote": {
"name": "comments_comment_vote",
"fields": {
"comments_comment_vote_id": {
"name": "comments_comment_vote_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"comments_comment_vote_src": {
"name": "comments_comment_vote_src",
"type": "INT",
"null": false,
"foreignTable": "comments_comment",
"foreignKey": "comments_comment_id"
},
"comments_comment_vote_dst": {
"name": "comments_comment_vote_dst",
"type": "INT",
"null": false,
"foreignTable": "account",
"foreignKey": "account_id"
},
"comments_comment_vote_score": {
"name": "comments_comment_vote_score",
"type": "TINYINT",
"null": false
}
}
}
}

View File

@ -71,6 +71,47 @@ final class ApiController extends Controller
return $list;
}
/**
* Api method to update comment list
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiCommentListUpdate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$old = clone CommentListMapper::get((int) $request->getData('id'));
$new = $this->updateCommentListFromRequest($request);
$this->updateModel($request->header->account, $old, $new, CommentMapper::class, 'comment_list', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Comment List', 'Comment list successfully updated', $new);
}
/**
* Method to update comment from request.
*
* @param RequestAbstract $request Request
*
* @return Comment
*
* @since 1.0.0
*/
private function updateCommentListFromRequest(RequestAbstract $request) : Comment
{
$list = CommentListMapper::get((int) $request->getData('id'));
$list->allowEdit = (bool) ($request->getData('allow_edit') ?? $list->allowEdit);
$list->allowVoting = (bool) ($request->getData('allow_voting') ?? $list->allowVoting);
$list->allowFiles = (bool) ($request->getData('allow_upload') ?? $list->allowFiles);
$list->status = (int) ($request->getData('commentlist_status') ?? $list->status);
return $list;
}
/**
* Api method to create comment
*

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\Comments\Models;
use Modules\Admin\Models\Account;
use Modules\Media\Models\Media;
use Modules\Admin\Models\NullAccount;
/**
@ -99,6 +100,14 @@ class Comment
*/
private $ref = null;
/**
* Media files
*
* @var Media[]
* @since 1.0.0
*/
protected array $media = [];
/**
* Constructor.
*
@ -207,4 +216,30 @@ class Comment
{
return [];
}
/**
* Get all media
*
* @return Media[]
*
* @since 1.0.0
*/
public function getMedia() : array
{
return $this->media;
}
/**
* Add media
*
* @param Media $media Media to add
*
* @return void
*
* @since 1.0.0
*/
public function addMedia(Media $media) : void
{
$this->media[] = $media;
}
}

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace Modules\Comments\Models;
use Modules\Media\Models\Media;
/**
* Task class.
*
@ -43,21 +45,13 @@ class CommentList
/**
* Is active
*
* @var bool
* @var int
* @since 1.0.0
*/
public bool $isActive = true;
public int $status = CommentListStatus::ACTIVE;
/**
* Is active
*
* @var bool
* @since 1.0.0
*/
public bool $allowComment = true;
/**
* Is active
* Allow voting
*
* @var bool
* @since 1.0.0
@ -65,13 +59,21 @@ class CommentList
public bool $allowVoting = true;
/**
* Is active
* Allow editing
*
* @var bool
* @since 1.0.0
*/
public bool $allowEdit = true;
/**
* Allow files
*
* @var bool
* @since 1.0.0
*/
public bool $allowFiles = true;
/**
* Get id.
*
@ -109,30 +111,4 @@ class CommentList
{
$this->comments[] = $comment;
}
/**
* Is active
*
* @return bool
*
* @since 1.0.0
*/
public function isActive() : bool
{
return $this->isActive;
}
/**
* Set list activity
*
* @param bool $active Is active
*
* @return void
*
* @since 1.0.0
*/
public function setActive(bool $active) : void
{
$this->isActive = $active;
}
}

View File

@ -34,10 +34,10 @@ final class CommentListMapper extends DataMapperAbstract
*/
protected static array $columns = [
'comments_list_id' => ['name' => 'comments_list_id', 'type' => 'int', 'internal' => 'id'],
'comments_list_active' => ['name' => 'comments_list_active', 'type' => 'bool', 'internal' => 'isActive'],
'comments_list_allow_comment' => ['name' => 'comments_list_allow_comment', 'type' => 'bool', 'internal' => 'allowComment'],
'comments_list_status' => ['name' => 'comments_list_status', 'type' => 'bool', 'internal' => 'status'],
'comments_list_allow_voting' => ['name' => 'comments_list_allow_voting', 'type' => 'bool', 'internal' => 'allowVoting'],
'comments_list_allow_edit' => ['name' => 'comments_list_allow_edit', 'type' => 'bool', 'internal' => 'allowEdit'],
'comments_list_allow_files' => ['name' => 'comments_list_allow_files', 'type' => 'bool', 'internal' => 'allowFiles'],
];
/**

View File

@ -0,0 +1,34 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Comments\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Comments\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Comment Status enum.
*
* @package Modules\Comments\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
abstract class CommentListStatus extends Enum
{
public const ACTIVE = 1;
public const LOCKED = 2;
public const INACTIVE = 3;
}

View File

@ -16,6 +16,7 @@ namespace Modules\Comments\Models;
use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use Modules\Media\Models\MediaMapper;
/**
* Mapper class.
@ -62,6 +63,21 @@ final class CommentMapper extends DataMapperAbstract
],
];
/**
* Has many relation.
*
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0
*/
protected static array $hasMany = [
'media' => [
'mapper' => MediaMapper::class,
'table' => 'comments_comment_media',
'external' => 'comments_comment_media_dst',
'self' => 'comments_comment_media_src',
],
];
/**
* Primary table.
*

View File

@ -33,7 +33,6 @@ final class NullCommentList extends CommentList
*/
public function __construct(int $id = 0)
{
$this->id = $id;
$this->isActive = false;
$this->id = $id;
}
}

View File

@ -1,14 +1,54 @@
<?php declare(strict_types=1);
use Modules\Comments\Models\CommentListStatus;
/** @var \Modules\Comments\Models\Comment[] $comments */
$comments = $this->commentList->getComments();
?>
<form method="POST" action="<?= \phpOMS\Uri\UriFactory::build('{/api}comment/list?id=' . $this->commentList->getId() . '{?}&csrf={$CSRF}'); ?>">
<select name="commentlist_status">
<option value="<?= CommentListStatus::ACTIVE; ?>"><?= $this->getHtml('lstatus-' . CommentListStatus::ACTIVE); ?>
<option value="<?= CommentListStatus::INACTIVE; ?>"><?= $this->getHtml('lstatus-' . CommentListStatus::INACTIVE); ?>
<option value="<?= CommentListStatus::LOCKED; ?>"><?= $this->getHtml('lstatus-' . CommentListStatus::LOCKED); ?>
</select>
<label class="checkbox" for="iComment">
<input id="iComment" type="checkbox" name="allow_voting" value="1">
<span class="checkmark"></span>
<?= $this->getHtml('Voting'); ?>
</label>
<label class="checkbox" for="iComment">
<input id="iComment" type="checkbox" name="allow_edit" value="1">
<span class="checkmark"></span>
<?= $this->getHtml('Edit'); ?>
</label>
<label class="checkbox" for="iComment">
<input id="iComment" type="checkbox" name="allow_upload" value="1">
<span class="checkmark"></span>
<?= $this->getHtml('Upload'); ?>
</label>
</form>
<?php
foreach ($comments as $comment) : ?>
<div class="row">
<div class="col-xs-12">
<section class="portlet">
<article>
<?= $comment->content; ?>
</article>
<div class="portlet-body">
<article>
<?= $comment->content; ?>
</article>
</div>
<div class="portlet-foot">
<?= $this->printHtml(
\sprintf('%3$s %2$s %1$s', $comment->createdBy->name1, $comment->createdBy->name2, $comment->createdBy->name3)
); ?>
<span class="floatRight"><?= $comment->createdAt->format('Y-m-d H:i:s'); ?></span>
</div>
</section>
</div>
</div>
<?php endforeach; ?>
<?php endforeach; ?>