Skip to content

Instantly share code, notes, and snippets.

@jonahgeorge
Last active January 19, 2017 19:00
Show Gist options
  • Save jonahgeorge/2f90f29f6b3ada56aa82179dbb4247fd to your computer and use it in GitHub Desktop.
Save jonahgeorge/2f90f29f6b3ada56aa82179dbb4247fd to your computer and use it in GitHub Desktop.
<?php
namespace App\Reports;
class BaseReport
{
public function render()
{
renderReport($this->header(), $this->results, [
'pageTitle' => $this->pageTitle(),
'subTitle' => $this->subTitle(),
'headerNote' => $this->headerNote(),
'getData' => $this->getData(),
'groupBy' => $this->groupBy(),
'export' => $this->export(),
]);
}
}
<?php
namespace App\Queries;
use \App\Models\Discipline;
use \App\Models\Company;
use \App\Eloquent\OrganizationLotteryPick;
class LotteryNumbersQuery extends Query
{
private $year;
private $discipline;
public function __construct(int $year, string $discipline)
{
$this->year = $year;
$this->discipline = $discipline;
}
public function run(): array
{
$rawLotteryPicks = $this->getRawLotteryPicks($this->year);
$activeCompanies = $this->getActiveCompanies();
$disciplines = $this->getDisciplines();
foreach ($rawLotteryPicks as $pick) {
if (!empty($this->discipline) && $pick['Disc_Code'] !== $this->discipline) {
continue;
}
if (!isset($activeCompanies[$pick['Org_code']]['name']) || empty($activeCompanies[$pick['Org_code']]['name'])) {
continue; //ignore inactive companies
}
if ($pick['Disc_Code'] !== $currentDisc) {
$currentDisc = $pick['Disc_Code'];
$disc_pick = 1;
}
$results[] = [
'Discipline' => $disciplines[$pick['Disc_Code']]['Disc_Name'],
'Pick Number' => $disc_pick,
'Company' => $companies[$pick['Org_code']]['name'],
'Lottery Draw Number' => $pick['Pick_No']
];
$disc_pick++;
}
return $results;
}
private function getRawLotteryPicks(int $year)
{
return OrganizationLotteryPick::where("Placement_Year", $year)
->orderBy("Disc_Code", "ASC")
->orderBy("Pick_No", "ASC")
->get()
->toArray();
}
private function getActiveCompanies()
{
$companies = json_decode(json_encode(Company::getActiveCompanies()), true);
return array_combine(array_column($companies, 'id'), $companies);
}
private function getDisciplines()
{
return Discipline::all()->keyBy("Disc_Code")->toArray();
}
}
<?php
namespace App\Reports;
class LotteryNumbersReport extends BaseReport
{
private $year;
private $discipline;
public function __construct(int $year, string $discipline)
{
$this->year = $year;
$this->discipline = $discipline;
$this->results = (new LotterNumbersQuery($year, $discipline))->run();
}
private function getData()
{
return '&year=' . $this->year . '&discipline=' . $this->discipline;
}
private function export()
{
return true;
}
private function groupBy()
{
return 'Discipline';
}
private function header()
{
$header = [];
if (count($this->results) > 0) {
$header = array_keys($this->results[0]);
}
return $header;
}
private function pageTitle()
{
return "Lottery Pick Numbers";
}
private function subTitle()
{
$subTitle = $this->year . " Placement Year";
$disciplines = Discipline::all()->keyBy('Disc_Code')->toArray();
if (empty($this->discipline)) {
$subTitle .= " - All Disciplines";
} else {
$subTitle .= " - " . $disciplines[$this->discipline]['Disc_Name'];
}
return $subTitle;
}
private function headerNote()
{
return <<<HTML
<div class="alert alert-info">
<i class="fa fa-info-circle"></i>
<b>Note:</b> Discipline pick orders will be made available once the MECOP Office
enters the numbers that were drawn at the Lottery Draw Meeting for '.{$this->year}.' Placement.
If any of your company's numbers are incorrect, please contact the MECOP Office. Thank you.
</div>
HTML;
}
}
<?php
namespace App\Controllers\Member;
use \App\Reports\LotteryNumbersReport;
use \Illuminate\Http\Request;
class ReportsController extends DBReportController
{
public function lottery_numbers(Request $request)
{
$year = $request->input('year');
if (empty($year)) {
$year = placementYearSeptemberCutoff();
}
$discipline = $request->input('discipline');
$report = new LotteryNumbersReport($year, $discipline);
$report->render();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment