/** * Execute the job. * * @param Client $api Pre-configured instance of the Client */ public function handle(Client $api) { // Initialize $this->api = $api; $this->api->setDefaultToken($this->token); $this->api->setPassError(config('vk-requester.pass_error', true)); // Processing if (!$this->requests->isEmpty()) { $this->sendToApi(); $this->fireEvents(); } }
protected function insertAllRow($sheet) { $sheet->each(function ($row) { $data = $this->parseFilm($row); $data['genre_id'] = $this->findGenreId($row['genero'], $data['title']); $film = $this->film->create($data); $country_id = $this->findCountryId($row['pais'], $film); $film->countries()->sync($country_id); }); if (!$this->newGenres->isEmpty()) { $this->info(Lang::get('commands.iffe.new-genres-added')); $this->info(implode(',', $this->newGenres->toArray())); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $month = new Carbon($this->argument('month')); $billboards = Billboard::activated()->get(); $pictures = Storage::files(); $missing_pictures = new Collection(); foreach ($billboards as $billboard) { $facings = $billboard->facings->all(); foreach ($facings as $facing) { $ref = $this->reference($billboard, $facing, $month); $image_url = "{$ref}.jpg"; if (in_array($image_url, $pictures)) { try { $this->trackingRepository->create(['facing_id' => $facing->id, 'image_url' => $image_url, 'tracking_date' => $month, 'location_id' => $billboard->location_id]); $this->info('Tracking #' . $ref . ' with image url ' . $image_url . ' created successfully.'); } catch (\Illuminate\Database\QueryException $e) { $this->error('Tracking #' . $ref . ' already exists.'); } } else { $this->error('Facing #' . $ref . ' picture missing.'); $missing_pictures->push(["name" => $facing->name, "image_url" => $image_url]); } } } if (!$missing_pictures->isEmpty()) { $this->notifyMissingPictures($missing_pictures, "*****@*****.**"); } }
/** * Format an Eloquent collection. * * @param \Illuminate\Database\Eloquent\Collection $collection * @return string */ public function formatEloquentCollection($collection) { if ($collection->isEmpty()) { return $this->encode([]); } $key = str_plural($collection->first()->getTable()); return $this->encode([$key => $collection->toArray()]); }
/** * Get the current status of the xml files according to the organization's segmentation/publishing type. * @param $currentFiles * @return array */ public function getCurrentStatus(Collection $currentFiles) { $currentStatus = []; if (!$currentFiles->isEmpty()) { $currentFiles->each(function ($file) use(&$currentStatus) { $currentStatus[$file->filename]['included_activities'] = $file->extractActivityId(); $currentStatus[$file->filename]['published_status'] = $file->published_to_register; }); } return $currentStatus; }
/** * Format data for simple csv * @param Collection $activities * @return array */ public function format(Collection $activities) { if ($activities->isEmpty()) { return false; } $this->csvData = ['headers' => $this->headers]; foreach ($activities as $activity) { $this->csvData[] = ['iati-identifier' => $activity->identifier['iati_identifier_text'], 'title' => !$activity->title ? '' : $this->formatTitle($activity->title), 'description_general' => !$activity->description ? '' : $this->formatDescription($activity->description, '1'), 'description_objective' => !$activity->description ? '' : $this->formatDescription($activity->description, '2'), 'description_target' => !$activity->description ? '' : $this->formatDescription($activity->description, '3'), 'description_others' => !$activity->description ? '' : $this->formatDescription($activity->description, '4'), 'activity-status' => (int) $activity->activity_status, 'start-planned' => !$activity->activity_date ? '' : $this->formatActivityDate($activity->activity_date, '1'), 'start-actual' => !$activity->activity_date ? '' : $this->formatActivityDate($activity->activity_date, '2'), 'end-planned' => !$activity->activity_date ? '' : $this->formatActivityDate($activity->activity_date, '3'), 'end-actual' => !$activity->activity_date ? '' : $this->formatActivityDate($activity->activity_date, '4'), 'funding_organisations' => !$activity->participating_organization ? '' : $this->formatParticipatingOrg($activity->participating_organization, '1'), 'accountable_organisations' => !$activity->participating_organization ? '' : $this->formatParticipatingOrg($activity->participating_organization, '2'), 'extending_organisations' => !$activity->participating_organization ? '' : $this->formatParticipatingOrg($activity->participating_organization, '3'), 'implementing_organisations' => !$activity->participating_organization ? '' : $this->formatParticipatingOrg($activity->participating_organization, '4'), 'recipient-country' => !$activity->recipient_country ? '' : $this->formatRecipientCountry($activity->recipient_country), 'recipient-country-codes' => !$activity->recipient_country ? '' : $this->formatRecipientCountryCodes($activity->recipient_country), 'recipient-country-percentages' => !$activity->recipient_country ? '' : $this->formatRecipientCountryPercentages($activity->recipient_country), 'recipient-region' => !$activity->recipient_region ? '' : $this->formatRecipientRegions($activity->recipient_region), 'recipient-region-codes' => !$activity->recipient_region ? '' : $this->formatRecipientRegionCodes($activity->recipient_region), 'recipient-region-percentages' => !$activity->recipient_region ? '' : $this->formatRecipientRegionPercentages($activity->recipient_region), 'sector-text' => !$activity->sector ? '' : $this->formatSectorText($activity->sector), 'sector-vocabularies' => !$activity->sector ? '' : $this->formatSectorVocabularies($activity->sector), 'sector-codes' => !$activity->sector ? '' : $this->formatSectorCodes($activity->sector), 'sector-percentages' => !$activity->sector ? '' : $this->formatSectorPercentages($activity->sector), 'total-incoming-funds' => !$activity->transactions ? '' : $this->formatTransactionValues($activity->transactions, 1), 'total-commitments' => !$activity->transactions ? '' : $this->formatTransactionValues($activity->transactions, 2), 'total-disbursements' => !$activity->transactions ? '' : $this->formatTransactionValues($activity->transactions, 3), 'total-expenditure' => !$activity->transactions ? '' : $this->formatTransactionValues($activity->transactions, 4)]; } return $this->csvData; }
/** * Format an Eloquent collection. * * @param \Illuminate\Database\Eloquent\Collection $collection * * @return string */ public function formatEloquentCollection($collection) { if ($collection->isEmpty()) { return $this->encode([]); } $model = $collection->first(); $key = str_plural($model->getTable()); if (!$model::$snakeAttributes) { $key = camel_case($key); } return $this->encode([$key => $collection->toArray()]); }
/** * Format data for Complete Csv generation. * @param Collection $activities * @return array */ public function format(Collection $activities) { try { if ($activities->isEmpty()) { return false; } $this->prepareCsv($activities); $elementFactories = $this->generateElementFactories(array_keys(array_first($this->data, function ($index, $value) { return $value; })), $this->except); return $this->fillActivityElementData($elementFactories, $activities)->fillTransactionData($activities)->fillResultData($activities); } catch (Exception $exception) { $this->logger->error($exception); } return null; }
/** * Display one or more prospects. * * @note We're using the 'table()' function which expects an array * of arrays (i.e. rows of data items/fields) * * @param Collection $prospects * @param bool $forceList * @param int $maxLen */ protected function showProspects($prospects, $forceList = false, $maxLen = 76) { if (empty($prospects) || $prospects->isEmpty()) { $this->info('No prospect records to display'); return; } if ($prospects->count() > 1 || $forceList) { $rows = $prospects->toArray(); $this->table(array_keys($rows[0]), $rows); } else { $prospect = $prospects->first(); $data = $prospect->toArray(); $rows = []; foreach ($data as $k => $v) { $rows[] = [$k, is_string($v) ? str_limit($v, $maxLen) : $v]; } $this->table(['field', 'value'], $rows); } $this->info(''); // Print a blank line }
/** * to create a lot of wrapper by using models in Eloquent Collection * * @param \Illuminate\Support\Collection $collection * @param \Illuminate\Database\Eloquent\Model|int $wantedLang language id or specific language model * @param \Illuminate\Database\Eloquent\Model|int $defaultLang language id or specific language model * @return \Illuminate\Support\Collection */ protected function createWrappersInCollection(Collection $collection, $wantedLang, $defaultLang) { $newCollection = new EloquentColl(); $tempCollection = new EloquentColl($collection->all()); while (!$tempCollection->isEmpty()) { $newCollection->add($this->wrapper->createNew($tempCollection->shift(), $wantedLang, $defaultLang)); } return $newCollection; }