Example #1
0
 public function index_onMigrateFlyers($save = true)
 {
     $migrated = $unmigrated = $added = $skipped = $ignored = 0;
     // Load a batch of unmigrated flyers
     $unmigrated = FlyerModel::with('legacyImage')->has('image', 0)->count();
     $flyers = FlyerModel::with('legacyImage')->has('image', 0)->limit(100)->get();
     $migrated = $flyers->count();
     // Migrate
     foreach ($flyers as $flyer) {
         $legacyImage = $flyer->legacyImage;
         // Too old?
         if (!$legacyImage->file) {
             $skipped++;
             continue;
         }
         $dir = str_split(sprintf('%08x', (int) $legacyImage->id), 2);
         array_pop($dir);
         $dir = implode('/', $dir);
         $path = 'migrate/' . $dir . '/' . $legacyImage->file;
         // Original file not found?
         if (!file_exists($path)) {
             $ignored++;
             continue;
         }
         if ($save) {
             $flyer->image()->create(['data' => $path]);
             $added++;
         }
     }
     $this->vars['added'] = $added;
     $this->vars['ignored'] = $ignored;
     $this->vars['skipped'] = $skipped;
     $this->vars['migrated'] = $migrated;
     $this->vars['unmigrated'] = $unmigrated;
 }
Example #2
0
 public function listFlyers()
 {
     if (!is_null($this->flyers)) {
         return $this->flyers;
     }
     $currentPage = input('page');
     $search = trim(input('search'));
     /** @var  Collection  $flyers */
     switch ($this->listType) {
         case self::BY_DATE:
             $flyers = FlyerModel::with('image')->date($this->year, $this->month)->paginate(16, $currentPage);
             break;
         case self::NEW_FLYERS:
             $flyers = FlyerModel::with('image')->recentFlyers()->paginate(16, $currentPage);
             break;
         case self::SEARCH:
             $query = FlyerModel::with('image')->search($search);
             if ($this->year) {
                 $query->date($this->year, $this->month);
             } else {
                 $query->recentFlyers();
             }
             $flyers = $query->paginate(16, $currentPage);
             break;
         default:
             return [];
     }
     $flyers->each(function (FlyerModel $flyer) {
         $flyer->setUrl($this->flyerPage, $this->controller);
     });
     // Pagination
     $query = [];
     $search and $query['search'] = $search;
     $query['page'] = '';
     $paginationUrl = Request::url() . '?' . http_build_query($query);
     $lastPage = $flyers->lastPage();
     if ($currentPage > $lastPage && $currentPage > 1) {
         return Redirect::to($paginationUrl . $lastPage);
     }
     $this->page['paginationUrl'] = $paginationUrl;
     return $flyers;
 }
Example #3
0
 public function onRun()
 {
     $this->page['flyer'] = $this->flyer = FlyerModel::with('image', 'event')->findOrFail((int) $this->property('id'));
 }