public function run() { $inModel = $this->model; $model = new Image(); $model->model = $inModel::className(); $model->primaryKey = $this->primaryKey; return $this->render('ImageUploadView', ['fileUploadData' => $model->getWidgetUploadData(), 'primaryKey' => $this->primaryKey, 'inModel' => $this->model, 'model' => $model, 'maxNumberOfFiles' => $this->maxNumberOfFiles]); }
public function actionDelete($id) { $model = Image::findOne($id); if ($model) { $model->delete(); $result = (object) ['success' => true, 'path' => Yii::getAlias(Image::FILE_DIR) . $model->src, 'file' => is_file(Yii::getAlias(Image::FILE_DIROOT) . $model->src)]; echo Json::encode($result); } }
public function getWidgetUploadData() { $results = []; $items = Image::find()->where(['model' => $this->model, 'primaryKey' => $this->primaryKey])->all(); $web = Yii::getAlias(self::FILE_DIR); $webroot = Yii::getAlias(self::FILE_DIROOT); foreach ($items as $item) { $webImage = $web . $item->src; $webrootImage = $webroot . $item->src; $thumb = $item->resize(); $size = filesize($webrootImage); $result = ['name' => $item->src, 'size' => $size, 'url' => $webImage, 'thumbnailUrl' => $thumb, 'deleteUrl' => Url::to(['/cms/admin/image/delete', 'id' => $item->id]), 'deleteType' => "DELETE"]; $results[] = $result; } if ($results) { return Json::encode($results); } return null; }
public function getImage() { return $this->hasOne(Image::className(), ['primaryKey' => 'id'])->andWhere(['model' => self::className()]); }
protected function getImages() { return $this->hasMany(Image::className(), ['primaryKey' => 'id'])->andFilterWhere(['model' => self::className()]); }