| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-12-15 22:03:42 +01:00
										 |  |  |  * TransactionLinkTransformer.php | 
					
						
							| 
									
										
										
										
											2020-02-16 13:57:18 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program 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. | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * GNU Affero General Public License for more details. | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Transformers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use FireflyIII\Models\TransactionJournalLink; | 
					
						
							| 
									
										
										
										
											2018-12-20 22:03:34 +01:00
										 |  |  | use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-15 22:03:42 +01:00
										 |  |  |  * Class TransactionLinkTransformer | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-12-15 22:03:42 +01:00
										 |  |  | class TransactionLinkTransformer extends AbstractTransformer | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-20 22:03:34 +01:00
										 |  |  |     /** @var JournalRepositoryInterface */ | 
					
						
							|  |  |  |     private $repository; | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-12-15 22:03:42 +01:00
										 |  |  |      * Constructor. | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @codeCoverageIgnore | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-12-15 22:03:42 +01:00
										 |  |  |     public function __construct() | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-20 22:03:34 +01:00
										 |  |  |         $this->repository = app(JournalRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param TransactionJournalLink $link | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function transform(TransactionJournalLink $link): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-20 22:03:34 +01:00
										 |  |  |         $notes = $this->repository->getLinkNoteText($link); | 
					
						
							| 
									
										
										
										
											2020-10-23 19:11:25 +02:00
										 |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2020-02-07 12:03:13 +01:00
										 |  |  |             'id'           => (int)$link->id, | 
					
						
							|  |  |  |             'created_at'   => $link->created_at->toAtomString(), | 
					
						
							|  |  |  |             'updated_at'   => $link->updated_at->toAtomString(), | 
					
						
							| 
									
										
										
										
											2020-07-12 17:54:51 +02:00
										 |  |  |             'inward_id'    => (int) $link->source_id, | 
					
						
							|  |  |  |             'outward_id'   => (int) $link->destination_id, | 
					
						
							|  |  |  |             'link_type_id' => (int) $link->link_type_id, | 
					
						
							| 
									
										
										
										
											2020-02-07 12:03:13 +01:00
										 |  |  |             'notes'        => '' === $notes ? null : $notes, | 
					
						
							|  |  |  |             'links'        => [ | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |                 [ | 
					
						
							|  |  |  |                     'rel' => 'self', | 
					
						
							| 
									
										
										
										
											2018-12-08 07:57:29 +01:00
										 |  |  |                     'uri' => '/transaction_links/' . $link->id, | 
					
						
							| 
									
										
										
										
											2018-06-28 17:02:13 +02:00
										 |  |  |                 ], | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-07-22 20:32:02 +02:00
										 |  |  | } |