/**
  * Creates a new Team model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Team();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $uploadedFile = UploadedFile::getInstance($model, 'icon');
         $model->save(false);
         if (!empty($uploadedFile)) {
             // Save origionals
             $originalAsset = new Asset();
             $originalAsset->assetable_type = Asset::ASSETABLE_TEAM;
             $originalAsset->assetable_id = $model->id;
             $originalAsset->uploadedFile = $uploadedFile;
             $originalAsset->saveAsset();
             // Save thumbnails
             $imageID = $originalAsset->id;
             $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_TEAM);
             foreach ($thumbnails as $thumbnail) {
                 $asset = new Asset();
                 $asset->assetable_type = Asset::ASSETABLE_TEAM;
                 $asset->assetable_id = $model->id;
                 $asset->parent_id = $imageID;
                 $asset->thumbnail = $thumbnail;
                 $asset->uploadedFile = $uploadedFile;
                 $asset->saveAsset();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #2
0
 /**
  * Creates a new Team model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Team();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Team model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($event_id = null)
 {
     $model = new Team();
     $model->event_id = $event_id;
     $events = Event::findAll(['active' => true]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'events' => $events]);
     }
 }
Example #4
0
 /**
  * Creates a new Team model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Team();
     if ($model->load(Yii::$app->request->post())) {
         $image = Upload::uploadImage($model);
         if ($model->save()) {
             // upload only if valid uploaded file instance found
             if ($image !== false) {
                 $path = Upload::getImageFile($image);
                 $image->saveAs($path);
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }