コード例 #1
0
ファイル: Voting.php プロジェクト: scify/Vote-collector
 public function defaultVotesSet()
 {
     // check that the count of GroupVotes with this voting's id is equal to the count of all groups * number of voting items of this voting
     $groupCount = Group::all()->count();
     $votingItemCount = VotingItem::ofVoting($this->id)->count();
     $correctAmount = $groupCount * $votingItemCount;
     if (GroupVote::ofVoting($this->id)->count() == $correctAmount) {
         return true;
     }
     return false;
 }
コード例 #2
0
 /**
  * Save a new voting to the database
  *
  * @param VotingRequest $request
  */
 private function createVoting(VotingRequest $request)
 {
     // Make a voting and save it
     $v = Voting::create(['title' => $request->input('title'), 'completed' => false]);
     // Make voting items and save them
     $objectives = $request->input('objectives');
     $types = $request->input('voting_types');
     if (count($objectives) != count($types)) {
         // objectives and types should always have the same length because of the way the form is made
         return 'ERROR: Vote objectives and types length is different!';
     }
     $count = count($objectives);
     for ($i = 0; $i < $count; $i++) {
         VotingItem::create(['voting_id' => $v->id, 'vote_type_id' => $types[$i], 'vote_objective_id' => $objectives[$i]]);
     }
 }