Your IP : 216.73.216.79


Current Path : /var/www/html/ekursus/backend/controllers/
Upload File :
Current File : /var/www/html/ekursus/backend/controllers/ContractorStaffController.php

<?php

namespace backend\controllers;

use Yii;
use backend\models\contractorstaff\ContractorStaff;
use backend\models\contractorstaff\ContractorStaffSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * ContractorStaffController implements the CRUD actions for ContractorStaff model.
 */
class ContractorStaffController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all ContractorStaff models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new ContractorStaffSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single ContractorStaff model.
     * @param integer $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 ContractorStaff model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new ContractorStaff();
        $id = Yii::$app->user->identity->staff->id;
        $staff = \backend\models\Staff::findOne($id);
        $user = \common\models\User::findOne($staff->userid);

        $model->no_spkk = $user->username;
        $model->created_at = date('Y-m-d H:i:s');
        $model->created_by = Yii::$app->user->identity->username;

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['update', 'id' => $model->contractor_staff_id]);
        }

        return $this->render('create', [
            'model' => $model,
        ]);
    }

    /**
     * Updates an existing ContractorStaff model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        $model->updated_at = date('Y-m-d H:i:s');
        $model->updated_by = Yii::$app->user->identity->username;

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->contractor_staff_id]);
        }

        return $this->render('update', [
            'model' => $model,
        ]);
    }

    public function actionLists($no_spkk)
    {               
        $posts = \backend\models\contractor\Contractor::find()
                ->where(['no_spkk' => $no_spkk])
                ->orderBy('no_spkk DESC')
                ->all();
                
        if (!empty($posts)) {
            foreach($posts as $post) {
                echo "<option value='".$post->no_spkk."'>".$post->contractor_staff_name."</option>";
            }
        } else {
            echo "<option>-</option>";
        }
        
    }

    /**
     * Deletes an existing ContractorStaff model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $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 ContractorStaff model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return ContractorStaff the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = ContractorStaff::findOne($id)) !== null) {
            return $model;
        }

        throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
    }
}