mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Same but for tags.
This commit is contained in:
parent
e1186b48ec
commit
a331b2d661
@ -23,8 +23,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Api\V1\Requests;
|
namespace FireflyIII\Api\V1\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\Tag;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class TagStoreRequest
|
* Class TagStoreRequest
|
||||||
*
|
*
|
||||||
@ -52,13 +50,19 @@ class TagStoreRequest extends Request
|
|||||||
*/
|
*/
|
||||||
public function getAll(): array
|
public function getAll(): array
|
||||||
{
|
{
|
||||||
|
$hasLocation = false;
|
||||||
|
if ($this->has('longitude') && $this->has('latitude') && $this->has('zoom_level')) {
|
||||||
|
$hasLocation = true;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'tag' => $this->string('tag'),
|
'tag' => $this->string('tag'),
|
||||||
'date' => $this->date('date'),
|
'date' => $this->date('date'),
|
||||||
'description' => $this->string('description'),
|
'description' => $this->string('description'),
|
||||||
'latitude' => '' === $this->string('latitude') ? null : $this->string('latitude'),
|
'has_location' => $hasLocation,
|
||||||
'longitude' => '' === $this->string('longitude') ? null : $this->string('longitude'),
|
'longitude' => $this->string('longitude'),
|
||||||
'zoom_level' => $this->integer('zoom_level'),
|
'latitude' => $this->string('latitude'),
|
||||||
|
'zoom_level' => $this->integer('zoom_level'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,13 +51,19 @@ class TagUpdateRequest extends Request
|
|||||||
*/
|
*/
|
||||||
public function getAll(): array
|
public function getAll(): array
|
||||||
{
|
{
|
||||||
|
$updateLocation = false;
|
||||||
|
if ($this->has('longitude') && $this->has('latitude') && $this->has('zoom_level')) {
|
||||||
|
$updateLocation = true;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'tag' => $this->string('tag'),
|
'tag' => $this->string('tag'),
|
||||||
'date' => $this->date('date'),
|
'date' => $this->date('date'),
|
||||||
'description' => $this->string('description'),
|
'description' => $this->string('description'),
|
||||||
'latitude' => '' === $this->string('latitude') ? null : $this->string('latitude'),
|
'has_location' => $updateLocation,
|
||||||
'longitude' => '' === $this->string('longitude') ? null : $this->string('longitude'),
|
'longitude' => '' === $this->string('longitude') ? null : $this->string('longitude'),
|
||||||
'zoom_level' => $this->integer('zoom_level'),
|
'latitude' => '' === $this->string('latitude') ? null : $this->string('latitude'),
|
||||||
|
'zoom_level' => '' === $this->string('zoom_level') ? null : $this->integer('zoom_level'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,20 +405,28 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
$tag->save();
|
$tag->save();
|
||||||
|
|
||||||
// update, delete or create location:
|
// update, delete or create location:
|
||||||
$hasLocation = $data['has_location'] ?? false;
|
$updateLocation = $data['has_location'] ?? false;
|
||||||
if (false === $hasLocation) {
|
|
||||||
$tag->locations()->delete();
|
// location must be updated?
|
||||||
}
|
if (true === $updateLocation) {
|
||||||
if (true === $hasLocation) {
|
// if all set to NULL, delete
|
||||||
$location = $this->getLocation($tag);
|
if (null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level']) {
|
||||||
if (null === $location) {
|
$tag->locations()->delete();
|
||||||
$location = new Location;
|
}
|
||||||
$location->locatable()->associate($tag);
|
|
||||||
|
// otherwise, update or create.
|
||||||
|
if (!(null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level'])) {
|
||||||
|
$location = $this->getLocation($tag);
|
||||||
|
if (null === $location) {
|
||||||
|
$location = new Location;
|
||||||
|
$location->locatable()->associate($tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
$location->latitude = $data['latitude'] ?? config('firefly.default_location.latitude');
|
||||||
|
$location->longitude = $data['longitude'] ?? config('firefly.default_location.longitude');
|
||||||
|
$location->zoom_level = $data['zoom_level'] ?? config('firefly.default_location.zoom_level');
|
||||||
|
$location->save();
|
||||||
}
|
}
|
||||||
$location->latitude = $data['latitude'] ?? config('firefly.default_location.latitude');
|
|
||||||
$location->longitude = $data['longitude'] ?? config('firefly.default_location.longitude');
|
|
||||||
$location->zoom_level = $data['zoom_level'] ?? config('firefly.default_location.zoom_level');
|
|
||||||
$location->save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tag;
|
return $tag;
|
||||||
|
@ -106,12 +106,12 @@ class AccountUpdateService
|
|||||||
// location must be updated?
|
// location must be updated?
|
||||||
if (true === $updateLocation) {
|
if (true === $updateLocation) {
|
||||||
// if all set to NULL, delete
|
// if all set to NULL, delete
|
||||||
if(null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level']) {
|
if (null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level']) {
|
||||||
$account->locations()->delete();
|
$account->locations()->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, update or create.
|
// otherwise, update or create.
|
||||||
if(!(null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level'])) {
|
if (!(null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level'])) {
|
||||||
$location = $this->accountRepository->getLocation($account);
|
$location = $this->accountRepository->getLocation($account);
|
||||||
if (null === $location) {
|
if (null === $location) {
|
||||||
$location = new Location;
|
$location = new Location;
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Transformers;
|
namespace FireflyIII\Transformers;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Models\Location;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
@ -56,6 +57,16 @@ class TagTransformer extends AbstractTransformer
|
|||||||
public function transform(Tag $tag): array
|
public function transform(Tag $tag): array
|
||||||
{
|
{
|
||||||
$date = null === $tag->date ? null : $tag->date->format('Y-m-d');
|
$date = null === $tag->date ? null : $tag->date->format('Y-m-d');
|
||||||
|
/** @var Location $location */
|
||||||
|
$location = $tag->locations()->first();
|
||||||
|
$latitude = null;
|
||||||
|
$longitude = null;
|
||||||
|
$zoomLevel = null;
|
||||||
|
if (null !== $location) {
|
||||||
|
$latitude = $location->latitude;
|
||||||
|
$longitude = $location->longitude;
|
||||||
|
$zoomLevel = $location->zoom_level;
|
||||||
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'id' => (int)$tag->id,
|
'id' => (int)$tag->id,
|
||||||
'created_at' => $tag->created_at->toAtomString(),
|
'created_at' => $tag->created_at->toAtomString(),
|
||||||
@ -63,9 +74,9 @@ class TagTransformer extends AbstractTransformer
|
|||||||
'tag' => $tag->tag,
|
'tag' => $tag->tag,
|
||||||
'date' => $date,
|
'date' => $date,
|
||||||
'description' => '' === $tag->description ? null : $tag->description,
|
'description' => '' === $tag->description ? null : $tag->description,
|
||||||
'latitude' => null === $tag->latitude ? null : (float)$tag->latitude,
|
'longitude' => $longitude,
|
||||||
'longitude' => null === $tag->longitude ? null : (float)$tag->longitude,
|
'latitude' => $latitude,
|
||||||
'zoom_level' => null === $tag->zoomLevel ? null : (int)$tag->zoomLevel,
|
'zoom_level' => $zoomLevel,
|
||||||
'links' => [
|
'links' => [
|
||||||
[
|
[
|
||||||
'rel' => 'self',
|
'rel' => 'self',
|
||||||
|
Loading…
Reference in New Issue
Block a user