Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Repositories\DonationRepository;
use App\Repositories\NeedsRepository;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Cookie;

class HomeController extends Controller
{
Expand All @@ -19,23 +20,38 @@ class HomeController extends Controller
public function __construct(DonationRepository $donationRepository, NeedsRepository $needsRepository)
{
$this->donation = $donationRepository;
$this->need = $needsRepository;
$this->need = $needsRepository;
}

/**
* Home page
* @return $this
*/
public function index()
public function index(Request $request)
{
$donations = $this->donation->getDonations(5);
$needs = $this->need->getNeeds(5);
$donations = $this->donation->getDonations(5);
$needs = $this->need->getNeeds(5);
$hideGreeting = false;

return view('frontend/home')
if ($request->hideGreeting || $request->cookie('hideGreeting')) {
$hideGreeting=true;
}


$view = view('frontend/home')
->with([
'donations' => ($donations) ? $donations : array(),
'needs' => ($needs) ? $needs : array()
'needs' => ($needs) ? $needs : array(),
'greeting' => $hideGreeting
]);

if ($hideGreeting) {
$hideGreetingCookie = cookie('hideGreeting', 'my value',60*24);
return response($view)->withCookie($hideGreetingCookie);
} else {
return $view;
}

}

/**
Expand Down
21 changes: 20 additions & 1 deletion app/Repositories/DonationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class DonationRepository implements DonationInterface
{
const DONATION_ID_PREFIX = "O";

/**
* Add donations
*
Expand All @@ -22,8 +24,14 @@ class DonationRepository implements DonationInterface
public function addDonation($input)
{
try {
Donation::create($input);
$donation = Donation::create($input);

//Update Reference column
$donation->ref = self::DONATION_ID_PREFIX.$donation->id;
$donation->save();

return true;

} catch (\Exception $e) {
Log::error($e->getMessage());
return false;
Expand Down Expand Up @@ -64,4 +72,15 @@ public function findDonation($id)
return false;
}
}

public function cha($id)
{
try {
return Donation::find($id);
} catch (\Exception $e) {
Log::error($e->getMessage());
return false;
}
}

}
11 changes: 10 additions & 1 deletion app/Repositories/NeedsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

class NeedsRepository implements NeedsInterface
{
const NEED_ID_PREFIX = "R";

/**
* Add needs
*
Expand All @@ -23,8 +25,15 @@ class NeedsRepository implements NeedsInterface
public function addNeed($input)
{
try {
Need::create($input);

$need = Need::create($input);

//Update Reference column
$need->ref = self::NEED_ID_PREFIX.$need->id;
$need->save();

return true;

} catch (\Exception $e) {
Log::error($e->getMessage());
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddColumnsDonationNeeds extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('donations', function (Blueprint $table) {
$table->string('ref')->default(0);
});

Schema::table('needs', function (Blueprint $table) {
$table->string('ref')->default(0);
});

//Update ref column
$sql = "UPDATE donations SET ref= concat('O',id) WHERE id>0";
DB::connection()->getPdo()->exec($sql);

$sql = "UPDATE needs SET ref= concat('R',id) WHERE id>0";
DB::connection()->getPdo()->exec($sql);


}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::enableForeignKeyConstraints();

Schema::table('donations', function (Blueprint $table) {
$table->dropColumn('ref');
});

Schema::table('needs', function (Blueprint $table) {
$table->dropColumn('ref');
});

Schema::disableForeignKeyConstraints();
}
}
12 changes: 11 additions & 1 deletion public/css/app.css

Large diffs are not rendered by default.

Loading