use common\models\Produit; | use common\models\Produit; | ||||
use common\models\Production; | use common\models\Production; | ||||
use common\models\User; | use common\models\User; | ||||
use common\models\UserBoulangerie; | |||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
use yii\web\Controller; | use yii\web\Controller; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; |
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => User::find(), | |||||
'query' => | |||||
(new \yii\db\Query()) | |||||
->select('*') | |||||
->from('user, user_boulangerie') | |||||
->where('user.id = user_boulangerie.id_user') | |||||
->andWhere('user_boulangerie.id_boulangerie = '.Yii::$app->user->identity->id) | |||||
]); | ]); | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
}*/ | }*/ | ||||
$users = User::find()->all() ; | |||||
$users = (new \yii\db\Query()) | |||||
->select('*') | |||||
->from('user, user_boulangerie') | |||||
->where('user.id = user_boulangerie.id_user') | |||||
->andWhere('user_boulangerie.id_boulangerie = '.Yii::$app->user->identity->id) | |||||
->all() ; | |||||
$arr_users = [] ; | $arr_users = [] ; | ||||
foreach($users as $u) | foreach($users as $u) | ||||
$arr_users[] = $u->email ; | $arr_users[] = $u->email ; |
public function isBoulanger() | public function isBoulanger() | ||||
{ | { | ||||
return $this->is_boulanger ; | return $this->is_boulanger ; | ||||
} | |||||
} | |||||
} | } |
<?php | |||||
namespace common\models; | |||||
use Yii; | |||||
use yii\helpers\Html ; | |||||
/** | |||||
* This is the model class for table "user_boulangerie". | |||||
* | |||||
* @property integer $id | |||||
* @property integer $id_user | |||||
* @property integer $id_boulangerie | |||||
*/ | |||||
class UserBoulangerie extends \yii\db\ActiveRecord | |||||
{ | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | |||||
{ | |||||
return 'user_boulangerie'; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['id_user', 'id_boulangerie'], 'required'], | |||||
[['id_user', 'id_boulangerie'], 'integer'], | |||||
]; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
]; | |||||
} | |||||
} |
<?php | |||||
use yii\db\Schema; | |||||
use yii\db\Migration; | |||||
class m161014_084709_table_user_boulangerie extends Migration | |||||
{ | |||||
public function up() | |||||
{ | |||||
$this->createTable('user_boulangerie', [ | |||||
'id' => 'pk', | |||||
'id_user' => Schema::TYPE_INTEGER . ' NOT NULL', | |||||
'id_boulangerie' => Schema::TYPE_INTEGER . ' NOT NULL', | |||||
]); | |||||
} | |||||
public function down() | |||||
{ | |||||
$this->dropTable('user_boulangerie'); | |||||
} | |||||
} |