public function run()
 {
     $categories = [['name' => 'Мебель', 'slug' => 'furniture'], ['name' => 'Посуда', 'slug' => 'dishes'], ['name' => 'Аксессуары', 'slug' => 'accessories'], ['name' => 'Кольца', 'slug' => 'rings'], ['name' => 'Заколки', 'slug' => 'hairpins'], ['name' => 'Серьги', 'slug' => 'earrings']];
     $data = [['title' => 'Доска-подставка под горячее', 'content' => ['description' => 'Осина, склейка. Обработка — масло', 'price' => '1000', 'tags' => ['подносы', 'деревяннаяпосуда']], 'categories' => ['dishes'], 'images' => ['cooking_boards_1.jpg', 'cooking_boards_2.jpg']], ['title' => 'Ложки-близняшки', 'content' => ['description' => 'Липа', 'price' => '1000', 'tags' => ['ложкидеревянные', 'деревяннаяпосуда']], 'categories' => ['dishes'], 'images' => ['spoon_1.jpg', 'spoon_2.jpg', 'spoon_3.jpg']], ['title' => 'Серьги «Треугольник»', 'content' => ['description' => 'Орех, хир. сталь', 'price' => '1000', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'серрежки', 'минимализм']], 'categories' => ['accessories', 'earrings'], 'images' => ['treugolnik_001.jpg']], ['title' => 'Серия сержек «Супрематизм»', 'content' => ['description' => 'Орех, хир. сталь', 'price' => '1000', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'сережки']], 'categories' => ['accessories', 'earrings'], 'images' => ['kvadro.jpg', 'lisichkini_usgki_1.jpg', 'lisichkini_usgki_2.jpg', 'suprematizm_1.jpg']], ['title' => 'Серьги «Параллелепипед»', 'content' => ['description' => 'Клён, хир. сталь', 'price' => '1000', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'сережки', 'клен']], 'categories' => ['accessories', 'earrings'], 'images' => ['parallelepiped_1.jpg', 'parallelepiped_2.jpg']], ['title' => 'Серьги «Палочки»', 'content' => ['description' => 'Венге, клён, хир. сталь', 'price' => 'Цена', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'сережки', 'палочки']], 'categories' => ['accessories', 'earrings'], 'images' => ['palochki.jpg']], ['title' => 'Серьги «Лодочки»', 'content' => ['description' => 'Клён, хир. сталь', 'price' => 'Цена', 'tags' => []], 'categories' => ['accessories', 'earrings'], 'images' => ['lodochki_1.jpg', 'lodochki_2.jpg']], ['title' => 'Серьги «Квадрат»', 'content' => ['description' => 'Орех, хир. сталь', 'price' => '1000', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'сережки']], 'categories' => ['accessories', 'earrings'], 'images' => ['kvadrat.jpg']], ['title' => 'Серьги «Круг»', 'content' => ['description' => 'Орех, хир. сталь', 'price' => '1000', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'сережки']], 'categories' => ['accessories', 'earrings'], 'images' => ['krug_1.jpg', 'krug_2.jpg']], ['title' => 'Серьги «Корельская берёза»', 'content' => ['description' => 'Корельская берёза, хир. сталь', 'price' => '1000', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'сережки']], 'categories' => ['accessories', 'earrings'], 'images' => ['korelskai_bereza_1.jpg', 'korelskai_bereza_2.jpg', 'korelskai_bereza_3.jpg']], ['title' => 'Серьги «Конус»', 'content' => ['description' => 'Орех, хир. сталь', 'price' => '1000', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'сережки', 'гвоздики']], 'categories' => ['accessories', 'earrings'], 'images' => ['konus_1.jpg', 'konus_2.jpg']], ['title' => 'Серьги «Кленовая коллекция»', 'content' => ['description' => 'Клён, хир. сталь', 'price' => '1000', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'сережки', 'клен']], 'categories' => ['accessories', 'earrings'], 'images' => ['klen_collection_kolos.jpg']], ['title' => 'Серьги из серии «Геометрия»', 'content' => ['description' => 'Орех, хир. сталь', 'price' => '1000', 'tags' => ['серьгиручнойработы', 'серьгииздерева', 'сережки']], 'categories' => ['accessories', 'earrings'], 'images' => ['geometry_collection_1.jpg', 'geometry_collection_2.jpg']], ['title' => 'Заколка декоративная «Анна»', 'content' => ['description' => 'Красное дерево', 'price' => '1000', 'tags' => ['шпильки', 'деревянныешпильки', 'заколкидляволос', 'заколки', 'заколкииздерева']], 'categories' => ['accessories', 'hairpins'], 'images' => ['anna_kolos.jpg', 'anna_kolos_02.jpg']], ['title' => 'Заколка «Ушки»', 'content' => ['description' => 'Переклейка, венге шпон', 'price' => '1000', 'tags' => ['шпильки', 'деревянныешпильки', 'заколкидляволос', 'заколки', 'заколкииздерева']], 'categories' => ['accessories', 'hairpins'], 'images' => ['shpilky_kolos_01.jpg']], ['title' => 'Заколка «Спутник»', 'content' => ['description' => 'Русский орех', 'price' => '1000', 'tags' => ['шпильки', 'деревянныешпильки', 'заколкидляволос', 'заколки', 'заколкииздерева']], 'categories' => ['accessories', 'hairpins'], 'images' => ['sputnik.jpg', 'sputnik_02.jpg', 'sputnik_03.jpg', 'sputnik_04.jpg']], ['title' => 'Заколка «Биоформа»', 'content' => ['description' => 'Ольха', 'price' => '1000', 'tags' => ['шпильки', 'деревянныешпильки', 'заколкидляволос', 'заколки', 'заколкииздерева']], 'categories' => ['accessories', 'hairpins'], 'images' => ['bio_03.jpg', 'bio_01.jpg', 'bio_02.jpg']], ['title' => 'Кольцо «Грани»', 'content' => ['description' => 'Русский орех, масло', 'price' => '1000', 'tags' => ['кольцо', 'кольцоиздерева', 'граненоекольцо', 'орех', 'дерево']], 'categories' => ['accessories', 'rings'], 'images' => ['grani_001.jpg']], ['title' => 'Кольцо «Костет»', 'content' => ['description' => 'Дуб, масло', 'price' => '1000', 'tags' => ['кольцоиздерева', 'костет', 'костетиздерева', 'дерево', 'дизайнспб', 'дуб']], 'categories' => ['accessories', 'rings'], 'images' => ['ring_kostet_01.jpg', 'ring_kostet_02.jpg', 'ring_kostet_03.jpg']], ['title' => 'Кольца на мизинец', 'content' => ['description' => 'Различные породы деревьев', 'price' => '700', 'tags' => ['кольцоиздерева', 'кольцорунойработы', 'дерево', 'дизайнспб']], 'categories' => ['accessories', 'rings'], 'images' => ['mizinec_001.jpg', 'mizinec_grange_001.jpg', 'mizinec_grange_002.jpg', 'mizinec_tiger_eye.jpg']], ['title' => 'Кольцо «Ольха большая»', 'content' => ['description' => 'Ольха, масло', 'price' => '1000', 'tags' => ['кольцоиздерева', 'кольцоназаказ', 'ольха', 'дизайнспб']], 'categories' => ['accessories', 'rings'], 'images' => ['olxa_001.jpg', 'olxa_002.jpg']], ['title' => 'Кольцо «Ольха круглая»', 'content' => ['description' => 'Ольха, масло', 'price' => '1000', 'tags' => ['кольцоиздерева', 'ольха', 'дизайнспб']], 'categories' => ['accessories', 'rings'], 'images' => ['olxa_kruglai_001.jpg', 'olxa_kruglai_002.jpg']], ['title' => 'Кольцо «Перстень»', 'content' => ['description' => 'Орех, масло', 'price' => '1000', 'tags' => ['кольцоиздерева', 'орех', 'дизайнспб']], 'categories' => ['accessories', 'rings'], 'images' => ['persten_001.jpg', 'persten_002.jpg', 'persten_003.jpg']], ['title' => 'Кольцо «Точечка»', 'content' => ['description' => 'Клен + вставка венге, воск', 'price' => '1000', 'tags' => ['кольцоиздерева', 'точка', 'минимализм', 'дизайниздерева']], 'categories' => ['accessories', 'rings'], 'images' => ['tochechka_001.jpg', 'tochechka_002.jpg', 'tochechka_003.jpg', 'tochechka_004.jpg']], ['title' => 'Кольцо «Тоннель»', 'content' => ['description' => 'Орех, масло', 'price' => '1000', 'tags' => ['кольцоиздерева', 'большоекольцо', 'украшенияручнойработы', 'минимализм', 'хипстота']], 'categories' => ['accessories', 'rings'], 'images' => ['tonnel_001.jpg', 'tonnel_002.jpg', 'tonnel_003.jpg', 'tonnel_004.jpg']], ['title' => 'Кольцо «Трио»', 'content' => ['description' => 'Дуб, масло', 'price' => '1000', 'tags' => ['треугольник', 'круг', 'квадрат', 'триптих', 'трио', 'дуб', 'супрематизм']], 'categories' => ['accessories', 'rings'], 'images' => ['trio_001.jpg', 'trio_002.jpg', 'trio_003.jpg']], ['title' => 'Кольцо «Twix»', 'content' => ['description' => 'Клен и Орех, масло', 'price' => '1000', 'tags' => ['кольцоиздерева', 'twix', 'сладкаяпарочка', 'диптих', 'коллекцияколец']], 'categories' => ['accessories', 'rings'], 'images' => ['twix_black_01.jpg', 'twix_black_02.jpg', 'twix_black_03.jpg', 'twix_collection.jpg', 'twix_whit_01.jpg', 'twix_whit_02.jpg', 'twix_whit_03.jpg', 'twix_whit_04.jpg']], ['title' => 'Кольцо «Усеченный цилиндр»', 'content' => ['description' => 'Ольха, масло', 'price' => '1000', 'tags' => ['кольцоиздерева', 'ручнаработа', 'кольцоручнойработы', 'дизайн']], 'categories' => ['accessories', 'rings'], 'images' => ['usechennii_cilindr_001.jpg', 'usechennii_cilindr_002.jpg']], ['title' => 'Кольцо «Вставка венге»', 'content' => ['description' => 'Клен + вставка шпона венге', 'price' => '1000', 'tags' => ['кольцоиздерева']], 'categories' => ['accessories', 'rings'], 'images' => ['spon_vstavka_kolos.jpg']], ['title' => 'Кольцо «Хребет»', 'content' => ['description' => 'Осина, масло', 'price' => '1000', 'tags' => ['кольцоиздерева', 'осина', 'дизайниздерева', 'минимализм', 'ручнаяработа']], 'categories' => ['accessories', 'rings'], 'images' => ['xrebet_001.jpg', 'xrebet_002.jpg']], ['title' => 'Кольцо «Зебра»', 'content' => ['description' => 'Клен + вставка шпона венге, масло', 'price' => '1000', 'tags' => ['кольцоиздерева', 'зебра', 'клен', 'венге', 'украшениеиздерева', 'дизайн']], 'categories' => ['accessories', 'rings'], 'images' => ['zebra_001.jpg', 'zebra_002.jpg']]];
     foreach ($categories as $key => $category) {
         Category::create($category);
     }
     foreach ($data as $product) {
         if (array_key_exists('images', $product)) {
             $images = $product['images'];
             unset($product['images']);
         }
         if (array_key_exists('categories', $product)) {
             $categories = $product['categories'];
             unset($product['categories']);
         }
         if (array_key_exists('tags', $product['content'])) {
             $tags = $product['content']['tags'];
             unset($product['content']['tags']);
         }
         $product['published'] = true;
         $product['published_at'] = date('Y-m-d H:i:s', rand(strtotime('2015-01-01'), strtotime('2015-09-01')));
         $model = Product::create($product);
         foreach ($categories as $slug) {
             $category = '';
             $category = Category::where('slug', '=', $slug)->first();
             // print_r($category);
             if (!is_null($category)) {
                 $model->categories()->add($category, null);
             }
         }
         foreach ($tags as $name) {
             $tag = '';
             $tag = Tag::where('name', '=', $name)->first();
             // print_r($category);
             if (is_null($tag)) {
                 $tag = Tag::create(['name' => $name]);
             }
             if (!is_null($tag)) {
                 $model->tags()->add($tag, null);
             }
         }
         foreach ($images as $key => $image) {
             $filePath = "./storage/app/images/" . $image;
             if (!file_exists($filePath)) {
                 echo 'File ' . $filePath . ' not exists.' . "\n";
                 continue;
             }
             $file = new File();
             $file->fromFile($filePath);
             $file['title'] = $model->title;
             $file['description'] = $model->content['description'];
             $model->featured_images()->save($file, null);
             // if ($key == 0) {
             //     $model->cover()->save($file, null);
             // }
         }
     }
 }
 public function run()
 {
     $driver = Driver::firstOrCreate(['name' => 'U.S. Postal Service', 'type' => 'shipping', 'class' => 'Bedard\\USPS\\Classes\\USPS', 'is_configurable' => true, 'is_default' => false]);
     $logo = new File();
     $logo->fromFile(plugins_path('bedard/usps/assets/images/usps.png'));
     $logo->save();
     $driver->image()->add($logo);
 }
 private function assignImages($model, $fileData)
 {
     if (array_key_exists($model->slug, $fileData)) {
         $images = $fileData[$model->slug];
         // print_r($images);
         echo $model->slug . " [";
         // echo get_class($model) . "\n";
         if (!is_array($images)) {
             return;
         }
         foreach ($images as $key => $filePath) {
             if (!is_array($filePath)) {
                 $pathinfo = pathinfo($filePath);
                 $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first();
                 if (!is_null($check)) {
                     // echo $filePath . " ";
                     // echo filemtime($filePath) . " ";
                     // echo $check->updated_at->timestamp . "\n";
                     if (filemtime($filePath) > $check->updated_at->timestamp) {
                         // echo "File " . $filePath . " is Newer. Update!" . "\n";
                         echo "^";
                         $check->delete();
                     } else {
                         echo "~";
                         continue;
                     }
                 } else {
                     // echo "File " . $filePath . " is New. Create!" . "\n";
                     echo "+";
                 }
                 $file = new File();
                 $file->fromFile($filePath);
                 switch ($key) {
                     case 'cover':
                         $model->cover()->save($file, null, ['title' => $model->title]);
                         break;
                     default:
                         echo ' Image ' . $filePath . ' not saved.' . "\n";
                         break;
                 }
             }
         }
         echo "]\n";
     } else {
         // preg_match_all('#<img.+?src="(.+?)"#', $model->content, $matches);
         // // $images = $matches[1];
         // $images = array_filter($matches[1], function ($value) {
         //     return !preg_match('#^https?\:\/\/#', $value);
         // });
         // if (count($images) != 0) {
         //     $filePath = $images[0];
         //     // echo $model->title . " -- " . $filePath . "\n";
         //     $file = new File();
         //     $file->fromFile("./" . $filePath);
         //     $model->cover()->save($file, null, ['title' => $model->title]);
         // }
     }
 }
