Esempio n. 1
0
 /**
  * Perform post-registration booting of services.
  *
  * @param \Illuminate\Routing\Router $router
  *
  * @return void
  */
 public function boot(Router $router)
 {
     $this->loadTranslationsFrom(__DIR__ . '/../lang', 'ebook');
     $this->loadViewsFrom(__DIR__ . '/../views', 'ebook');
     $this->publishes([__DIR__ . '/../views' => base_path('resources/views/vendor/ebook'), __DIR__ . '/../lang' => base_path('resources/lang/vendor/ebook'), __DIR__ . '/../config/ebook.php' => config_path('ebook.php')]);
     $this->publishes([__DIR__ . '/../database/migrations/2015_11_30_000000_create_ebooks_table.php' => database_path('migrations/2015_11_30_000000_create_ebooks_table.php')], 'db');
     $this->mapWebRoutes($router, __DIR__ . '/routes.php', config('ebook.add_route'));
     $class = Ebook::class;
     // pattern filters
     $router->pattern('ebook', '[0-9]+');
     // model bindings
     $router->model('ebook', $class);
     Enum::registerResources([$class]);
     CategoryManager::register($class, config('ebook.category'));
     MenuManager::addItems(config('ebook.menus'));
     AccessControl::register($class, config('ebook.access_control'));
 }
Esempio n. 2
0
 /**
  * @param array $data
  */
 public function seed($data)
 {
     DB::table('readers')->truncate();
     $readers = [];
     foreach ($data as $username => $security) {
         /** @var User $user */
         $user = User::findBy('username', $username);
         /** @var Enum $enum */
         $enum = Enum::where('slug', $security)->where('type', 'ebook.security')->first();
         if ($user && $enum) {
             $readers[] = ['user_id' => $user->id, 'security_id' => $enum->id, 'code' => "RD-{$user->id}"];
         }
     }
     if ($readers) {
         DB::table('readers')->insert($readers);
     }
 }
Esempio n. 3
0
 /**
  * - 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);
     }
 }
Esempio n. 4
0
 /**
  * @param $id
  *
  * @return \Illuminate\Database\Query\Builder|static
  */
 protected function positionModel($id)
 {
     return Enum::find($id);
 }
Esempio n. 5
0
 /**
  * EnumController constructor.
  */
 public function __construct()
 {
     Enum::onlyResources([Ebook::class]);
     parent::__construct();
 }
Esempio n. 6
0
 /**
  * Reader có thể đọc $ebook khi:
  * - Quyền đọc >= Mức bảo mật của $ebook
  * - Hoặc được gán quyền đọc tạm thời đối với $ebook
  * - Hoặc người của Thư viện
  *
  * @param \Minhbang\Ebook\Ebook $ebook
  *
  * @return bool
  */
 public function canRead($ebook)
 {
     return Enum::compare($this->security_id, $ebook->security_id, '>=') || in_array($ebook->id, $this->ebooks->pluck('id')->all()) || user()->hasRole('tv.*');
 }