public function answerRank($asg, $rank) { $asgId = $asg->id; $userId = $this->currentUser->id; for ($i = 0; $i < count($rank); $i++) { $currentRank = count($rank) - $i; GpAsgAnsRank::firstOrCreate(['asg_id' => $asgId, 'gp_id' => $rank[$i], 'user_id' => $userId, 'rank' => $currentRank]); } }
public function removeGp($gpId) { $gp = Group::find($gpId); if ($gp != null) { if (count($gp->members) <= 0) { if (count(GpAsgAnsRank::where('gp_id', $gpId)->get()) <= 0) { $gp->delete(); return 0; } return -3; //some members have already ranked the group } else { return -2; } //has members in group } return -1; //there is no such group }
public function getAnswersGroupByUser($asgId) { return GpAsgAnsRank::where("asg_id", $asgId)->get()->groupBy("user_id"); }