Example #1
0
 public function getImages()
 {
     $result = $this->hasMany(RImages::className(), ['id_item' => 'id']);
     if (count($result->all()) == 0) {
         $result = RImages::find()->where(["id" => 1])->all();
     }
     return $result;
 }
Example #2
0
 public function addImageSlider()
 {
     if ($this->image_slider) {
         $dir = 'files/system/default_page/slider';
         if (!is_dir($dir)) {
             mkdir($dir);
         }
         $dir .= '/' . $this->image_slider->baseName . '.' . $this->image_slider->extension;
         $this->image_slider->saveAs($dir);
         $image = new RImages();
         $image->src = $dir;
         $image->save();
         $RSettings = new RSettings();
         $RSettings->type = 'imageSlider';
         $RSettings->value = $image->id;
         $RSettings->save();
     }
 }
Example #3
0
 public function save()
 {
     if (!$this->id) {
         $category = new FCategory();
     } else {
         $category = FCategory::findOne($this->id);
     }
     $category->name = $this->name;
     $category->sort = $this->sort;
     if ($this->parent_id) {
         $category->parent_id = $this->parent_id;
     }
     $category->save();
     if ($this->image) {
         $dir = 'files/system/categories/' . $category->id;
         if (!is_dir($dir)) {
             mkdir($dir);
         }
         $dir .= '/' . $this->image->baseName . '.' . $this->image->extension;
         $this->image->saveAs($dir);
         $image = new RImages();
         $image->src = $dir;
         $image->save();
         $category->image = $image->id;
     }
     if ($this->image_detail) {
         $dir = 'files/system/categories/' . $category->id;
         if (!is_dir($dir)) {
             mkdir($dir);
         }
         $dir .= '/' . $this->image_detail->baseName . '.' . $this->image_detail->extension;
         $this->image_detail->saveAs($dir);
         $image = new RImages();
         $image->src = $dir;
         $image->save();
         $category->image_detail = $image->id;
     }
     $category->bool_item = $this->bool_item;
     $category->save();
 }
Example #4
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->imageFile) {
             if ($this->img) {
                 $this->img->delete();
             }
             $dir = 'files/system/reklama';
             if (!is_dir($dir)) {
                 mkdir($dir);
             }
             $dir .= '/' . $this->imageFile->baseName . '.' . $this->imageFile->extension;
             $this->imageFile->saveAs($dir);
             $image = new RImages();
             $image->src = $dir;
             $image->save();
             $this->image = $image->id;
         }
         return true;
     }
     return false;
 }
Example #5
0
 public function getImage()
 {
     return $this->hasOne(RImages::className(), ['id' => 'value']);
 }
Example #6
0
 public function getImagesDetail()
 {
     return $this->hasOne(RImages::className(), ['id' => 'image_detail']);
 }
Example #7
0
 private function saveImage($image)
 {
     $dir = 'files/items/' . $this->id_category;
     if (!is_dir($dir)) {
         mkdir($dir);
     }
     $dir .= '/' . $image->baseName . '.' . $image->extension;
     $image->saveAs($dir);
     $rimage = new RImages();
     $rimage->id_item = $this->id_item;
     $rimage->src = $dir;
     $rimage->save();
 }
Example #8
0
 public function actionDeleteImage()
 {
     $post = Yii::$app->request->post();
     $id = $post["id"];
     $RImages = RImages::findOne($id);
     if ($RImages->delete()) {
         return "true";
     } else {
         return "false";
     }
 }