예제 #1
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $result = ['status' => false];
     if (Yii::$app->request->isPost && isset($_POST['id'])) {
         if (is_array($_POST['id'])) {
             foreach ($_POST['id'] as $id) {
                 File::find()->where('id = :id', ['id' => $id])->one()->delete();
             }
         } else {
             File::find()->where('id = :id', ['id' => $_POST['id']])->one()->delete();
         }
         $result['status'] = true;
         if ($this->callback != null) {
             $this->callback($_POST['id']);
         }
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     return $result;
 }
예제 #2
0
 public function run()
 {
     if ($this->model != null && $this->attribute != null) {
         if (count($this->model->{$this->attribute}) > 1) {
             foreach ($this->model->{$this->attribute} as $id => $file_id) {
                 $this->file[] = File::getFile($file_id);
             }
             $this->placeholder = count($this->model->{$this->attribute}) . ' файла';
         } elseif ($this->model->{$this->attribute} > 0) {
             // делаем запрос на информацию о файле
             $this->file[] = File::getFile($this->model->{$this->attribute});
             $this->placeholder = $this->file[0]['original_name'];
         }
         $classArray = $this->parseClassName($this->model);
         $this->htmlOptions['id'] = ucfirst($classArray['classname']) . ucfirst($this->attribute);
     } else {
         $classArray = ['classname' => 'File'];
         $this->attribute = 'file';
         $this->htmlOptions['id'] = 'File-' . uniqid();
     }
     $this->registerAssetBundle();
     $this->registerClientScript();
     return $this->render('index', ['classArray' => $classArray]);
 }
예제 #3
0
 public function getUrl($arSize, $imageQuality = 80)
 {
     return File::getResizeImage($this->id, $arSize, $imageQuality);
 }