[DOCUMENTATION][REFACTOR] Add documentation to all flagged function and do some small cleanup

This commit is contained in:
Hugo Sales
2020-11-06 19:47:15 +00:00
committed by Hugo Sales
parent 9cc7b6adf5
commit 5cced1c9ed
21 changed files with 363 additions and 92 deletions

View File

@@ -32,9 +32,16 @@ use Symfony\Component\HttpFoundation\Request;
class Favourite extends Module
{
/**
* HTML rendering event that adds the favourite form as a note
* action, if a user is logged in
*/
public function onAddNoteActions(Request $request, Note $note, array &$actions)
{
$user = Common::user();
if (($user = Common::user()) == null) {
return Event::next;
}
$opts = ['note_id' => $note->getId(), 'gsactor_id' => $user->getId()];
$is_set = DB::find('favourite', $opts) != null;
$form = Form::create([
@@ -42,6 +49,8 @@ class Favourite extends Module
['note_id', HiddenType::class, ['data' => $note->getId()]],
['favourite', SubmitType::class, ['label' => ' ']],
]);
// Form handler
$ret = self::noteActionHandle($request, $form, $note, 'favourite', function ($note, $data) use ($opts) {
$fave = DB::find('favourite', $opts);
if (!$data['is_set'] && ($fave == null)) {
@@ -53,9 +62,11 @@ class Favourite extends Module
}
return Event::stop;
});
if ($ret != null) {
return $ret;
}
$actions[] = $form->createView();
return Event::next;
}