Example #1
0
 public function actionIndex()
 {
     if (!Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = $this->signupForm;
     $modelAuthRule = new AuthRule();
     $modelAuthItem = new AuthItem();
     $authRule = AuthRule::find()->all();
     $authItem = AuthItem::find()->all();
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post())) {
             try {
                 $transaction = Yii::$app->db->beginTransaction();
                 if ($model->signup()) {
                     $transaction->commit();
                     Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Pendaftaran Karyawan Berhasil'));
                     return $this->redirect(['/user/signup']);
                 } else {
                     throw new \Exception("Signup validation savepoint failed");
                 }
             } catch (\Exception $e) {
                 Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Pendaftaran Karyawan Gagal'));
                 $transaction->rollback();
             }
         }
     }
     return $this->render('index', ['model' => $model, 'modelAuthRule' => $modelAuthRule, 'authRule' => $authRule, 'modelAuthItem' => $modelAuthItem, 'authItem' => $authItem]);
 }
Example #2
0
 public function actionSearchRole()
 {
     $ruleName = $_POST['depdrop_parents'][0];
     $authItem = AuthItem::find()->where(['rule_name' => $ruleName])->all();
     $data = [];
     foreach ($authItem as $item) {
         $data[] = ['id' => $item->name, 'name' => $item->name];
     }
     echo Json::encode(['output' => $data]);
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AuthItem::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(['type' => $this->type, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'rule_name', $this->rule_name])->andFilterWhere(['like', 'data', $this->data]);
     return $dataProvider;
 }
 /**
  * Updates an existing AuthItem model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $parent = AuthItemChild::find()->where(['child' => $model->name])->one();
     if (Yii::$app->request->isPost) {
         $oldRole = $model->name;
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
             $role = $this->auth->getRole($oldRole);
             if (empty($role)) {
                 Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Jabatan Gagal Diubah'));
             } else {
                 $role->name = $model->name;
                 $role->description = $model->description;
                 $role->data = Yii::$app->request->post('routers');
                 $role->ruleName = $model->rule_name;
                 $this->auth->update($oldRole, $role);
                 Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Data Jabatan Berhasil Diubah'));
                 return $this->redirect(['index']);
             }
         } else {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Jabatan Gagal Diubah'));
         }
     }
     $routers = RouterGenerator::run();
     ksort($routers);
     $children = AuthItem::find()->all();
     $rule = AuthRule::find()->all();
     return $this->render('update', ['model' => $model, 'routers' => $routers, 'registeredRouters' => $this->auth->getRole($model->name), 'children' => $children, 'rule' => $rule, 'parent' => $parent]);
 }
Example #5
0
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\user\models\AuthItemSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Management Jabatan');
$this->params['breadcrumbs'][] = $this->title;
Panel::begin(['title' => $this->title, 'icon' => 'fa fa-file-text-o']);
?>

    <?php 
echo AlertBlock::widget(['type' => AlertBlock::TYPE_ALERT, 'useSessionFlash' => true]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Tambah Data Jabatan'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center']], ['attribute' => 'name', 'filter' => ArrayHelper::map(AuthItem::find()->asArray()->all(), 'name', 'name'), 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center']], ['attribute' => 'rule_name', 'filter' => ArrayHelper::map(AuthRule::find()->asArray()->all(), 'name', 'name'), 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center']], ['label' => Yii::t('app', 'Dibawahi Oleh'), 'value' => function ($data) {
    $str = [];
    foreach ($data->authItemChildren0 as $children) {
        $str[] = $children['parent'];
    }
    return implode(',', $str);
}, 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center']], ['attribute' => 'created_at', 'filter' => false, 'format' => ['date', 'php:d F Y'], 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center']], ['attribute' => 'updated_at', 'filter' => false, 'format' => ['date', 'php:d F Y'], 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update}', 'contentOptions' => ['class' => 'text-center']]]]);
?>

<?php 
Panel::end();
Example #6
0
use app\components\Panel;
use kartik\alert\AlertBlock;
use yii\helpers\ArrayHelper;
use app\modules\user\models\AuthItem;
use app\modules\user\models\AuthRule;
use app\components\Status;
/* @var $this yii\web\View */
/* @var $searchModel app\models\PersonSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Manajemen Karyawan');
$this->params['breadcrumbs'][] = $this->title;
?>


<?php 
Panel::begin(['title' => $this->title, 'icon' => 'fa fa-file-text-o']);
echo AlertBlock::widget(['type' => AlertBlock::TYPE_ALERT, 'useSessionFlash' => true]);
?>
    <p>
        <?php 
echo Html::a('<i class="fa fa-plus"></i> ' . Yii::t('app', 'Tambah Data Karyawan'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>
<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center']], ['attribute' => 'full_name', 'value' => 'full_name', 'headerOptions' => ['class' => 'text-center']], ['value' => function ($model) {
    return Status::getGender($model->gender);
}, 'attribute' => 'gender', 'contentOptions' => ['class' => 'text-center'], 'filter' => Status::getGenderList(), 'headerOptions' => ['class' => 'text-center']], ['value' => 'user.assignment.itemName.name', 'attribute' => 'jabatan', 'filter' => ArrayHelper::map(AuthItem::find()->asArray()->all(), 'name', 'name'), 'headerOptions' => ['class' => 'text-center']], ['value' => 'user.assignment.itemName.rule_name', 'attribute' => 'divisi', 'filter' => ArrayHelper::map(AuthRule::find()->asArray()->all(), 'name', 'name'), 'headerOptions' => ['class' => 'text-center']], ['value' => 'user.email', 'attribute' => 'email', 'headerOptions' => ['class' => 'text-center']], ['class' => 'yii\\grid\\ActionColumn', 'contentOptions' => ['class' => 'text-center']]]]);
?>

<?php 
Panel::end();
Example #7
0
 /**
  * Updates an existing Person model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelUser = $this->findUserModel($model);
     $modelAuthRule = new AuthRule();
     $modelAuthItem = new AuthItem();
     $authRule = AuthRule::find()->all();
     $authItem = AuthItem::find()->all();
     $id = $modelUser->id;
     $app = \app\modules\user\models\AuthAssignment::find()->with(['itemName.ruleName'])->where(['user_id' => $id])->one();
     $ruleName = $app->itemName->ruleName->name;
     $itemName = $app->itemName->name;
     if (Yii::$app->request->isPost) {
         // do transaction if fails it will not saved
         $transaction = Yii::$app->db->beginTransaction();
         try {
             if ($modelUser->load(Yii::$app->request->post()) && $modelUser->validate()) {
                 $modelUser->generateAuthKey();
                 // first attempt save user record
                 if ($modelUser->save()) {
                     if ($model->load(Yii::$app->request->post())) {
                         $model->user_id = $modelUser->id;
                         // second attemp save person record
                         if ($model->validate() && $model->save()) {
                             if ($modelAuthItem->load(Yii::$app->request->post()) && $modelAuthItem->validate()) {
                                 $auth = Yii::$app->authManager;
                                 $role = $auth->getRole($modelAuthItem->name);
                                 $oldRole = $modelUser->assignment->itemName->name;
                                 // if role from dropdown exists in table authItem
                                 // and old role is not same as new input role from
                                 // dropdown then revoke old one then assig the new one
                                 if (!empty($role)) {
                                     // thrid attempt revoke and assign role to user
                                     if ($oldRole !== $role->name) {
                                         $oldRoleObject = $auth->getRole($oldRole);
                                         $auth->revoke($oldRoleObject, $modelUser->id);
                                         $auth->assign($role, $modelUser->id);
                                         $transaction->commit();
                                     } else {
                                         $transaction->commit();
                                     }
                                     Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Data Karyawan Berhasil Diubah'));
                                     return $this->redirect(['index']);
                                 } else {
                                     throw new \Exception("AuthRole search data checkpoint fail to save");
                                 }
                             } else {
                                 throw new \Exception("AuthItem (Role) validation checkpoint fail to save");
                             }
                         } else {
                             throw new \Exception("Person save checkpoint fail to save");
                         }
                     } else {
                         throw new \Exception("Person loaded checkpoint fail to save");
                     }
                 } else {
                     throw new \Exception("User save checkpoint fail to save");
                 }
             } else {
                 throw new \Exception("User validation checkpoint fail to save");
             }
         } catch (\Exception $e) {
             $transaction->rollback();
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Karyawan Gagal Diubah'));
         }
     }
     return $this->render('update', ['model' => $model, 'modelUser' => $modelUser, 'modelAuthRule' => $modelAuthRule, 'authRule' => $authRule, 'modelAuthItem' => $modelAuthItem, 'authItem' => $authItem, 'ruleName' => $ruleName, 'itemName' => $itemName]);
 }