|
- <?php
-
-
-
- namespace backend\models;
-
- use Yii;
- use yii\base\Model;
- use common\models\User ;
- use common\models\Producer ;
- use common\models\UserProducer ;
-
-
- class AccessUserProducerForm extends Model
- {
-
- public $id_user ;
-
-
-
- public function rules()
- {
- return [
- [['id_user'], 'required'],
- [['id_user'], 'integer'],
- ];
- }
-
-
-
- public function attributeLabels()
- {
- return [
- 'id_user' => 'Utilisateur',
- ];
- }
-
- public function save()
- {
- $user = User::searchOne([
- 'id' => $this->id_user
- ]) ;
-
- if($user) {
- $user->id_producer = Producer::getId() ;
- if($user->status != User::STATUS_PRODUCER && $user->status != User::STATUS_ADMIN) {
- $user->status = User::STATUS_PRODUCER ;
- }
- return $user->save();
- }
-
- return false;
- }
-
- }
|