| Current Path : /var/www/html/ekursus/backend/controllers/ |
| Current File : /var/www/html/ekursus/backend/controllers/SysUserController.php |
<?php
namespace backend\controllers;
use Yii;
use backend\models\SysUser;
use backend\models\SysUserSearch;
use backend\models\Staff;
use backend\models\StaffSearch;
use backend\models\User;
use backend\models\UserSearch;
use backend\models\StaffAccess;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* SysUserController implements the CRUD actions for SysUser model.
*/
class SysUserController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all SysUser models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new SysUserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
public function actionUpdateKey()
{
$myarr = (array)Yii::$app->request->post('selection');
foreach ($myarr as $arr) {
$sysuser = SysUser::find()->where(['id_pengguna'=>$arr])->one();
$user = new User();
$user->username = $sysuser->id_pengguna;
$user->password_hash = Yii::$app->security->generatePasswordHash($contractor->katalaluan);
$user->auth_key = Yii::$app->security->generateRandomString();
$user->kod_negeri = $sysuser->kod_negeri;
$user->status = '10';
if($user->save(false)) {
$staff = new Staff();
$staff->userid = $user->id;
$staff->staff_name = $sysuser->nama;
if($staff->save(false)) {
$staffaccess = new StaffAccess();
$staffaccess->staff_info_id = $staff->id;
$staffaccess->role_code = $sysuser->had_capaian;
if($staffaccess->save(false)) {
}
}
}
}
$searchModel = new SysUserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single SysUser model.
* @param string $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new SysUser model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new SysUser();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_pengguna]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing SysUser model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param string $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_pengguna]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing SysUser model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param string $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the SysUser model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $id
* @return SysUser the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = SysUser::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
}