/**
  * Finds the Request model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Request the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Request::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * AJAX
  * Удаляет запрос
  */
 public function actionDelete_ajax()
 {
     $request = Request::find(self::getParam('id'));
     if (is_null($request)) {
         return self::jsonError('Нет такого запроса');
     }
     $request->delete();
     return self::jsonSuccess();
 }
 /**
  * Регистрирует посещение
  * @param $target_id
  * @param $target_type
  */
 public static function enrol($target_id, $target_type)
 {
     $user_id = 0;
     $user_model = \Auth::user();
     if ($user_model) {
         $user_id = $user_model->id;
     }
     $request = \Request::instance();
     self::create(['user_id' => $user_id, 'user_ip' => $request->getClientIp(), 'target_id' => $target_id, 'target_type' => $target_type]);
 }
Example #4
0
 public function add($stock_id)
 {
     if ($this->validate()) {
         $stock = Stock::find($stock_id);
         $request = Request::insert(['stock_id' => $stock_id, 'month' => $this->monthCounter]);
         Application::mail(User::find(Yii::$app->params['chat']['consultant_id'])->getEmail(), 'Запрос на добавление услуги', 'request', ['stock' => $stock, 'user' => \Yii::$app->user->identity, 'request' => $request]);
         return true;
     } else {
         return false;
     }
 }
Example #5
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;
 }
Example #6
0
 /**
  * TODO 本来之前用setXAttribute方式来做的默认值,但是看源码需要有这三个值传过来才行,SO。。。
  */
 protected static function boot()
 {
     static::creating(function (Comment $comment) {
         $comment->ip = \Request::getClientIp();
         $comment->user_agent = \Request::header('User-Agent');
         $comment->status = static::STATUS_VERIFY;
         if (!\Auth::guest()) {
             $comment->user_id = \Auth::user()->id;
         }
         //TODO 目前没有好的xss解决办法(HtmlPurifier会将<script>标签去掉, 导致评论有可能和原意不一致)
         $pattern = ['/(<\\s*?script\\s*?>.*?<\\s*?\\/\\s*?script\\s*?>)/i', '/(<\\s*?style\\s*?>.*<\\s*?\\/?style\\s*?>)/i'];
         $replacement = ["\n```javascript\n\$1\n```\n", "\n```css\n\$1\n```\n"];
         $comment->text = strip_tags(preg_replace($pattern, $replacement, $comment->text), '<script><style>');
     });
     static::created(function (Comment $comment) {
         //            if ($comment->parent_id > 0 && $replyComment = static::active()->find($comment->parent_id)) {
         //TODO 发送邮件(这儿应该还要根据at的人再发邮件...)
         //            }
     });
     parent::boot();
 }
Example #7
0
 public static function fromToken($already_parsed = false)
 {
     $usuario = [];
     $token = [];
     try {
         if ($already_parsed) {
             $token = $already_parsed;
             $usuario = JWTAuth::toUser($token);
         } else {
             $token = JWTAuth::parseToken();
             if ($token) {
                 try {
                     $usuario = $token->toUser();
                 } catch (Exception $e) {
                     //Request::header();
                     abort(401, 'error con $token->toUser()');
                 }
             } else {
                 if (!Request::has('username')) {
                     abort(401, 'No existe Token');
                 }
             }
         }
         if (!$usuario) {
             abort(401, 'Token inválido, prohibido entrar.');
         }
     } catch (JWTException $e) {
         abort(401, 'token_expired');
     }
     // *************************************************
     //    Traeremos los roles y permisos
     // *************************************************
     //User::roles_y_permisos($usuario);
     $usuario = User::datos_usuario_logueado($usuario);
     $usuario->token = $token;
     return (array) $usuario;
 }
Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRequest()
 {
     return $this->hasOne(Request::className(), ['id' => 'request_id']);
 }
Example #9
0
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(); ?>
Example #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRequests()
 {
     return $this->hasMany(Request::className(), ['id' => 'request_id'])->viaTable('category_request', ['category_id' => 'id']);
 }
 /**
  * AJAX
  *
  * REQUEST:
  * - monthcounter - int - количество покупамых месяцев
  * - stock_id - int - идентификатор акции
  */
 public function actionAdd_step1()
 {
     $monthCounter = self::getParam('monthcounter');
     $stockId = self::getParam('stock_id');
     $request = Request::insert(['stock_id' => $stockId, 'month' => $monthCounter]);
     Application::mail(User::find(Yii::$app->params['chat']['consultant_id'])->getEmail(), 'Запрос на добавление услуги', 'request', ['stock' => Stock::find($stockId), 'user' => \Yii::$app->user->identity, 'request' => $request]);
     return self::jsonSuccess(['user' => ['email' => Yii::$app->user->identity->getEmail(), 'fio' => Yii::$app->user->identity->getNameFull()], 'request' => ['id' => $request->getId(), 'sum' => $monthCounter * 100 * 65]]);
 }
 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);
 }
Example #13
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRequests()
 {
     return $this->hasMany(Request::className(), ['id_anak' => 'id_data_diri_anak']);
 }
 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();
 }
Example #15
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRequests0()
 {
     return $this->hasMany(Request::className(), ['service_id' => 'id']);
 }
 /**
  * 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();
     }
 }
Example #17
0
 /**
  * @param $id
  */
 public function delete($id)
 {
     $req = Request::findOrFail($id);
     $req->delete();
 }
Example #18
0
 public function actionRequests()
 {
     return $this->render(['items' => \app\models\Request::query(['user_id' => \Yii::$app->user->id])->all()]);
 }