diff --git a/.gitignore b/.gitignore index 4fbb073..94640f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor/ /composer.lock +.idea/ \ No newline at end of file diff --git a/src/Collections/FutureCollection.php b/src/Collections/FutureCollection.php index a5a9630..7052f58 100644 --- a/src/Collections/FutureCollection.php +++ b/src/Collections/FutureCollection.php @@ -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; } /** diff --git a/src/Commands/CommitToFutureCommand.php b/src/Commands/CommitToFutureCommand.php index cb3834c..e025d38 100644 --- a/src/Commands/CommitToFutureCommand.php +++ b/src/Commands/CommitToFutureCommand.php @@ -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.'); @@ -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