[COMPONENT][CONTROLLER][TWIG] Recycle component work

This commit is contained in:
rainydaysavings 2020-09-04 00:13:58 +01:00 committed by Hugo Sales
parent b0566e7b8c
commit 492f32c555
3 changed files with 15 additions and 9 deletions

View File

@ -55,7 +55,7 @@ class Post
if ($form->isSubmitted()) { if ($form->isSubmitted()) {
$data = $form->getData(); $data = $form->getData();
if ($form->isValid()) { if ($form->isValid()) {
self::storeNote($actor_id, $data['content'], $data['attachments'], $is_local = true, $data['reply_to']); self::storeNote($actor_id, $data['content'], $data['attachments'], $is_local = true, $data['reply_to'], null);
} else { } else {
// TODO display errors // TODO display errors
} }
@ -68,9 +68,13 @@ class Post
]; ];
} }
public function favourite(Request $request, string $fav_to) public function recycle(Request $request, string $repeat_of)
{ {
$note = DB::find('note', ['id' => $fav_to]); $note = DB::find('note', ['id' => $repeat_of]);
$content_repeat = DB::dql('select n.content from App\Entity\Note n ' .
'where n.reply_to = ' . $repeat_of
);
if ($note == null) { if ($note == null) {
throw new ClientException(_m('No such note')); throw new ClientException(_m('No such note'));
} }
@ -78,7 +82,8 @@ class Post
$actor_id = Common::ensureLoggedIn()->getActor()->getId(); $actor_id = Common::ensureLoggedIn()->getActor()->getId();
$form = Form::create([ $form = Form::create([
['favourite', SubmitType::class, []], ['repeat_of', HiddenType::class, ['data' => (int) $repeat_of]],
['save', SubmitType::class, ['label' => _m('Submit')]],
]); ]);
$form->handleRequest($request); $form->handleRequest($request);
@ -86,7 +91,7 @@ class Post
if ($form->isSubmitted()) { if ($form->isSubmitted()) {
$data = $form->getData(); $data = $form->getData();
if ($form->isValid()) { if ($form->isValid()) {
self::storeNote($actor_id, $data['content'], $data['attachments'], $is_local = true, $data['reply_to']); self::storeNote($actor_id, $data[$content_repeat], $data['attachments'], $is_local = true, $data['reply_to'], $data['repeat_of']);
} else { } else {
// TODO display errors // TODO display errors
} }
@ -95,13 +100,13 @@ class Post
return [ return [
'_template' => 'note/reply.html.twig', '_template' => 'note/reply.html.twig',
'note' => $note, 'note' => $note,
'fav' => $form->createView(), 'reply' => $form->createView(),
]; ];
} }
public static function storeNote(int $actor_id, string $content, array $attachments, bool $is_local, ?int $reply_to = null) public static function storeNote(int $actor_id, string $content, array $attachments, bool $is_local, ?int $reply_to = null, ?int $repeat_of = null)
{ {
$note = Note::create(['gsactor_id' => $actor_id, 'content' => $content, 'is_local' => $is_local, 'reply_to' => $reply_to]); $note = Note::create(['gsactor_id' => $actor_id, 'content' => $content, 'is_local' => $is_local, 'reply_to' => $reply_to, 'repeat_of' => $repeat_of]);
$files = []; $files = [];
foreach ($attachments as $f) { foreach ($attachments as $f) {
$nf = Media::validateAndStoreFile($f, Common::config('attachments', 'dir'), $nf = Media::validateAndStoreFile($f, Common::config('attachments', 'dir'),

View File

@ -36,6 +36,7 @@ class Posting extends Module
public function onAddRoute($r) public function onAddRoute($r)
{ {
$r->connect('note_reply', '/note/reply/{reply_to<\d*>}', [C\Post::class, 'reply']); $r->connect('note_reply', '/note/reply/{reply_to<\d*>}', [C\Post::class, 'reply']);
$r->connect('note_recycle', '/main/all', [C\Post::class, 'recycle']);
} }
public function onStartTwigPopulateVars(array &$vars) public function onStartTwigPopulateVars(array &$vars)

View File

@ -19,7 +19,7 @@
<use xlink:href="#icon-reply"></use> <use xlink:href="#icon-reply"></use>
</svg> </svg>
</a> </a>
<a href="{{ path('note_reply', {'reply_to': note.getId()}) }}"> <a href="{{ path('note_recycle', {'repeat_of': note.getId()}) }}">
<svg class="icon icon-recycle"> <svg class="icon icon-recycle">
<use xlink:href="#icon-recycle"></use> <use xlink:href="#icon-recycle"></use>
</svg> </svg>