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
 /**
  * Import flyer from url.
  *
  * @param  string  $url
  * @param  bool    $replace
  * @return  bool
  */
 public function importFlyer($url = null, $replace = false)
 {
     $existingFlyer = null;
     if ($replace) {
         $existingFlyer = $this->flyers->first();
         // @TODO: Backwards compatibility, remove when Anqh is killed
         if (!$existingFlyer && $this->flyer_id) {
             $existingFlyer = FlyerModel::find($this->flyer_id);
         }
     }
     if ($url && $url != $this->flyer_url) {
         // Import flyer from new url
         $flyerUrl = $url;
     } else {
         if (!$url && $this->flyer_url) {
             // Import flyer from existing url
             $flyerUrl = $this->flyer_url;
         }
     }
     if (isset($flyerUrl)) {
         return Db::transaction(function () use($flyerUrl, $existingFlyer) {
             $flyer = FlyerModel::importToEvent($this, $flyerUrl, $existingFlyer);
             $this->flyer_url = $flyerUrl;
             $this->flyer_front_url = url($flyer->image->getPath());
             return $this->save();
         });
     }
     return false;
 }
Example #3
0
 public function listMonths()
 {
     if (!is_null($this->months)) {
         return $this->months;
     }
     $months = [];
     foreach (FlyerModel::countsPerMonth() as $year => $counts) {
         $months[$year] = ['months' => [], 'url' => $this->controller->pageUrl($this->flyersPage, ['year' => $year], false), 'active' => $year === $this->year];
         foreach ($counts as $month => $count) {
             $months[$year]['months'][$month] = ['count' => $count, 'url' => $this->controller->pageUrl($this->flyersPage, ['year' => $year, 'month' => $month], false), 'active' => $year === $this->year && $month === $this->month];
         }
     }
     return $this->months = $months;
 }
Example #4
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 #5
0
 public function onRun()
 {
     $this->page['flyer'] = $this->flyer = FlyerModel::with('image', 'event')->findOrFail((int) $this->property('id'));
 }