Esempio n. 1
0
 /**
  * Creates a new Route model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $rootPath = Yii::$app->params['route_img_dir'];
     $model = new Route();
     $status = Lookup::items("RouteStatus");
     if ($model->load(Yii::$app->request->post())) {
         $image = UploadedFile::getInstance($model, 'img');
         $ext = $image->getExtension();
         $randName = time() . rand(1000, 9999) . "." . $ext;
         $path = abs(crc32($randName) % 500);
         $rootPath = $rootPath . "img/";
         if (!file_exists($rootPath)) {
             mkdir($rootPath, 0777, true);
         }
         $image->saveAs($rootPath . $randName);
         $model->img = $rootPath . $randName;
         if ($model->save()) {
             $is_joined = Join::find()->andWhere(['user_id' => $model->author_id, 'route_id' => $model->id])->all() == null;
             if ($is_joined) {
                 $join = new Join();
                 $join->user_id = $model->author_id;
                 $join->route_id = $model->id;
                 $join->save();
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'status' => $status]);
     }
 }
Esempio n. 2
0
 /**
  * Deletes an existing Route model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionJoinus()
 {
     $model = new Join();
     $result['msg'] = "";
     $in = Yii::$app->request->post();
     //print_r($in);
     $model->user_id = $in["user_id"];
     $model->route_id = $in["route_id"];
     if (Yii::$app->request->post()) {
         $is_joined = Join::find()->andWhere(['user_id' => $model->user_id, 'route_id' => $model->route_id])->all() !== null;
         if ($is_joined) {
             $result['msg'] = "You have successfully joined, please do not repeat to join!";
         } else {
             if ($model->save()) {
                 $result['msg'] = "successfully joined!";
             }
         }
     }
     exit(json_encode($result));
 }