/**
  * Delete model with medias
  * @param $id
  * @return array
  */
 public function actionDelete($id)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if (Yii::$app->user->isGuest) {
         return ['error' => 'Please, authorise to delete files.'];
     }
     $tableName = Media::tableName();
     /**
      * @var yeesoft\media\models\Media
      */
     $model = Media::findOne(["{$tableName}.id" => $id, "{$tableName}.created_by" => Yii::$app->user->identity->id]);
     if (!$model) {
         return ['error' => Yii::t('yii', 'You are not allowed to perform this action.')];
     }
     if ($model->isImage()) {
         $model->deleteThumbs($this->routes);
     }
     $model->deleteFile($this->routes);
     $model->delete();
     return ['success' => 'true'];
 }
 /**
  * @param array $value the value of the attribute
  */
 public function setUploadValue($value)
 {
     $this->newUploads = [];
     foreach ($value as $media_id) {
         if (ctype_digit($media_id) && !in_array($media_id, $this->newUploads)) {
             $media = Media::findOne([Media::tableName() . '.' . Media::primaryKey()[0] => $media_id]);
             //Disallow to add images uploaded by other users
             if (!$media || $media->created_by !== Yii::$app->user->id) {
                 continue;
             }
             $this->newUploads[] = (int) $media_id;
         }
     }
 }
 /** Render model info
  * @param int $id
  * @param string $strictThumb only this thumb will be selected
  * @return string
  */
 public function actionInfo($id, $strictThumb = null)
 {
     $tableName = Media::tableName();
     /**
      * @var yeesoft\media\models\Media
      */
     $model = Media::findOne(["{$tableName}.id" => $id]);
     return $this->renderPartial('info', ['model' => $model, 'strictThumb' => $strictThumb]);
 }