/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AdvisorGroup::find();
     if (!isset($params['sort'])) {
         $query->orderBy(['id_advisor_group' => SORT_DESC]);
     }
     $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(['id_advisor_group' => $this->id_advisor_group, 'id_advisor' => $this->id_advisor, 'id_group' => $this->id_group, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }
 /**
  * Lists all Application models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new ApplicationSearch();
     if ($this->user->id_user_role == Dict::USER_ROLE_ADVISOR) {
         $advisor = Advisor::find()->andWhere(['id_user' => $this->user->id])->one();
         //find related groups
         $id_groups = AdvisorGroup::find()->andWhere(['id_advisor' => $advisor['id_advisor']])->all();
         $ids = [];
         foreach ($id_groups as $value) {
             $ids[] = $value['id_group'];
         }
         $query = Application::find()->andWhere(['in', 'id_group', $ids]);
         //->orderBy(['id_application' => SORT_DESC]);
         $dataProvider = $searchModel->search(Yii::$app->request->get(), $query);
     } else {
         if ($this->user->id_user_role == Dict::USER_ROLE_BETTERDEBT) {
             $query = Application::find();
             $dataProvider = $searchModel->search(Yii::$app->request->get(), $query);
         }
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $userModel = User::find()->andWhere(['id_user' => $model->id_user])->one();
     if ($this->user->id_user_role == Dict::USER_ROLE_CLIENT) {
         if ($model->id_user != $this->user->id) {
             throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page.");
         }
     } else {
         if ($this->user->id_user_role == dict::USER_ROLE_ADVISOR) {
             $advisor = Advisor::findOne(['id_user' => $this->user->id_user]);
             $groups = AdvisorGroup::find()->andWhere(['id_advisor' => $advisor->id_advisor])->all();
             $id_groups = [];
             foreach ($groups as $val) {
                 $id_groups[] = $val->id_group;
             }
             // check
             if (!in_array($model->id_group, $id_groups)) {
                 throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page.");
             }
         }
     }
     //validate email
     if (Yii::$app->request->isAjax && $userModel->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($userModel);
     }
     if ($model->load(Yii::$app->request->post()) && $userModel->load(Yii::$app->request->post())) {
         $arr = ['User' => $_POST['User'], 'Client' => $_POST['Client']];
         $result = $userModel->UserUpdate($this->_roleId, $arr, $id);
         if ($result) {
             return $this->redirect(['index']);
         } else {
             return $this->render('update', ['model' => $model, 'userModel' => $userModel]);
         }
     } else {
         return $this->render('update', ['model' => $model, 'userModel' => $userModel]);
     }
 }
 /**
  *
  * @return 返回同一个institution下面的advisor
  */
 public function actionSub()
 {
     $id = Yii::$app->request->get('id_group');
     $ids = [];
     if ($id != '') {
         //find id_advisor according to id_group
         $id_array = AdvisorGroup::find()->andWhere(['id_group' => $id])->all();
         if (!empty($id_array)) {
             foreach ($id_array as $value) {
                 $ids[] = $value->id_advisor;
             }
         }
     }
     $out = [];
     if (isset($_POST['depdrop_parents'])) {
         $parents = $_POST['depdrop_parents'];
         if ($parents != null) {
             $id_institution = $parents[0];
             $out = self::getAdvisor($id_institution);
             echo json_encode(['output' => $out, 'selected' => $ids]);
             return;
         }
     }
     echo json_encode(['output' => '', 'selected' => '']);
 }
Exemple #5
0
    } else {
        return '0';
    }
}], ['class' => 'backend\\widgets\\ActionColumn', 'template' => '{invite}{view}{update}{delete}', 'width' => '18%', 'buttons' => ['invite' => function ($url, $model, $key) {
    if ($model->user) {
        if ($model->user->status == 0) {
            $options = ['class' => 'btn btn-light btn-icon', 'title' => Yii::t('yii', 'Invite'), 'aria-label' => Yii::t('yii', 'Invite'), 'data-confirm' => Yii::t('yii', 'Are you sure invite this advisor to email?'), 'data-pjax' => '0'];
            return Html::a('<span class="glyphicon">&#xe621;</span>', $url, $options);
        }
    }
}, 'cancelinvite' => function ($url, $model, $key) {
    $options = ['class' => 'btn btn-light btn-icon', 'title' => Yii::t('yii', 'Cancel Invition'), 'aria-label' => Yii::t('yii', 'Cancel Invition'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to cancel invition?'), 'data-pjax' => '0'];
    return Html::a('<span class="fa fa-mail-reply"></span>', $url, $options);
}], 'detailViewAttributes' => function ($model, $key) {
    //find relation Group with id_advisor
    $arrays_group = AdvisorGroup::find()->andWhere(['id_advisor' => $model->id_advisor])->all();
    if (!empty($arrays_group)) {
        $result = [];
        foreach ($arrays_group as $v) {
            $res = GroupView::find()->andWhere(['id_group' => $v->id_group])->all();
            if (!empty($res)) {
                foreach ($res as $val) {
                    $result[] = $val['name'];
                }
            }
        }
    }
    return ['id_advisor', ['label' => 'Institution Name', 'value' => $model->institution ? $model->institution->institution_name : ''], ['label' => 'Office Name', 'value' => $model->office ? $model->office->office_id : ''], 'advisor_id', ['label' => 'First Name', 'value' => $model->user ? $model->user->first_name : ''], ['label' => 'Mid Name', 'value' => $model->user ? $model->user->mid_name : ''], ['label' => 'Last Name', 'value' => $model->user ? $model->user->last_name : ''], ['label' => 'Email', 'value' => $model->user ? $model->user->email : ''], 'phone', ['label' => 'Trained', 'value' => $model->trained ? 'No' : 'Yes'], ['label' => 'approved', 'value' => $model->approved ? 'No' : 'Yes'], 'train_date:datetime', 'created_at:datetime', 'updated_at:datetime', ['label' => 'id_group', 'value' => empty($result) ? 'No' : implode('/', $result)]];
}]]]);
?>
			</div>
Exemple #6
0
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id_group', ['attribute' => 'id_custodian', 'value' => function ($model) {
    if ($model->custodian) {
        return $model->custodian->name;
    } else {
        return 'Unknown';
    }
}], 'group_id', 'name', 'created_at:datetime', 'updated_at:datetime', ['label' => 'Advisor Count', 'value' => function ($model) {
    if ($model->advisorGroups) {
        return count($model->advisorGroups);
    } else {
        return '0';
    }
}], ['class' => 'backend\\widgets\\ActionColumn', 'width' => '18%', 'template' => '{view} {update} {delete}', 'detailViewAttributes' => function ($model, $key) {
    $arrays_advisor = AdvisorGroup::find()->andWhere(['id_group' => $model->id_group])->all();
    if (!empty($arrays_advisor)) {
        $result = [];
        foreach ($arrays_advisor as $v) {
            $advisor_u = advisor::find()->Where(['id_advisor' => $v['id_advisor']])->asArray()->one();
            $res = User::find()->andWhere(['id_user' => $advisor_u['id_user']])->asArray()->one();
            $result[] = $res['first_name'] . ' ' . $res['last_name'];
        }
    }
    return ['id_group', ['label' => 'Custodian', 'value' => $model->custodian ? $model->custodian->name : 'Unknown'], ['label' => 'advisor', 'value' => empty($result) ? 'No' : implode('/', $result)], 'group_id', 'created_at:datetime', 'updated_at:datetime'];
}]]]);
?>
      </div>
    </div>
    <!-- End Panel -->
  </div>