Exemple #1
0
 public function run()
 {
     $inModel = $this->model;
     $model = new Image();
     $lang = in_array('lang', $inModel->attributes()) ? $inModel->lang : '';
     $model->model = $inModel::className();
     /*if($lang)
       $model->model.='\\' . $lang;*/
     $model->primaryKey = $this->primaryKey;
     return $this->render('ImageUploadView', ['fileUploadData' => $model->getWidgetUploadData(), 'primaryKey' => $this->primaryKey, 'inModel' => $this->model, 'model' => $model, 'maxNumberOfFiles' => $this->maxNumberOfFiles, 'extensions' => 'image/*', 'lang' => $lang, 'label' => $this->label, 'header' => $this->header]);
 }
Exemple #2
0
 public function actionSortable()
 {
     /** @var  $modelList Attachment[] */
     $data = \Yii::$app->request->get('data');
     foreach ($data as $k => $id) {
         $model = Image::findOne($id);
         if (!$model) {
             continue;
         }
         $model->position = $k + 1;
         $model->save();
     }
 }
Exemple #3
0
 public function getImages()
 {
     return $this->hasMany(Image::className(), ['primaryKey' => 'id'])->andWhere(['model' => self::className()])->orderBy(['position' => SORT_ASC]);
 }
Exemple #4
0
 public function getWidgetUploadData()
 {
     $results = [];
     $items = Image::find()->where(['model' => $this->model, 'primaryKey' => $this->primaryKey])->orderBy(['position' => SORT_ASC])->all();
     $web = $this->getFilePath(false);
     $webroot = $this->getFilePath();
     foreach ($items as $item) {
         if (!is_file($webroot . '/' . $item->src)) {
             $size = 0;
             $thumb = $this->imageThumb . '100x100';
             $webImage = $thumb;
         } else {
             $thumb = $item->resize();
             $webImage = Url::base(true) . '/images/' . $web . '/' . $item->src;
             $webrootImage = $webroot . '/' . $item->src;
             $size = filesize($webrootImage);
         }
         $result = ['name' => $item->id . ' # ' . $item->src, 'size' => $size, 'url' => $webImage, 'thumbnailUrl' => $thumb, 'deleteUrl' => Url::to(['/core/image/delete', 'id' => $item->id]), 'deleteType' => "DELETE"];
         $results[] = $result;
     }
     if ($results) {
         return Json::encode($results);
     }
     return null;
 }
 public function actionImageCacheCreate()
 {
     set_time_limit(0);
     ignore_user_abort(true);
     $path = \Yii::getAlias(THEMEPATH);
     $this->createImageCache($path);
     $images = Image::find()->all();
     $methods = [\yii\image\drivers\Image::AUTO, \yii\image\drivers\Image::CROP];
     foreach ($images as $k => $image) {
         foreach (self::$sizeList as $size) {
             foreach ($methods as $method) {
                 $image->resize($size, $method);
             }
         }
         if (($k + 1) % 10 == 0) {
             header('Ping:pong');
         }
     }
 }