/** * Handle the event. * * @param EmailAddedToQueue $event * @return void */ public function handle(EmailAddedToQueue $event) { // retrieve the data from the event object $data = $event->getMail(); $response = $event->getResponse(); $tags = $data->getTags(); if (count($tags) > 1) { $tags = json_encode($tags); } else { $tags = reset($tags); } $l = MailStatistic::create(['recipient' => $data->getTo()->getEmail(), 'tag' => $tags, 'status' => 'queued', 'project_id' => $data->getProject()->id, 'service_message_id' => $response->http_response_body->id, 'category_id' => $data->getCategory() ? $data->getCategory()->id : null]); }
public function charts(Project $project) { $mailStatistics = $this->mailStatistics->newestGrouped()->pluck('status', 'id'); $lastStatuses = []; $total = 0; $mailStatistics->each(function ($item, $key) use(&$lastStatuses, &$total) { if (!isset($lastStatuses[$item])) { $lastStatuses[$item] = 0; } $lastStatuses[$item]++; $total++; }); return view("mail-stats::mail-statistics.charts", compact('project', 'lastStatuses', 'total')); }
/** * Determine the category of the given service_message_id * * @param $service_message_id * @return null|Category */ private static function determineCategoryByMessageId($service_message_id) { $mail_statistic = MailStatistic::where('service_message_id', $service_message_id)->first(); return is_null($mail_statistic) ? null : $mail_statistic->category; }
/** @test */ public function mailstat_create_without_a_given_category_should_not_throw_exception() { $statistic = $this->mailStatistics->create(['recipient' => "*****@*****.**", 'tag' => 'tag', 'status' => 'queued', 'project_id' => $this->project->id, 'service_message_id' => "insertmessageidhere"]); $this->assertInstanceOf($this->mailStatisticsClass, $statistic); $this->assertNull($statistic->category); }