예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Profile::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['user_id' => $this->user_id, 'dep_id' => $this->dep_id]);
     $query->andFilterWhere(['like', 'pxname', $this->pxname])->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'photo', $this->photo])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'phone', $this->phone]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Profile::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['profile_id' => $this->profile_id, 'precinct_id' => $this->precinct_id, 'type_id' => $this->type_id, 'employee_id' => $this->employee_id]);
     $query->orFilterWhere(['like', 'profilenumber', $this->globalSearch])->orFilterWhere(['like', 'phonenumber', $this->globalSearch])->orFilterWhere(['like', 'profile_firstname', $this->globalSearch])->orFilterWhere(['like', 'profile_middlename', $this->globalSearch])->orFilterWhere(['like', 'profile_lastname', $this->globalSearch])->orFilterWhere(['like', 'profile_picture', $this->globalSearch])->orFilterWhere(['like', 'gsis', $this->globalSearch])->orFilterWhere(['like', 'sss', $this->sss])->orFilterWhere(['like', 'mothers_maiden_name', $this->globalSearch])->orFilterWhere(['like', 'sex', $this->globalSearch]);
     return $dataProvider;
 }
예제 #3
0
 public function actionForm()
 {
     //vd(1);
     $model = Profile::find()->where(['user_id' => Yii::$app->user->id])->one();
     if (!$model) {
         $model = new Profile();
     }
     if ($model->load(Yii::$app->request->post())) {
         //vd($_POST);
         if ($model->validate()) {
             $model->gender = $_POST['gender'];
             $model->user_id = Yii::$app->user->id;
             $model->login = User::getLoginById(Yii::$app->user->id);
             $model->save();
             return $this->render('form', ['model' => $model]);
         } else {
             vd($model->getErrors());
         }
     }
     return $this->render('form', ['model' => $model]);
 }
예제 #4
0
 public function actionActiveRecordJoin()
 {
     // Работа с Active Record используя Join
     // SELECT `customer`.* FROM `customer`
     // LEFT JOIN `order` ON `order`.`customer_id` = `customer`.`id`
     // WHERE `order`.`status` = 1
     //
     // SELECT * FROM `order` WHERE `customer_id` IN (...)
     /*$model = Profile::find()
       ->select('profile.*')
       ->leftJoin('auth_assignment', '`auth_assignment`.`user_id` = `profile`.`user_id`')                          // условие, достать только с ролью "Пользователь"
       ->where(['auth_assignment.item_name' => 'Создатель'])                                                       // условие, достать только с ролью "Пользователь"
       ->with(['user', 'imagesOfObjects'])                                                                         // здесь дополнительная связь к таблицам, которые нужно вытащить
       ->all();*/
     // Лучше так
     /*$model = Profile::find()
       ->select('profile.*')
       ->innerJoinWith('user', '`user`.`id` = `profile`.`user_id`')                          // условие, достать только с ролью "Пользователь"
       ->where(['user.email' => '*****@*****.**'])                                                  // условие, достать только с ролью "Пользователь"
       ->with(['imagesOfObjects.image'])                                                     // здесь дополнительная связь к таблицам, которые нужно вытащить
       ->all();*/
     // или так
     /*$model = Profile::find()->joinWith([
           'user' => function ($query) {
               $query->andWhere(['<', 'id', 5])
               ->select(['user.id', 'user.email', 'user.phone']);                                 // выборочные поля из user
           },
       ])->with(['imagesOfObjects.image'])
           ->all();*/
     // или так
     /*$model = Profile::find()->innerJoinWith([
           'user' => function ($query) {
               $query->andWhere(['<', 'id', 5])
                   ->select(['user.id', 'user.email', 'user.phone']);                                 // выборочные поля из user
           },
       ])->all();*/
     // получить данные много ко многим через модель см getImages() которая использует getImagesOfObjects() в модели Profile
     /*$model = Profile::find()
           ->where(['user_id' => 1])
           //->innerJoinWith([                         // если найдет images, тогда достанет пользователя
           ->joinWith([                                // достанет пользователя, даже если не найдет images
           'images' => function ($query) {
           },
       ])->one();*/
     // или
     //$model = Profile::findOne(1);
     // получить данные много ко многим через модель см getImages() которая использует getImagesOfObjects() в модели Profile
     //d($model->images);
     // Join с дополнительным условием CONDITION (возвращает true, если условие истинно)
     /*$model = Profile::find()->innerJoinWith([
           'user' => function ($query) {
               $query->onCondition(['user.status' => User::STATUS_NOT_ACTIVE]);
           },
       ])->all();*/
     // или так
     /*$model = Profile::find()->joinWith([
           'user' => function ($query) {
               $query->onCondition(['user.status' => User::STATUS_NOT_ACTIVE]);        // если условие верно, таблицы объединяются. Отличается от where, который возвращает только
                                                                                       // один профили с верным условием, тем, что возвращает все профили, а где условие верно
                                                                                       // добавляет связанную таблицу. Если использовать innerJoinWith(), будет работать как where()
           },
       ])->all();*/
     // Обратные связи. Смотри модель User inverseOf() Например есть код:
     // SELECT * FROM `user` WHERE `id` = 1
     //$model = User::findOne(1);
     // SELECT * FROM `profile` WHERE `user_id` = 1
     //$profile = $model->profile2[0];
     // SQL-запрос не выполняется
     //$model2 = $profile->user;
     // выведет "одинаковы"
     //echo ($model === $model2) ? 'одинаковы' : 'НЕ одинаковы';
     $model = Profile::find()->joinWith(['user' => function ($query) {
         $query->onCondition(['user.status' => User::STATUS_NOT_ACTIVE]);
     }])->all();
     return $this->render('index', ['model' => $model]);
 }
