Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Job::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(['like', '_id', $this->_id])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'company_name', $this->company_name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'number_vacancy', $this->number_vacancy]);
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getJob()
 {
     return $this->hasOne(Job::className(), ['id' => 'job_id']);
 }
Example #3
0
<?php

use yii\grid\GridView;
use yii\data\ActiveDataProvider;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\Job;
/* @var $this yii\web\View */
$this->title = 'Jobs';
$this->params['breadcrumbs'][] = $this->title;
$dataProvider = new ActiveDataProvider(['query' => Yii::$app->user->can('admin') ? Job::find() : Job::findByUser(Yii::$app->user->identity->username), 'pagination' => ['pageSize' => 20]]);
?>

<div class="box">
  <div class="box-body">

<?php 
if (Yii::$app->user->can('listResources')) {
    echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'description'], ['attribute' => 'firmware', 'value' => function ($model, $index, $widget) {
        return $model->firmware && $model->firmware->description ? $model->firmware->description : '';
    }], ['attribute' => 'scanner', 'value' => function ($model, $index, $widget) {
        return $model->scanner && $model->scanner->name ? $model->scanner->name : '(not set)';
    }], ['attribute' => 'status', 'value' => function ($model, $index, $widget) {
        return $model->getCurrentStatus();
    }], ['attribute' => 'created_at', 'format' => ['datetime', 'php:Y-m-d H:i:s']], ['attribute' => 'updated_at', 'format' => ['datetime', 'php:Y-m-d H:i:s']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete} {view} {schedule} {reset}', 'buttons' => ['delete' => function ($url, $model, $key) {
        if ($model->canDelete()) {
            return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['//job/delete', 'id' => $model->id], ['data-pjax' => 0, 'data-method' => 'post', 'data-confirm' => 'Are you sure you want to delete this item?', 'aria-label' => "Delete", 'title' => 'Delete']);
        }
        return '<span class="glyphicon glyphicon-trash text-muted"></span>';
    }, 'schedule' => function ($url, $model, $key) {
        if ($model->canSchedule()) {
Example #4
0
 /**
  * Finds the Job model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $_id
  * @return Job the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Job::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionReset()
 {
     if (Yii::$app->user->can('updateResource')) {
         $model = Job::findOne(['id' => Yii::$app->request->get('id')]);
         if ($model->reset()) {
             $model->save();
             Yii::$app->getSession()->setFlash('success', 'Job reset.');
         } else {
             Yii::$app->getSession()->setFlash('error', 'Failed to reset job.');
         }
     } else {
         Yii::$app->getSession()->setFlash('error', 'Not allowed.');
     }
     return $this->redirect(['index']);
 }
Example #6
0
 public function actionProfile()
 {
     $model_profile = new Profile();
     $model_pass = new ChangePassword();
     $user = new User();
     $info = $user->getUserInfo(Yii::$app->user->getId());
     $message = "";
     if ($model_profile->load(Yii::$app->request->post()) && $model_profile->validate()) {
         foreach ($model_profile as $key => $value) {
             if ($model_profile->{$key}) {
                 $info->setAttribute($key, Html::encode($model_profile->{$key}));
             }
         }
         $info->update();
         $message = "Changes saved";
     }
     if ($model_pass->load(Yii::$app->request->post()) && $model_pass->validate()) {
         if ($model_pass->new_password == $model_pass->new_password_rep) {
             $info->setAttribute('password_hash', Yii::$app->security->generatePasswordHash(Html::encode($model_pass->new_password)));
             $info->update();
             $message = "Changes saved";
         }
     }
     $model = new Job();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['../job/view', 'id' => (string) $model->_id]);
     }
     return $this->render('profile', ['model_profile' => $model_profile, 'model_pass' => $model_pass, 'info' => $info, 'message' => $message, 'model' => $model]);
 }
Example #7
0
 /**
  *
  * @return \yii\db\ActiveQuery
  */
 public function findByUser($id)
 {
     return Job::find()->where(['created_by' => $id]);
 }