Skip to content

Commit

Permalink
Created migrations, seeders, relationship speaker -> schedule; Remove…
Browse files Browse the repository at this point in the history
…d sponsors from home; Sessions layout; Home controller pulls sessions from database
  • Loading branch information
tdiam committed Feb 18, 2018
1 parent 8b0e4e5 commit ba09884
Show file tree
Hide file tree
Showing 14 changed files with 386 additions and 262 deletions.
30 changes: 22 additions & 8 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,38 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use LaravelLocalization;
use App\Speaker;

class HomeController extends Controller {

public function index(Request $request) {
// $speakers = DB::table('speakers')->get();
$speakers = Speaker::all();

$data['name'] = 'Big Shaq';
$data['short_description'] = "Enterpreneur computer engineer and white hat hacker";
$data['id'] = 'jobs';
$data['img_src'] = 'https://i1.sndcdn.com/artworks-000241864958-t7ad44-t500x500.jpg';
$speakers = array($data, $data, $data);
$sessions = [
['from' => '10:30', 'to' => '12:30'],
['from' => '13:00', 'to' => '15:00'],
['from' => '15:30', 'to' => '17:30']
];

/* Contains three arrays, one for each session */
$speakersBySession = [[], [], []];

foreach($speakers as $speaker) {
$talk = $speaker->talk;
foreach($sessions as $i => $session) {
if($talk->hour >= $session['from'] && $talk->hour <= $session['to']) {
$speakersBySession[$i][] = $speaker;
break;
}
}
}

$isPjax = $request->header('X-PJAX');
if ($isPjax) {
return response()->view('home', compact('isPjax', 'speakers'), 200)
return response()->view('home', compact('isPjax', 'sessions', 'speakersBySession'), 200)
->header('X-PJAX-URL', LaravelLocalization::getLocalizedURL());
}
return view('home', compact('speakers'));
return view('home', compact('sessions', 'speakersBySession'));
}

}
26 changes: 26 additions & 0 deletions app/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,30 @@ class Schedule extends Model
// type: workshop or talk
use HasTranslations;
public $translatable = ['event_title','event_prev','subtitle'];
public $timestamps = false;

public function speaker() {
return $this->belongsTo('App\Speaker')->withDefault();
}

/* So that toArray() method in Schedule controller returns the translated value of each attribute
and also returns the event title link mutator attribute */
public function toArray() {
$attributes = parent::toArray();

foreach ($this->getTranslatableAttributes() as $name) {
$attributes[$name] = $this->getTranslation($name, app()->getLocale());
}
$attributes["event_title_link"] = $this->event_title_link;

return $attributes;
}

public function getEventTitleLinkAttribute() {
if($this->type == "talk") {
return '<a href="/speakers#' . $this->speaker->sid . '">' . $this->speaker->name . '</a>';
} else {
return $this->event_title;
}
}
}
9 changes: 7 additions & 2 deletions app/Speaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

class Speaker extends Model
{
// other fields: id,img_src
// other fields: id,img_src,schedule_id;
use HasTranslations;
public $translatable = ['name','talk_title','talk_prev','bio'];
public $translatable = ['name','bio'];
public $timestamps = false;

public function talk() {
return $this->hasOne('App\Schedule');
}
}
37 changes: 37 additions & 0 deletions database/migrations/2018_02_18_005101_create_schedules_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

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

class CreateSchedulesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('schedules', function (Blueprint $table) {
$table->increments('id');
$table->char('hour', 5);
$table->text('img_src');
$table->text('type');
$table->unsignedInteger('speaker_id')->nullable();
$table->json('event_title');
$table->json('event_prev');
$table->json('subtitle');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('schedules');
}
}
34 changes: 34 additions & 0 deletions database/migrations/2018_02_18_005326_create_speakers_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

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

class CreateSpeakersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('speakers', function (Blueprint $table) {
$table->increments('id');
$table->string('sid')->unique();
$table->text('img_src');
$table->json('name');
$table->json('bio');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('speakers');
}
}
64 changes: 47 additions & 17 deletions database/seeds/ScheduleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,55 @@ class ScheduleSeeder extends Seeder
*/
public function run()
{
DB::table('schedules')->insert([
'hour'=>'13:12',
'img_src'=>'scienceReactors.jpeg',
'type'=>'performance',
'event_title'=>json_encode([
'en'=>'Science Reactors',
'el'=> 'Science Reactors',
]),
'event_prev'=>json_encode([
'en'=>'Why god studied electrical engineering',
'el'=>'Γιατί ο θεός είναι ηλεκτρολόγος',
$schedules = [
App\Schedule::create([
'hour' => '13:12',
'img_src' => 'scienceReactors.jpeg',
'type' => 'performance',
/* Be careful not to use json_encode in create method, since laravel-translatable takes care of it by itself */
'event_title' => [
'en' => 'Science Reactors',
'el' => 'Science Reactors'
],
'event_prev' => [
'en' => 'Why God studied Electrical Engineering',
'el' => 'Γιατί ο Θεός είναι ηλεκτρολόγος'
],
'subtitle' => [
'en' => 'Justification.',
'el' => 'Ερμηνεία-Επεξήγηση'
]
]),
'subtitle'=>json_encode([
'en'=>'Justification.',
'el'=>'Ερμηνεία-Επεξήγηση.',
App\Schedule::create([
'hour' => '14:00',
'img_src' => 'styllas.jpeg',
'type' => 'talk',
'event_title' => [
'en' => 'Michail Styllas',
'el' => 'Μιχάλης Στύλλας'
],
'event_prev' => [
'en' => 'Everest, the end of chaos!',
'el' => 'Το τέλος του χάους στο everest!'
],
'subtitle' => [
'en' => 'Chaos is extreme weather, chaos is extreme love!',
'el'=> 'Χάος είναι ο ακραίος καιρός του έβερεστ, χάος είναι η αγάπη'
],
'speaker_id' => App\Speaker::create([
'name' => [
'en' => 'Michail Styllas',
'el' => 'Μιχάλης Στύλλας'
],
'sid' => 'styllas',
'img_src' => 'styllas.jpeg',
'bio' => [
'en' => 'dede',
'el'=> 'δεδεδ',
]
])->id
])
]);


];

}
}
20 changes: 0 additions & 20 deletions database/seeds/SpeakersSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,5 @@ class SpeakersSeeder extends Seeder
*/
public function run()
{
DB::table('speakers')->insert([
'name'=>json_encode([
'en'=> 'Michail Styllas',
'el'=> 'Μιχάλης Στύλας'
]),
'id'=>'styllas',
'img_src'=>'styllas.jpeg',
'talk_title'=>json_encode([
'en'=>'Everest, the end of chaos!',
'el'=> 'Το τέλος του χάους στο everest!',
]),
'talk_prev'=>json_encode([
'en'=>'Chaos is extreme weather, chaos is extreme love!',
'el'=>'Χάος είναι ο ακραίος καιρός του έβερεστ, χάος είναι η αγάπη'
]),
'bio'=>json_encode([
'en'=>'dede',
'el'=>'δεδεδ'
])
]);
}
}
Loading

0 comments on commit ba09884

Please sign in to comment.