/**
  * Lists all Achievement models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new AchievementSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Ejemplo n.º 2
0
 /**
  * Updates an existing Player model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $image = $model->getAsset(Asset::THUMBNAIL_CONTENT);
     $achievementModel = new AchievementSearch();
     $params = ['AchievementSearch' => ['player_id' => $model->id]];
     $achievementDataProvider = $achievementModel->search($params);
     $model->birthday = date('d.m.Y', strtotime($model->birthday));
     $searchModel = new CareerSearch();
     // careerDataProvider
     $params = ['CareerSearch' => ['player_id' => $model->id]];
     $careerDataProvider = $searchModel->search($params);
     $careerDataProvider->setSort(['defaultOrder' => ['season_id' => SORT_DESC]]);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $uploadedFile = UploadedFile::getInstance($model, 'avatar');
         // If image was uploaded
         if (!empty($uploadedFile)) {
             // Save origionals
             $originalAsset = $model->getAsset();
             if (!isset($originalAsset->id)) {
                 $originalAsset = new Asset();
             }
             $originalAsset->assetable_type = Asset::ASSETABLE_PLAYER;
             $originalAsset->assetable_id = $model->id;
             $originalAsset->uploadedFile = $uploadedFile;
             $originalAsset->saveAsset();
             // Save thumbnails
             $imageID = $originalAsset->id;
             $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_PLAYER);
             foreach ($thumbnails as $thumbnail) {
                 $asset = $model->getAsset($thumbnail);
                 if (!isset($asset->id)) {
                     $asset = new Asset();
                 }
                 $asset->assetable_type = Asset::ASSETABLE_PLAYER;
                 $asset->assetable_id = $model->id;
                 $asset->parent_id = $imageID;
                 $asset->thumbnail = $thumbnail;
                 $asset->uploadedFile = $uploadedFile;
                 $asset->cropData = $model->cropData;
                 $asset->saveCroppedAsset();
             }
         }
         $model->slug = $model->genSlug();
         $model->birthday = date('Y-m-d', strtotime($model->birthday));
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model, 'achievementModel' => $achievementModel, 'achievementDataProvider' => $achievementDataProvider, 'image' => $image, 'careerDataProvider' => $careerDataProvider]);
 }