'How to create two buttons based on separate id's
I am trying to create two buttons, based on if a certain condition is met. I am doing something wrong and only one button get created, and it's the wrong one to begin with.
There is a condition called onDuty that is true when a member of a team is on duty. A member can be in many teams and a team can hold many members. So, als long as a member of a team is not on duty (onDuty = false) I want to display a button for him to be able to asign duty to himself.
Below is what I have been trying to do so far:
$user = User::find()->where(['user.iduser' => Yii::$app->user->identity->iduser])->all();
foreach ($user as $team) {
$userTeams = $team->teamIdteams;
foreach ($userTeams as $teams) {
$teamId = $teams->idteam;
}
$userAndTeam = UserAndTeams::find()->where(['userid' => Yii::$app->user->identity->iduser])->andWhere(['teamid'=>$teamId])->all();
foreach ($userAndTeam as $userAndTeams) {
// Here I fail to get it done correctly.
if ($userAndTeams->onduty !== true) {
echo Html::a('<span class="btn-label">'.$teams->name.'</span>',
['activate', 'id' => Yii::$app->user->identity->iduser, 'team' => $teamId],
['class' => 'btn btn-primary']);
}
}
}
Solution 1:[1]
Never mind. I am an idiot sometimes...
$user = User::find()->where(['user.iduser' => Yii::$app->user->identity->iduser])->all();
foreach ($user as $team) {
$userTeams = $team->teamIdteams;
foreach ($userTeams as $teams) {
$teamId = $teams->idteam;
$userAndTeam = UserAndTeams::find()->where(['userid' => Yii::$app->user->identity->iduser])->andWhere(['teamid'=>$teamId])->all();
foreach ($userAndTeam as $userAndTeams) {
// Here I fail to get it done correctly.
if ($userAndTeams->onduty !== true) {
echo Html::a('<span class="btn-label">'.$teams->name.'</span>',
['activate', 'id' => Yii::$app->user->identity->iduser, 'team' => $teamId],
['class' => 'btn btn-primary']);
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Malgosh |
