예제 #1
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     $auth = Yii::$app->authManager;
     $role = $auth->getRole($this->jabatan);
     if ($this->validate() && !empty($role)) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->validate() && $user->save()) {
             $person = new Person();
             $person->first_name = $this->first_name;
             $person->last_name = $this->last_name;
             $person->gender = $this->gender;
             $person->birth_date = $this->birth_date;
             $person->user_id = $user->id;
             if ($person->validate() && $person->save()) {
                 $auth->assign($role, $user->id);
                 return true;
             }
         }
     }
     return false;
 }
예제 #2
0
 protected function findPersonModel($id)
 {
     if (($model = Person::findOne(['user_id' => $id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #3
0
 /**
  * Logs in a user using the provided username and password.
  * @return boolean whether the user is logged in successfully
  */
 public function login()
 {
     if ($this->validate()) {
         $person = Person::findOne(['user_id' => $this->getUser()->id]);
         Status::login($person);
         return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
     }
     return false;
 }
예제 #4
0
 public function actionIndex()
 {
     //get role based on user id
     $auth = Yii::$app->authManager;
     $id = Yii::$app->user->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;
     $user = \app\modules\user\models\Person::find()->where(['user_id' => $id])->one();
     $members = (new \yii\db\Query())->from('auth_item')->select(['person.first_name', 'person.last_name'])->where(['rule_name' => $ruleName])->join('INNER JOIN', 'auth_assignment', 'auth_assignment.item_name = auth_item.name')->join('INNER JOIN', 'user', 'user.id = auth_assignment.user_id')->join('INNER JOIN', 'person', 'person.user_id = user.id')->all();
     return $this->render('index', ['ruleName' => $ruleName, 'itemName' => $itemName, 'members' => $members, 'name' => $user->first_name . ' ' . $user->last_name]);
 }
예제 #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Person::find();
     $query->joinWith(['user', 'user.assignment.itemName']);
     $query->where(['user.status' => USER::STATUS_ACTIVE]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['gender' => $this->gender]);
     $query->andFilterWhere(['LIKE', 'CONCAT(first_name, last_name)', $this->full_name]);
     $query->andFilterWhere(['LIKE', 'auth_item.rule_name', $this->divisi]);
     $query->andFilterWhere(['LIKE', 'auth_item.name', $this->jabatan]);
     $dataProvider->sort->defaultOrder = ['id' => SORT_DESC];
     $dataProvider->sort->attributes['full_name'] = ['asc' => ['full_name' => SORT_ASC], 'desc' => ['full_name' => SORT_DESC]];
     $dataProvider->sort->attributes['email'] = ['asc' => ['user.email' => SORT_ASC], 'desc' => ['user.email' => SORT_DESC], 'label' => 'Email'];
     $dataProvider->sort->attributes['jabatan'] = ['asc' => ['auth_item.name' => SORT_ASC], 'desc' => ['auth_item.name' => SORT_DESC]];
     $dataProvider->sort->attributes['divisi'] = ['asc' => ['auth_item.rule_name' => SORT_ASC], 'desc' => ['auth_item.rule_name' => SORT_DESC]];
     return $dataProvider;
 }
예제 #6
0
파일: User.php 프로젝트: nicovicz/portalctv
 public function getPerson()
 {
     return $this->hasOne(Person::className(), ['user_id' => 'id']);
 }
예제 #7
0
      </span>
    </div>
    </div>
    </form>
    </div>
</div>

<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center']], ['label' => 'Tugas Dari', 'headerOptions' => ['class' => 'text-center'], 'value' => function ($data) {
    // menampilkan nama karyawan yang tugas nya bukan dari diri sendiri
    // tugas dari diri sendiri akan diberi label strip (-)
    if ($data->task_from !== Yii::$app->user->id) {
        return $data->userFrom->person->first_name . ' ' . $data->userFrom->person->last_name;
    }
    return '-';
}, 'attribute' => 'task_from', 'filter' => ArrayHelper::map(Person::find()->joinWith(['user'])->asArray()->all(), 'user.id', 'full_name')], ['label' => 'Judul Tugas', 'headerOptions' => ['class' => 'text-center'], 'value' => 'task_title', 'attribute' => 'task_title'], ['label' => 'Tanggal Mulai', 'headerOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'], 'value' => function ($data) {
    $keterangan = date('d F Y', strtotime($data->task_start));
    return $keterangan;
}], ['label' => 'Tanggal Selesai', 'headerOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'], 'value' => function ($data) {
    $keterangan = date('d F Y', strtotime($data->task_end));
    return $keterangan;
}], ['class' => 'yii\\grid\\ActionColumn', 'headerOptions' => ['class' => 'text-center'], 'header' => 'Lampiran', 'template' => '{download}', 'contentOptions' => ['class' => 'text-center'], 'buttons' => ['download' => function ($url, $model) {
    if (!empty($model->attachment)) {
        return Html::a('<i class="fa fa-download fa-2x"></i>', Url::to(['download', 'id' => $model->id]), ['title' => 'Download Lampiran']);
    }
    return '-';
}]], ['value' => function ($model) {
    return Status::getPeriod($model->period);
}, 'attribute' => 'period', 'headerOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'], 'header' => 'Periode'], ['class' => 'yii\\grid\\ActionColumn', 'header' => 'Status Tugas', 'template' => '{update}', 'headerOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'], 'buttons' => ['update' => function ($url, $model) {
    $taskStatus = Status::getTaskStatus($model->status);
    $taskColor = Status::getTaskColor($model->status);