コード例 #1
0
ファイル: Export.php プロジェクト: mazhuravlev/olx-grabber
 public static function export(Offer $offer)
 {
     $result = ['cat' => Categories::getCat(preg_replace('/^nedvizhimost\\//', '', $offer->cat_path)), 'orig_id' => $offer->olx_id, 'date_grabbed' => time(), 'date_added' => time(), 'href' => $offer->href, 'title' => $offer->title, 'description' => $offer->description, 'price' => $offer->price_string, 'thumbnail' => self::getThumbnail($offer), 'cityDetails' => self::getLocation($offer), 'source' => 'OLX', 'phone' => self::getPhones($offer)];
     $details = $offer->details;
     if (array_key_exists('Объявление от', $details) and 'Бизнес' == $details['Объявление от']) {
         $result['_agent'] = true;
     }
     foreach ($details as $parameter => $value) {
         /** @var DetailsParameter $detailParameter */
         $detailParameter = DetailsParameter::query()->where('parameter', $parameter)->first();
         if ($detailParameter and $detailParameter->export_property) {
             if ($detailParameter->is_integer_field) {
                 $result[$detailParameter->export_property] = self::extractInteger($value);
             } elseif ($detailValue = $detailParameter->detailsValues()->where('value', $value)->first() and $detailValue->export_value) {
                 $result[$detailParameter->export_property] = $detailValue->export_value;
             }
         }
     }
     return $result;
 }
コード例 #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->enableInfo = $this->option('info');
     $cache = [];
     $bar = $this->enableInfo ? null : ($bar = $this->output->createProgressBar(Offer::count()));
     $offers = Offer::query()->chunk(100, function (Collection $offers) use($bar, &$cache) {
         $this->info("Got {$offers->count()} offers");
         foreach ($offers as $offer) {
             if ($bar) {
                 $bar->advance();
             }
             foreach ($offer->details as $key => $value) {
                 if (array_key_exists($key, $cache)) {
                     if (array_key_exists($value, $cache[$key])) {
                         $this->info("{$key}:{$value} exists in cache");
                         continue;
                     }
                 } else {
                     $cache[$key] = [];
                 }
                 $detailsParameter = DetailsParameter::firstOrCreate(['parameter' => $key]);
                 try {
                     $detailsValue = $detailsParameter->detailsValues()->firstOrCreate(['value' => $value]);
                     if ($detailsValue->wasRecentlyCreated) {
                         array_push($cache[$key], $value);
                         $this->info("Added {$key}:{$value}");
                     }
                 } catch (QueryException $e) {
                     if (23000 !== intval($e->getCode())) {
                         throw $e;
                     } else {
                         $this->info("Skipped {$key}:{$value}");
                     }
                 }
             }
         }
     });
 }
コード例 #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $detailsParameterId)
 {
     $detailsParameter = DetailsParameter::findOrFail($detailsParameterId);
     $detailsParameter->update(['export_property' => $request->get('export_property'), 'is_integer_field' => 'true' === $request->get('is_integer_field') ? true : false]);
     return response()->json($detailsParameter);
 }
コード例 #4
0
 function parameter($id)
 {
     /** @var \App\Models\DetailsParameter $detailsParameter */
     $detailsParameter = \App\Models\DetailsParameter::findOrFail($id);
     return view('details_parameter')->with(['detailsParameter' => $detailsParameter, 'detailsValues' => $detailsParameter->detailsValues()->get()]);
 }