public static function boot() { parent::boot(); ProductLine::deleting(function ($productLine) { File::delete($productLine->image); }); }
/** * Run the database seeds. * * @return void */ public function run() { factory(Priola\ProductCategory::class, 5)->create()->each(function ($pc) { for ($i = 0; $i < 1; $i++) { if (rand(0, 1) == 1) { $pc->productLines()->save(factory(Priola\ProductLine::class)->make()); } } }); foreach (\Priola\ProductCategory::all() as $productCategory) { factory(Priola\Product::class, 10)->create(['product_category_id' => $productCategory->id])->each(function ($p) { for ($i = 0; $i < 5; $i++) { $p->productColors()->save(factory(Priola\ProductColor::class)->make()); } $p->masterClasses()->save(factory(Priola\MasterClass::class)->make()); }); } foreach (\Priola\ProductLine::all() as $productLine) { factory(Priola\Product::class, 10)->create(['product_line_id' => $productLine->id])->each(function ($p) { for ($i = 0; $i < 5; $i++) { $p->productColors()->save(factory(Priola\ProductColor::class)->make()); } $p->masterClasses()->save(factory(Priola\MasterClass::class)->make()); }); } foreach (\Priola\MasterClass::all() as $masterClass) { factory(Priola\MasterClassStep::class, 6)->create(['master_class_id' => $masterClass->id]); } }
public static function boot() { parent::boot(); ProductLine::deleting(function ($competitionWorkImage) { File::delete($competitionWorkImage->image); }); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $productCategoryList = ProductCategory::lists('title', 'id'); $productLineList = ProductLine::lists('title', 'id'); $productList = Product::lists('title', 'id'); $productTagList = ProductTag::lists('name', 'name'); return View('admin.products.edit', ['productCategoryList' => $productCategoryList, 'productLineList' => $productLineList, 'productList' => $productList, 'product' => Product::find($id), 'productTagList' => $productTagList]); }
public function updateCatalogOrderItems() { $data = Input::get('data'); foreach ($data as $dataItem) { $productLine = null; if ($dataItem['type'] == 'Priola\\ProductLine') { $itemToSave = ProductLine::findOrFail($dataItem['id']); } else { $itemToSave = Product::findOrFail($dataItem['id']); } $itemToSave->catalog_order = $dataItem['order']; $itemToSave->save(); } return response("ok"); }
/** * @param Request $request */ private function checkFiles(Request $request) { $fileNameWithoutExt = str_random(32); $fileName = $fileNameWithoutExt . '.' . $request->file('file')->getClientOriginalExtension(); $directory = public_path() . '/resources/uploads/'; $request->file('file')->move($directory, $fileName); $zipper = new Zipper(); File::makeDirectory($directory . $fileNameWithoutExt); $zipper->make($directory . $fileName)->extractTo($directory . $fileNameWithoutExt); $createdProductCategories = []; $dataTransferResultErrors = ['productCategories' => array(), 'productLines' => array(), 'products' => array(), 'otherErrors' => array()]; $dataTransferResultWarnings = ['productCategories' => array(), 'productLines' => array(), 'products' => array()]; $findResults = File::glob($directory . $fileNameWithoutExt . '/img/'); if (count($findResults) == 0) { array_push($dataTransferResultErrors['otherErrors'], 'отсутствует папка с изображениями img'); } $findResults = File::glob($directory . $fileNameWithoutExt . '/products.xlsx'); if (count($findResults) == 0) { array_push($dataTransferResultErrors['otherErrors'], 'отсутствует файл Excel версии 2007 и выше. Убедитесь, что структура архива соотвествует образцу. Обратите внимание, что папка img и файл Excel находятся в корне архива, а не в папке, которая находится в корне архива'); } if (count($dataTransferResultErrors['otherErrors'])) { Session::put('dataTransferResult.Errors', $dataTransferResultErrors); Session::put('dataTransferResult.Warnings', $dataTransferResultWarnings); File::delete($directory . $fileName); File::deleteDirectory($directory . $fileNameWithoutExt); return; } Excel::selectSheets('Категории')->load($directory . $fileNameWithoutExt . '/products.xlsx', function ($reader) use($directory, $fileNameWithoutExt, $createdProductCategories, $dataTransferResultErrors, $dataTransferResultWarnings, $fileName, $request) { $productCategories = []; foreach ($reader->toArray() as $row) { if ($row['nomer'] == null) { continue; } array_push($productCategories, $row['nomer']); $imagePattern = '/img/product-category-' . $row['nomer']; $findResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*'); if (count($findResults) == 0) { $dataTransferResultErrors['productCategories'][$row['nomer']] = 'У категории с номером ' . $row['nomer'] . ' отсутствует изображение: ' . $imagePattern; } if ($row['nomer'] <= ProductCategory::max('id')) { $dataTransferResultErrors['productCategories'][$row['nomer'] . ' дублирование данных (категория)'] = 'Категория с номером ' . $row['nomer'] . ' возможно уже присутствует в базe. Проверьте условие минимальности номера категории'; } } Excel::selectSheets('Линейки продукции')->load($directory . $fileNameWithoutExt . '/products.xlsx', function ($reader) use($directory, $fileNameWithoutExt, $createdProductCategories, $dataTransferResultErrors, $dataTransferResultWarnings, $fileName, $productCategories, $request) { $productLines = []; foreach ($reader->toArray() as $row) { if ($row['nomer'] == null) { continue; } array_push($productLines, $row['nomer']); if (!in_array($row['kategoriya'], $productCategories) && ProductCategory::find($row['kategoriya']) == null) { $dataTransferResultErrors['productLines'][$row['nomer'] . ' целостость данных (категория)'] = 'У линейки продукции указана несущестующая категория: ' . $row['kategoriya']; } $imagePattern = '/img/product-line-' . $row['nomer']; $findResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*'); if (count($findResults) == 0) { $dataTransferResultErrors['productLines'][$row['nomer']] = 'У линейки продукции с номером ' . $row['nomer'] . ' отсутствует изображение: ' . $imagePattern; } if ($row['nomer'] <= ProductLine::max('id')) { $dataTransferResultErrors['productLines'][$row['nomer'] . ' дублирование данных (линейка продукции)'] = 'Линейка продукции с номером ' . $row['nomer'] . ' возможно уже присутствует в базe. Проверьте условие минимальности номера линейки продукции'; } } Excel::selectSheets('Продукция')->load($directory . $fileNameWithoutExt . '/products.xlsx', function ($reader) use($directory, $fileNameWithoutExt, $createdProductCategories, $dataTransferResultErrors, $dataTransferResultWarnings, $fileName, $productLines, $productCategories, $request) { foreach ($reader->toArray() as $row) { if ($row['nomer'] == null) { continue; } if ($row['kategoriya'] == null && $row['lineyka_produktsii'] == null) { $dataTransferResultErrors['products'][$row['nomer'] . ' целостость данных (нет привязки)'] = 'У продукции должна быть либо категория либо линейка продукции'; } if ($row['kategoriya'] != null && $row['lineyka_produktsii'] != null) { $dataTransferResultErrors['products'][$row['nomer'] . ' целостость данных (плохая привязка)'] = 'У продукции не может быть одновременно категории и линейка продукции'; } if ($row['kategoriya'] != null && !in_array($row['kategoriya'], $productCategories) && ProductCategory::find($row['kategoriya']) == null) { $dataTransferResultErrors['products'][$row['nomer'] . ' целостость данных (категория)'] = 'У продукции указана несущестующая категория: ' . $row['kategoriya']; } if ($row['lineyka_produktsii'] != null && !in_array($row['lineyka_produktsii'], $productLines) && ProductLine::find($row['lineyka_produktsii']) == null) { $dataTransferResultErrors['products'][$row['nomer'] . ' целостость данных (категория)'] = 'У продукции указана несущестующая категория: ' . $row['lineyka_produktsii']; } $imagePattern = '/img/product-' . $row['nomer']; $findResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*'); if (count($findResults) == 0) { $dataTransferResultErrors['products'][$row['nomer']] = 'У продукции с номером ' . $row['nomer'] . ' отсутсвует основное изображение: ' . $imagePattern; } $imagePattern = '/img/product-' . $row['nomer'] . '-color-'; $findResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*'); $notFoundProductColorImages = []; foreach ($findResults as $findResult) { $colorNumber = substr($findResult, strpos($findResult, 'color') + 6, strpos($findResult, '.') - strpos($findResult, 'color') - 6); $imagePattern = '/img/product-' . $row['nomer'] . '-image-' . $colorNumber; $findProductColorImageResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*'); if (count($findProductColorImageResults) == 0) { array_push($notFoundProductColorImages, $imagePattern); } } if (count($notFoundProductColorImages) > 0) { $dataTransferResultWarnings['products'][$row['nomer'] . ' предупреждение об изображении для палитры'] = 'У продукции с номером ' . $row['nomer'] . ' отсутсвуют изображения продукта для цветовой палитры: '; foreach ($notFoundProductColorImages as $foundProductColorImage) { $dataTransferResultWarnings['products'][$row['nomer'] . ' предупреждение об изображении для палитры'] .= $foundProductColorImage . ', '; } } $imagePattern = '/img/product-' . $row['nomer'] . '-image-'; $findResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*'); $notFoundProductColors = []; foreach ($findResults as $findResult) { $colorNumber = substr($findResult, strpos($findResult, 'image') + 6, strpos($findResult, '.') - strpos($findResult, 'color') - 6); $colorPattern = '/img/product-' . $row['nomer'] . '-color-' . $colorNumber; $findProductColorResults = File::glob($directory . $fileNameWithoutExt . $colorPattern . '*'); if (count($findProductColorResults) == 0) { array_push($notFoundProductColors, $colorPattern); } } if (count($notFoundProductColors) > 0) { $dataTransferResultWarnings['products'][$row['nomer'] . ' предупреждение о самом изображении палитры'] = 'У продукции с номером ' . $row['nomer'] . ' отсутсвуют изображения самой цветовой палитры: '; foreach ($notFoundProductColors as $notFoundProductColor) { $dataTransferResultWarnings['products'][$row['nomer'] . ' предупреждение о самом изображении палитры'] .= $notFoundProductColor . ', '; } } } Session::put('dataTransferResult.Errors', $dataTransferResultErrors); Session::put('dataTransferResult.Warnings', $dataTransferResultWarnings); if (count($dataTransferResultErrors['productCategories']) == 0 && count($dataTransferResultErrors['productLines']) == 0 && count($dataTransferResultErrors['products']) == 0) { Session::put('dataTransferResult.FilesPath', $directory . $fileNameWithoutExt); } else { File::delete($directory . $fileName); File::deleteDirectory($directory . $fileNameWithoutExt); } }); }); }); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { ProductLine::destroy($id); return redirect('/admin/productLines'); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $reviewTagList = ReviewTag::lists('text', 'text'); return View('admin.reviews.edit', ['productList' => Product::all()->lists('title', 'id'), 'productLineList' => ProductLine::all()->lists('title', 'id'), 'regionTechnologyList' => RegionTechnology::all()->lists('username', 'id'), 'reviewTagList' => $reviewTagList, 'productReview' => Review::find($id)]); }
public function search() { $searchResults = new \Illuminate\Database\Eloquent\Collection(); $string = Input::get('string'); $productCategories = ProductCategory::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get(); foreach ($productCategories as $productCategory) { $body = strip_tags($productCategory->description); if (strlen($body) > 100) { $body = substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $productCategory->title, 'body' => $body, 'link' => '/catalog/' . $productCategory->id]); $searchResults->push($searchResult); } $productLines = ProductLine::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get(); foreach ($productLines as $productLine) { $body = strip_tags($productLine->description); if (strlen($body) > 100) { $body = substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $productLine->title, 'body' => $body, 'link' => '/productLine/' . $productLine->id]); $searchResults->push($searchResult); } $products = Product::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get(); foreach ($products as $product) { $body = strip_tags($product->description); if (strlen($body) > 100) { $body = substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $product->title, 'body' => $body, 'link' => '/product/' . $product->id]); $searchResults->push($searchResult); } $masterClasses = MasterClass::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get(); foreach ($masterClasses as $masterClass) { $body = strip_tags($masterClass->description); if (strlen($body) > 100) { $body = substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $masterClass->title, 'body' => $body, 'link' => '/master-class/' . $masterClass->id]); $searchResults->push($searchResult); } $events = Event::where('title', 'like', '%' . $string . '%')->orWhere('body', 'like', '%' . $string . '%')->get(); foreach ($events as $event) { $body = strip_tags($event->description); if (strlen($body) > 100) { $body = substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $event->title, 'body' => $body, 'link' => '/events/' . $event->id]); $searchResults->push($searchResult); } $novelties = Novelty::where('title', 'like', '%' . $string . '%')->orWhere('body', 'like', '%' . $string . '%')->get(); foreach ($novelties as $novelty) { $body = strip_tags($novelty->description); if (strlen($body) > 100) { $body = mb_substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $novelty->title, 'body' => $body, 'link' => '/novelties/' . $novelty->id]); $searchResults->push($searchResult); } $reviews = Review::where('body', 'like', '%' . $string . '%')->get()->load('regionTechnology'); foreach ($reviews as $review) { $body = strip_tags($review->body); if (strlen($body) > 100) { $body = mb_substr($body, 0, 100); } $searchResult = new SearchResult(['title' => RegionTechnology::where('id', $review->region_technology_id)->first()->username, 'body' => $body, 'link' => '/reviews/' . $review->id]); $searchResults->push($searchResult); } $competitions = Competition::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get(); foreach ($competitions as $competition) { $body = strip_tags($competition->description); if (strlen($body) > 100) { $body = substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $competition->title, 'body' => $body, 'link' => '/competitions/' . $competition->id]); $searchResults->push($searchResult); } $courses = Course::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get(); foreach ($courses as $course) { $body = strip_tags($course->description); if (strlen($body) > 100) { $body = substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $course->title, 'body' => $body, 'link' => '/courses/' . $course->id]); $searchResults->push($searchResult); } $massMediaNews = MassMediaNews::where('title', 'like', '%' . $string . '%')->orWhere('body', 'like', '%' . $string . '%')->get(); foreach ($massMediaNews as $massMediaNewItem) { $body = strip_tags($massMediaNewItem->body); if (strlen($body) > 100) { $body = substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $massMediaNewItem->title, 'body' => $body, 'link' => '/mass-media-news/' . $massMediaNewItem->id]); $searchResults->push($searchResult); } $regionWorkshops = RegionWorkshop::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get(); foreach ($regionWorkshops as $regionWorkshop) { $body = strip_tags($regionWorkshop->description); if (strlen($body) > 100) { $body = substr($body, 0, 100); } $searchResult = new SearchResult(['title' => $regionWorkshop->title, 'body' => $body, 'link' => '/regions/workshops/' . $regionWorkshop->id]); $searchResults->push($searchResult); } return view('home.searchResults', ['string' => $string, 'searchResults' => $searchResults]); }