/**
  * Lists all Request models.
  * @return mixed
  */
 public function actionIndex()
 {
     if (!Yii::$app->user->can("admin")) {
         throw new HttpException(403, 'You are not allowed to perform this action.');
     }
     $dataProvider = new ActiveDataProvider(['query' => Request::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
 /**
  * AJAX
  * Удаляет запрос
  */
 public function actionDelete_ajax()
 {
     $request = Request::find(self::getParam('id'));
     if (is_null($request)) {
         return self::jsonError('Нет такого запроса');
     }
     $request->delete();
     return self::jsonSuccess();
 }
示例#3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Request::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->joinWith('area');
     $dataProvider->sort->attributes['area_name'] = ['asc' => ['areas.name' => SORT_ASC], 'desc' => ['areas.name' => SORT_DESC]];
     $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(['id' => $this->id, 'area_id' => $this->area_id, 'creation_date' => $this->creation_date, 'completion_date' => $this->completion_date]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'areas.name', $this->area_name]);
     return $dataProvider;
 }
 /**
  * Commits the request if all the files have
  * been dealt with
  */
 private function commitRequest($request_id)
 {
     if (!Yii::$app->user->can("admin")) {
         throw new HttpException(403, 'You are not allowed to perform this action.');
     }
     $requests = RequestFile::find()->where(['request_id' => $request_id])->andWhere(['granted' => NULL])->all();
     if (sizeof($requests) == 0) {
         $request = Request::find()->where(['id' => $request_id])->one();
         $request->committed = 1;
         $request->save();
     }
 }
示例#5
0
文件: _form.php 项目: Hyuchiha/SAU
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\UsersRequest */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="users-request-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'request_id')->dropDownList(
        ArrayHelper::map(
            Request::find()->all(),'id','subject')
        , array('prompt' => "")
    ) ?>

    <?= $form->field($model, 'user_id')->dropDownList(
        ArrayHelper::map(
            User::find()->all(),'id','first_name')
        , array('prompt' => "")
    ) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>
 public function actionTab($tab)
 {
     $searchModel = new RequestSearch();
     $html = null;
     switch ($tab) {
         case 1:
             $query = Request::find()->where(['user_id' => Yii::$app->user->id]);
             $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $query);
             $html = $this->renderPartial('GridViewMyRequest', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
             break;
         case 2:
             $query = Request::find()->joinWith('usersRequests')->where(['users_request.user_id' => Yii::$app->user->id]);
             $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $query);
             $html = $this->renderPartial('GridViewRequestAssigned', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
             break;
         case 3:
             $area = Area::find()->where(['id_responsable' => Yii::$app->user->id])->one();
             $query = Request::find()->joinWith('areasRequests')->where(['areas_request.area_id' => $area->id]);
             $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $query);
             $html = $this->renderPartial('GridViewRequestForArea', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
             break;
         case 4:
             $dataProvider = $searchModel->search(Yii::$app->request->queryParams, null);
             $html = $this->renderPartial('GridViewAllRequest', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
             break;
         case 5:
             $query = Request::find()->where(['status' => 'Calendarizada']);
             $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $query);
             $html = $this->renderPartial('GridViewRequestScheduled', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
             break;
     }
     return JSON::encode($html);
 }
 public static function isRequestBetween(UserId $user1_id, UserId $user2_id, $req_type)
 {
     if (!RequestType::isValid($req_type)) {
         throw new InvalidEnumKeyException("Value: " . $req_type);
     }
     return Request::find()->where(['user1_id' => $user1_id->getId(), 'user2_id' => $user2_id->getId()])->orWhere(['user1_id' => $user2_id->getId(), 'user2_id' => $user1_id->getId()])->exists();
 }