예제 #5
0
 public function actionProfiles()
 {
     $dataProvider = new ActiveDataProvider(['query' => Profile::find(), 'pagination' => ['pageSize' => 20]]);
     return $this->render('profiles', ['dataProvider' => $dataProvider]);
 }
예제 #6
0
 public function actionChangePassword()
 {
     $passwordForm = new ChangePasswordForm();
     $paymentForm = Profile::find()->where(['user_id' => Yii::$app->user->identity->id])->one();
     if (!isset($paymentForm)) {
         $paymentForm = new ProfileForm();
     }
     $userForm = User::findOne(Yii::$app->user->identity->id);
     $passwordForm->id = $userForm->id;
     $request = Yii::$app->request;
     if ($request->isPost && $passwordForm->load($request->post()) && $passwordForm->validate()) {
         if ($passwordForm->save()) {
             return $this->redirect(['setting', 'tab' => 'passwordTab', 'alert' => $passwordForm->getAlert()]);
         } else {
             return $this->render('setting', ['userForm' => $userForm, 'passwordForm' => $passwordForm, 'tab' => 'passwordTab', 'paymentForm' => $paymentForm]);
         }
     }
     return $this->render('setting', ['userForm' => $userForm, 'passwordForm' => $passwordForm, 'tab' => 'passwordTab', 'paymentForm' => $paymentForm]);
 }
    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'casenumber')->textInput(['maxlength' => true, 'style' => 'width: 300px']);
?>

   
    <?php 
echo $form->field($model, 'profile_id')->hiddenInput(['value' => Yii::$app->request->get('id')])->label("");
?>
    
    <!--<?php 
$profile = Profile::find()->all();
$listData = ArrayHelper::map($profile, 'profile_id', 'profile_lastname');
echo $form->field($model, 'profile_id')->dropDownList($listData, ['prompt' => 'Select Profile', 'style' => 'width: 300px']);
?>
-->

     
    
    <?php 
$category = Category::find()->all();
$listData = ArrayHelper::map($category, 'category_id', 'category_name');
echo $form->field($model, 'category_id')->dropDownList($listData, ['prompt' => 'Select Category', 'style' => 'width: 300px']);
?>
    

    <div class="form-group">