コード例 #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]);
 }
コード例 #2
0
ファイル: ApiController.php プロジェクト: nicovicz/portalctv
 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]);
 }
コード例 #3
0
ファイル: AuthItemSearch.php プロジェクト: nicovicz/portalctv
 /**
  * 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;
 }
コード例 #4
0
ファイル: AuthRule.php プロジェクト: nicovicz/portalctv
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthItems()
 {
     return $this->hasMany(AuthItem::className(), ['rule_name' => 'name']);
 }
コード例 #5
0
 /**
  * Finds the AuthItem model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return AuthItem the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AuthItem::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #6
0
ファイル: index.php プロジェクト: nicovicz/portalctv
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();
コード例 #7
0
ファイル: AuthAssignment.php プロジェクト: kvaxminsk/evo8
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getItemName()
 {
     return $this->hasOne(AuthItem::className(), ['name' => 'item_name']);
 }
コード例 #8
0
ファイル: index.php プロジェクト: nicovicz/portalctv
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();
コード例 #9
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]);
 }
コード例 #10
0
ファイル: AuthItemChild.php プロジェクト: nicovicz/portalctv
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getChild0()
 {
     return $this->hasOne(AuthItem::className(), ['name' => 'child']);
 }