/** * Execute the command. * * @param VoteRepositoryInterface $repository * @param Dispatcher $event */ public function handle(VoteRepositoryInterface $repository, Dispatcher $event) { /** * Create Vote */ $vote = $repository->create($this->model, $this->vote_open_date, $this->vote_close_date); /** * Announce VoteWasCreated */ $event->fire(new VoteWasCreated($vote)); }
/** * Execute the command. * * @param VoteRepositoryInterface $repository * @param Dispatcher $event * @return array|null */ public function handle(VoteRepositoryInterface $repository, Dispatcher $event) { /** * Check if Class uses SubmissibleTrait */ $isSubmissible = array_has(class_uses($this->vote->votable), SubmissibleTrait::class); /** * If there are no submission then project failed, or less than the minimum submissions */ $class = snake_case(class_basename($this->vote->votable)); if ($isSubmissible && $this->vote->votable->submissions->count() < config('defaults.project.' . $class . '.minimum_of_submissions')) { /** * Fail this project */ $this->dispatch(new FailIdeaSynapseScriptStageCommand($this->vote->votable)); return; } /** * Check if Class uses EnrollableTrait */ $isEnrollable = array_has(class_uses($this->vote->votable), EnrollableTrait::class); if ($isEnrollable) { /** * If there are no users applied to any available * Expenditure/Position then the project has Failed */ $this->vote->votable->enrollable->load('enrollers')->pluck('enrollers')->each(function ($item) { /** * Check if there is no enrollers to this position * Potentially can make different things for each empty item * * @var $item Collection */ if ($item->isEmpty()) { /** * Fail this project */ $this->dispatch(new FailFundingStageCommand($this->vote->votable)); return; } }); } /** * Open Vote by setting Status to true */ $repository->open($this->vote->id); /** * Announce VoteWasOpened */ $event->fire(new VoteWasOpened($this->vote)); }
/** * Display a listing of the resource. * * @param VoteRepositoryInterface $repository * @return \Illuminate\Http\Response */ public function index(VoteRepositoryInterface $repository) { return view('project.vote.index')->with('votes', $repository->allOpened()->load('project')); }
/** * Handle the event. * * @param Event $event */ public function handle(Event $event) { $this->repository->deactivate($event->vote->id); }