-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from trms/resolve-partial-bulletins
provide a method of resolving partial bulletins
- Loading branch information
Showing
7 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php namespace TRMS\Carousel\Models\Traits; | ||
|
||
use TRMS\Carousel\Exceptions\CarouselModelException; | ||
use TRMS\Carousel\Requests\ModelRequest; | ||
use TRMS\Carousel\Models\Bulletin; | ||
|
||
trait ResolvesPartial | ||
{ | ||
public function resolvePartial() | ||
{ | ||
if(!$this->PartialBulletin){ | ||
return $this; | ||
} | ||
if(!$this->api){ | ||
throw new CarouselModelException('Calling resolvePartial on unsaved bulletins is not allowed. Use the API save method to save this bulletin on the server.'); | ||
} | ||
$request = new ModelRequest(Bulletin::class, ['id'=>$this->id]); | ||
$result = $this->api->get($request); | ||
$this->applyPartialProps($result); | ||
$this->PartialBulletin = false; | ||
return $this; | ||
} | ||
|
||
private function applyPartialProps($serverResponse) | ||
{ | ||
$props = collect($serverResponse->toArray())->filter(function($value, $key){ | ||
return empty($this->$key) && $this->$key !== false && $this->$key !== 0; | ||
})->toArray(); | ||
|
||
$this->setProps($props); | ||
$this->setBlocksFromProps($serverResponse->toArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters