| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // {{{ License
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This file is part of GNU social - https://www.gnu.org/software/social
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // }}}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Plugin\Favourite\Controller; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use App\Core\DB\DB; | 
					
						
							| 
									
										
										
										
											2021-04-15 00:57:29 +00:00
										 |  |  | use App\Core\Event; | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  | use Symfony\Component\HttpFoundation\Request; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Favourite | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-09-16 17:04:05 +01:00
										 |  |  |     public function favouritesByActorId(Request $request, int $id) | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-16 17:04:05 +01:00
										 |  |  |         $notes = DB::dql( | 
					
						
							|  |  |  |             'select n from App\Entity\Note n, Plugin\Favourite\Entity\Favourite f ' . | 
					
						
							|  |  |  |             'where n.id = f.note_id ' . | 
					
						
							| 
									
										
										
										
											2021-09-18 03:22:27 +01:00
										 |  |  |             'and f.actor_id = :id ' . | 
					
						
							| 
									
										
										
										
											2021-09-16 17:04:05 +01:00
										 |  |  |             'order by f.created DESC', | 
					
						
							|  |  |  |             ['id' => $id] | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-06 19:49:03 +01:00
										 |  |  |         $notes_out = null; | 
					
						
							|  |  |  |         Event::handle('FormatNoteList', [$notes, &$notes_out]); | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2021-09-22 16:46:58 +01:00
										 |  |  |             '_template'     => 'network/feed.html.twig', | 
					
						
							|  |  |  |             'notes'         => $notes_out, | 
					
						
							|  |  |  |             'page_title'    => 'Favourites timeline.', | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-16 17:04:05 +01:00
										 |  |  |     public function favouritesByActorNickname(Request $request, string $nickname) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $user = DB::findOneBy('local_user', ['nickname' => $nickname]); | 
					
						
							|  |  |  |         return self::favouritesByActorId($request, $user->getId()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      *  Reverse favourites stream | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Request $request | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws \App\Util\Exception\NoLoggedInUser user not logged in | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array template | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-16 17:04:05 +01:00
										 |  |  |     public function reverseFavouritesByActorId(Request $request, int $id) | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-16 17:04:05 +01:00
										 |  |  |         $notes = DB::dql('select n from App\Entity\Note n, Plugin\Favourite\Entity\Favourite f ' . | 
					
						
							| 
									
										
										
										
											2021-04-15 00:57:29 +00:00
										 |  |  |                             'where n.id = f.note_id ' . | 
					
						
							| 
									
										
										
										
											2021-09-18 03:22:27 +01:00
										 |  |  |                             'and f.actor_id != :id ' . | 
					
						
							|  |  |  |                             'and n.actor_id = :id ' . | 
					
						
							| 
									
										
										
										
											2021-04-15 00:57:29 +00:00
										 |  |  |                             'order by f.created DESC' , | 
					
						
							| 
									
										
										
										
											2021-09-16 17:04:05 +01:00
										 |  |  |                             ['id' => $id] | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-06 19:49:03 +01:00
										 |  |  |         $notes_out = null; | 
					
						
							| 
									
										
										
										
											2021-08-07 21:52:00 +00:00
										 |  |  |         Event::handle('FormatNoteList', [$notes, &$notes_out]); | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2021-09-22 16:46:58 +01:00
										 |  |  |             '_template' => 'network/feed.html.twig', | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  |             'notes'     => $notes, | 
					
						
							| 
									
										
										
										
											2021-09-22 16:46:58 +01:00
										 |  |  |             'page_title'    => 'Reverse favourites timeline.', | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-16 17:04:05 +01:00
										 |  |  |     public function reverseFavouritesByActorNickname(Request $request, string $nickname) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $user = DB::findOneBy('local_user', ['nickname' => $nickname]); | 
					
						
							|  |  |  |         return self::reverseFavouritesByActorId($request, $user->getId()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-04-14 19:59:37 +00:00
										 |  |  | } |