Example #4
0
 private function assignImage($field, $filePath, $model)
 {
     $file = new File();
     $file->fromFile($filePath);
     if (!is_null($model->{$field}) && strtotime($model->{$field}->updated_at) < filemtime($filePath)) {
         echo "Update " . $field . " by file " . $file->getFilename() . "\n";
         $model->{$field}->delete();
         $model->{$field}()->save($file);
     }
 }
Example #5
0
 /**
  * Add image size information.
  *
  * @param  string $filePath
  * @return  File
  */
 public function fromFile($filePath)
 {
     if (!is_null($filePath)) {
         parent::fromFile($filePath);
         if ($this->isImage() && $this->hasFile($this->disk_name)) {
             list($width, $height) = getimagesize(realpath($filePath));
             $width and $this->image_width = $width;
             $height and $this->image_height = $height;
         }
     }
     return $this;
 }
 /**
  * @param $username
  *
  * @return string|null
  */
 private function findAvatar($username)
 {
     $library = MediaLibrary::instance();
     $files = $library->listFolderContents($this->imageStoragePath, 'title', 'image');
     foreach ($files as $file) {
         $pathinfo = pathinfo($file->publicUrl);
         if ($pathinfo['filename'] == $username) {
             $file = new File();
             $file->is_public = $this->imagePublic;
             $file->fromFile(base_path() . $pathinfo['dirname'] . '/' . $pathinfo['basename']);
             return $file;
         }
     }
 }
 private function assignImages($model, $fileData)
 {
     if (array_key_exists($model->slug, $fileData)) {
         $images = $fileData[$model->slug];
         echo $model->slug . " [";
         foreach ($images as $key => $filePath) {
             if (!is_array($filePath)) {
                 $pathinfo = pathinfo($filePath);
                 $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first();
                 if (!is_null($check)) {
                     if (filemtime($filePath) > $check->updated_at->timestamp) {
                         echo "^";
                         $check->delete();
                     } else {
                         echo "~";
                         continue;
                     }
                 } else {
                     echo "+";
                 }
                 $file = new File();
                 $file->fromFile($filePath);
                 switch ($key) {
                     case 'logo_color':
                         $model->logo_color()->save($file, null, ['title' => $model->title]);
                         break;
                     case 'logo_bw':
                         $model->logo_bw()->save($file, null, ['title' => $model->title]);
                         break;
                     default:
                         echo ' Image ' . $filePath . ' not saved.' . "\n";
                         break;
                 }
             }
         }
         echo "]\n";
     }
 }
 private function assignImages($model, $fileData)
 {
     if (array_key_exists($model->slug, $fileData)) {
         $images = $fileData[$model->slug];
         // print_r($images);
         echo $model->slug . " [";
         // echo get_class($model) . "\n";
         foreach ($images as $key => $filePath) {
             if (!is_array($filePath)) {
                 $pathinfo = pathinfo($filePath);
                 $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first();
                 if (!is_null($check)) {
                     // echo $filePath . " ";
                     // echo filemtime($filePath) . " ";
                     // echo $check->updated_at->timestamp . "\n";
                     if (filemtime($filePath) > $check->updated_at->timestamp) {
                         // echo "File " . $filePath . " is Newer. Update!" . "\n";
                         echo "^";
                         $check->delete();
                     } else {
                         echo "~";
                         continue;
                     }
                 } else {
                     // echo "File " . $filePath . " is New. Create!" . "\n";
                     echo "+";
                 }
                 $file = new File();
                 $file->fromFile($filePath);
                 // $file->save();
                 $model->images()->save($file, null, ['title' => $model->title]);
             }
         }
         echo "]\n";
     }
 }
 private function assignImages($model, $fileData)
 {
     if (array_key_exists($model->slug, $fileData)) {
         $images = $fileData[$model->slug];
         echo $model->slug . " [";
         // echo get_class($model) . "\n";
         foreach ($images as $key => $filePath) {
             if (!is_array($filePath)) {
                 $pathinfo = pathinfo($filePath);
                 $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first();
                 if (!is_null($check)) {
                     // echo $filePath . " ";
                     // echo filemtime($filePath) . " ";
                     // echo $check->updated_at->timestamp . "\n";
                     if (filemtime($filePath) > $check->updated_at->timestamp) {
                         // echo "File " . $filePath . " is Newer. Update!" . "\n";
                         echo "^";
                         $check->delete();
                     } else {
                         echo "~";
                         continue;
                     }
                 } else {
                     // echo "File " . $filePath . " is New. Create!" . "\n";
                     echo "+";
                 }
                 $file = new File();
                 $file->fromFile($filePath);
                 // $file->save();
                 // echo $filePath . "\n";
                 switch ($key) {
                     case 'playbill':
                         $model->playbill()->save($file, null, ['title' => $model->title]);
                         break;
                         // case 'playbill_flat':
                         //     $model->playbill_flat()->save($file);
                         //     break;
                         // case 'playbill_mask':
                         //     $model->playbill_mask()->save($file);
                         //     break;
                     // case 'playbill_flat':
                     //     $model->playbill_flat()->save($file);
                     //     break;
                     // case 'playbill_mask':
                     //     $model->playbill_mask()->save($file);
                     //     break;
                     case 'video':
                         $model->video()->save($file, null, ['title' => $model->title]);
                         break;
                     case 'repertoire':
                         $model->repertoire()->save($file, null, ['title' => $model->title]);
                         break;
                     case 'cover':
                         $model->cover()->save($file, null, ['title' => $model->title]);
                         break;
                     case 'portrait':
                         $model->portrait()->save($file, null, ['title' => $model->title]);
                         break;
                     default:
                         echo ' Image ' . $filePath . ' not saved.' . "\n";
                         break;
                 }
             } elseif (is_array($filePath)) {
                 foreach ($filePath as $filename => $filePath) {
                     $pathinfo = pathinfo($filePath);
                     $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first();
                     // preg_match("~^(\d+)~", $filename, $matches);
                     // print_r($matches);
                     if (!is_null($check)) {
                         // echo $filePath . " ";
                         // echo filemtime($filePath) . " ";
                         // echo $check->updated_at->timestamp . "\n";
                         if (filemtime($filePath) > $check->updated_at->timestamp) {
                             // echo "File " . $filePath . " is Newer. Update!" . "\n";
                             echo "^";
                             $check->delete();
                         } else {
                             // echo "File " . $filePath . " is Older. Skip!" . "\n";
                             echo "~";
                             continue;
                         }
                     } else {
                         // echo "File " . $filePath . " is New. Create!" . "\n";
                         echo "+";
                     }
                     $file = new File();
                     $file->fromFile($filePath);
                     // $file->save();
                     // if (count($matches) > 0) {
                     //     $file->sort_order = intval($matches[0], 10);
                     //     print_r($file);
                     // }
                     // if ( $key == 'bg' && preg_match('/.+?_flat/', $filename) ) {
                     //     $model->background_flat()->save($file);
                     // }
                     // elseif ( $key == 'bg' && preg_match('/.+?_mask/', $filename) ) {
                     //     $model->background_mask()->save($file);
                     // }
                     if ($key == 'bg') {
                         $model->background()->save($file);
                     } elseif ($key == 'gallery') {
                         $model->featured()->save($file);
                     } else {
                         echo $filePath . ' not saved.' . "\n";
                     }
                 }
             }
         }
         echo "]\n";
     }
 }
Example #10
0
 /**
  * Create file from path, save it and return File object
  *
  * @param $path
  * @param $public
  *
  * @return File
  */
 protected function getSavedFile($path, $public = true)
 {
     $file = new File();
     $file->is_public = $public;
     $file->fromFile($path);
     $file->save();
     return $file;
 }