protected function importImages($techid, $resource = 'Property', $quality = 'HiRes') { // connect $this->rets = \App::make('rets'); // we should have things in DB now, and we can look at that data. $listing = RetsProperty::where('techid', $techid)->first(); if (is_null($listing)) { $this->error('Not able to locate listing by techid'); return false; } // clean all images $listing->photos()->delete(); $this->line('We\'re expecting ' . $listing->piccount . ' images for ' . $listing->listnbr); $images = $this->rets->getImage($resource, $listing->techid, '*', $quality); $this->line('Images collections:'); if (is_null($images)) { $this->error($listing->techid . ' has no images'); if ($listing->piccount == 0) { return; } $this->line('Going to get images (' . $listing->piccount . ') one by one'); for ($p = 1; $p <= $listing->piccount; $p++) { $image = $this->rets->getImage($resource, $listing->techid, $p, $quality); if (is_null($image)) { continue; } $file = RetsImage::fromApi($image); $listing->photos()->save($file); } $this->info('Images imported!'); return; } $this->line('We have ' . $images->count() . ' images'); foreach ($images as $i => $image) { $file = RetsImage::fromApi($image); $listing->photos()->save($file); } }
protected function importImagesAgency() { // we should have things in DB now, and we can look at that data. $listingCount = RetsProperty::where('listing_office_shortid', \Config::get('system.sales.office_id', '445sp'))->count(); $this->line('We have ' . $listingCount . ' items in property table'); $loadImages = $this->ask('Are you ready to load all images? (y/n)', 'y'); if (strtolower($loadImages) == 'n') { $this->line('You can load images any time later.'); exit; } if ($listingCount > 0) { for ($i = 0; $i < $listingCount; $i += 100) { $this->info('Current offset: ' . $i); $listings = RetsProperty::where('listing_office_shortid', \Config::get('system.sales.office_id', '445sp'))->take(100)->skip($i)->get(['techid']); foreach ($listings as $listing) { $this->call('rets:image', ['--id' => $listing->techid]); } } } }