[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) 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); 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 public static function getAllNotes(int $note_scope): array
{ {
return DB::sql( return DB::sql(

View File

@ -1,20 +1,30 @@
{% extends 'stdgrid.html.twig' %} {% 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 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"> <main class="feed" tabindex="0" role="feed">
<div class="h-feed hfeed notes"> <div class="h-feed hfeed notes">
{% if notes is defined and notes is not empty %} {% if notes is defined and notes is not empty %}
{% for conversation in notes %} {% for note in notes %}
{% include '/note/view.html.twig' with {'note': conversation['note'], 'have_user': have_user, 'replies': conversation['replies']} only %} {% block current_note %}
<hr tabindex="0" title="{{ 'End of note and replies.' | trans }}"> {{ noteView.macro_note(note, null) }}
{% endfor %} <hr tabindex="0" title="{{ 'End of note and replies.' | trans }}">
{% else %} {% endblock current_note %}
<div id="empty-notes"><h1>{% trans %}No notes here.{% endtrans %}</h1></div> {% endfor %}
{% endif %} {% else %}
</div> <div id="empty-notes"><h1>{% trans %}No notes here.{% endtrans %}</h1></div>
</main> {% endif %}
</div>
</main>
{% endblock body %} {% endblock body %}

View File

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