Skip to content

Commit

Permalink
v.0.3.0.3
Browse files Browse the repository at this point in the history
To handle multiple connections with their own future table, also load in subclasses of Future

And fix FutureCollection to actually return a model
  • Loading branch information
pakomp committed Nov 21, 2017
1 parent 6663319 commit 1fffb47
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
/composer.lock
.idea/
23 changes: 19 additions & 4 deletions src/Collections/FutureCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ class FutureCollection extends EloquentCollection
{
/**
* Get the original model state
*
* @return Illuminate\Support\Collection
*
* @return Dixie\EloquentModelFuture\Contracts\ModelFuture
*/
public function original()
{
return $this->map(function ($item) {
return $item->futureable;
$model = $this->first()->futureable;
return $model;
}

/**
* Get the models for each change.
* @return Dixie\EloquentModelFuture\Contracts\ModelFuture
*/
public function models($include_org=false)
{
$res = $this->map(function ($item) {
$model = (clone $item->futureable)->forceFill($item->data);
return $model;
});
if($include_org) {
$res->prepend($this->original());
}
return $res;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion src/Commands/CommitToFutureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public function handle()
->untilDate($today)
->uncommitted()
->get();

foreach(getSubclassesOf(Future::class) as $class) {
$futures->concat($class::with('futureable')
->untilDate($today)
->uncommitted()
->get());
}

if ($futures->isEmpty()) {
$this->outputMessage('No future plans for today.');
Expand All @@ -52,6 +57,14 @@ public function handle()
$this->outputMessage("{$futures->count()} futures updated.");
}

private function getSubclassesOf($parent) {
$result = array();
foreach (get_declared_classes() as $class) {
if (is_subclass_of($class, $parent))
$result[] = $class;
}
return $result;
}

/**
* Write a line to the commandline
Expand Down

0 comments on commit 1fffb47

Please sign in to comment.