[CONTROLLER][Actor] Provide template with all notes by actor

[ENTITY][Note] Add getAllNotesByActor

[TWIG] Actor profile page now renders all notes by the actor
This commit is contained in:
Eliseu Amaro 2021-12-01 21:41:41 +00:00
parent 6bcd42a3a7
commit eeb42ef8ea
Signed by: eliseuamaro
GPG Key ID: 96DA09D4B97BC2D5
4 changed files with 37 additions and 17 deletions

View File

@ -71,6 +71,6 @@ class Actor extends Controller
}
public function ActorShowNickname(Request $request, string $nickname)
{
return $this->ActorByNickname($nickname, fn ($actor) => ['_template' => 'actor/view.html.twig', 'actor' => $actor]);
return $this->ActorByNickname($nickname, fn ($actor) => ['_template' => 'actor/view.html.twig', 'actor' => $actor, 'notes' => \App\Entity\Note::getAllNotesByActor($actor)]);
}
}

View File

@ -217,6 +217,18 @@ class Note extends Entity
return Avatar::getAvatarUrl($this->getActorId(), $size);
}
public static function getAllNotesByActor(Actor $actor): array
{
return DB::sql(
<<<'EOF'
select {select} from note n
where (n.actor_id & :actor_id) <> 0
order by n.created DESC
EOF,
['actor_id' => $actor],
);
}
public static function getAllNotes(int $note_scope): array
{
return DB::sql(

View File

@ -1,16 +1,26 @@
{% extends 'stdgrid.html.twig' %}
{% import '/cards/note/view.html.twig' as noteView %}
{% block title %}{{ actor.getNickname() }}'s profile{% endblock %}
{% block title %}{{ actor.getNickname() ~ '\'s profile' | trans }}{% endblock %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('assets/default_theme/css/pages/feeds.css') }}" type="text/css">
{% endblock stylesheets %}
{% block body %}
{% block profile_view %}{% include 'cards/profile/view.html.twig' %}{% endblock profile_view %}
{% block profile_view %}
{% include 'cards/profile/view.html.twig' %}
{% endblock profile_view %}
<main class="feed" tabindex="0" role="feed">
<div class="h-feed hfeed notes">
{% if notes is defined and notes is not empty %}
{% for conversation in notes %}
{% include '/note/view.html.twig' with {'note': conversation['note'], 'have_user': have_user, 'replies': conversation['replies']} only %}
{% for note in notes %}
{% block current_note %}
{{ noteView.macro_note(note, null) }}
<hr tabindex="0" title="{{ 'End of note and replies.' | trans }}">
{% endblock current_note %}
{% endfor %}
{% else %}
<div id="empty-notes"><h1>{% trans %}No notes here.{% endtrans %}</h1></div>

View File

@ -40,6 +40,4 @@
{{ block | raw }}
{% endfor %}
</section>
<hr>
{% endblock profile_view %}