/** * Duyệt danh sách Tài liệu thuộc $category * * @param \Minhbang\Category\Category $category * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show(Category $category) { $paths = $category->getRoot1Path(['id', 'title'], false); $breadcrumbs = []; foreach ($paths as $cat) { $breadcrumbs[route('ilib.category.show', ['category' => $cat->id])] = $cat->title; } $breadcrumbs['#'] = $category->title; $this->buildBreadcrumbs($breadcrumbs); $ebooks = $this->optionAppliedPaginate(Ebook::queryDefault()->published()->withEnumTitles()->categorized($category)); $ebook_widget = new EbookWidget(); return view('ilib::frontend.category.show', compact('category', 'ebooks', 'ebook_widget')); }
/** * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function index(Request $request) { $this->buildBreadcrumbs(['#' => trans('ilib::common.search')]); $q = $request->get('q'); $params = $request->only(array_keys($this->key_column)); $attributes = $this->getAttributes($params); $advanced = !empty($attributes); $category_id = mb_array_extract('category_id', $attributes); $pyear_start = (int) mb_array_extract('pyear_start', $attributes); $pyear_end = (int) mb_array_extract('pyear_end', $attributes); $pyear_end = $pyear_end >= $pyear_start ? $pyear_end : 0; $query = Ebook::queryDefault()->published()->withEnumTitles()->withCategoryTitle()->whereAttributes($attributes)->searchKeyword($q); if ($pyear_start || $pyear_end) { if ($pyear_start) { if ($pyear_end) { $query->whereBetween('ebooks.pyear', [$pyear_start, $pyear_end]); } else { $query->where('ebooks.pyear', '>=', $pyear_start); } } else { $query->where('ebooks.pyear', '<=', $pyear_end); } } if ($category_id && ($category = Category::find($category_id))) { $query->categorized($category); } $ebooks = $this->optionAppliedPaginate($query); $total = $ebooks->total(); $ebook_widget = new EbookWidget(); $categories = CategoryManager::of(Ebook::class)->selectize(); $enums = (new Ebook())->loadEnums('id'); $column_key = array_combine(array_values($this->key_column), array_keys($this->key_column)); return view('ilib::frontend.search.index', $enums + compact('q', 'ebooks', 'ebook_widget', 'total', 'categories', 'params', 'column_key', 'advanced')); }
public function __construct() { $this->type = Ebook::class; Category::$use_moderator = false; $this->views['index'] = 'ilib::backend.category'; parent::__construct(); }
/** * - Tự động lấy trang đầu của PDF làm cover * - Thứ tự data: * 0 title, 1 filename(ko đuôi file), 2 summary, 3 pyear, 4 pages, 5 category_slug, 6 security_slug, * 7 language, 8 writer, 9 publisher, 10 pplace, 11 user_id, 12 status, 13 hit, 14 featured * * @param string $dir * @param array $data * * @throws \Spatie\PdfToImage\Exceptions\InvalidFormat */ public function seed($dir, $data) { DB::table('ebooks')->truncate(); $data_dir = storage_path('data/' . config('ebook.data_dir')); $tmp_dir = storage_path('tmp'); $img_dir = public_path(setting('system.public_files') . '/' . config('ebook.featured_image.dir')); $ebooks = []; foreach ($data as $ebook) { $category = Category::findBy('slug', $ebook[5]); $security = Enum::where('slug', $ebook[6])->where('type', 'ebook.security')->first(); if ($security && $category && is_file("{$dir}/{$ebook[1]}.pdf")) { $pdf = new Pdf("{$dir}/{$ebook[1]}.pdf"); $pdf->saveImage("{$tmp_dir}/{$ebook[1]}.png"); $image_file = save_new_image("{$ebook[1]}.png", "{$tmp_dir}/{$ebook[1]}.png", $img_dir, ['main' => ['width' => config('ebook.featured_image.width'), 'height' => config('ebook.featured_image.height'), 'method' => 'resize'], 'sm' => ['width' => config('ebook.featured_image.width_sm'), 'height' => config('ebook.featured_image.height_sm'), 'method' => 'resize']]); @unlink("{$tmp_dir}/{$ebook[1]}.png"); File::copy("{$dir}/{$ebook[1]}.pdf", "{$data_dir}/{$ebook[1]}.pdf"); $ebooks[] = ['title' => $ebook[0], 'slug' => VnString::to_slug($ebook[0]), 'filename' => $ebook[1] . '.pdf', 'filemime' => 'application/pdf', 'filesize' => File::size("{$dir}/{$ebook[1]}.pdf"), 'summary' => $ebook[2], 'featured_image' => $image_file, 'pyear' => $ebook[3], 'pages' => $ebook[4], 'category_id' => $category->id, 'security_id' => $security->id, 'language_id' => Enum::firstOrCreate(['title' => $ebook[7], 'type' => 'ebook.language'], ['slug' => VnString::to_slug($ebook[7])])->id, 'writer_id' => Enum::firstOrCreate(['title' => $ebook[8], 'type' => 'ebook.writer'], ['slug' => VnString::to_slug($ebook[8])])->id, 'publisher_id' => Enum::firstOrCreate(['title' => $ebook[9], 'type' => 'ebook.publisher'], ['slug' => VnString::to_slug($ebook[9])])->id, 'pplace_id' => Enum::firstOrCreate(['title' => $ebook[10], 'type' => 'ebook.pplace'], ['slug' => VnString::to_slug($ebook[10])])->id, 'user_id' => $ebook[11], 'status' => $ebook[12], 'hit' => $ebook[13], 'featured' => $ebook[14], 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]; } } if ($ebooks) { DB::table('ebooks')->insert($ebooks); } }