Choosing the right tool for the job sometimes means bringing along a whole toolbox. I’ll show how a complex back-end system was built with Craft, Laravel, Redis, and more, all working in harmony.
https://www.flickr.com/photos/iangbl/
View Slide
https://www.flickr.com/photos/florianric/
https://www.flickr.com/photos/pennuja/
Yeah, we could make that work.
Yeah, we could make that work.But…
Content
Content Users
Content Users Voting
https://www.flickr.com/photos/beraldoleal
Route::get('/', array('as' => 'home','uses' => 'HomeController@ ','after' => 'cache'));showVoteHome
!!Route::filter('cache', function($route, $request, $response, $max_age=1200){});
class Nominee extends Eloquent {!// ...!}
SELECT description,body,tagline,hashtag,closingTimeFROM craft_content
// ...}class Nominee extends Eloquent {
// ...}class Nominee extends Eloquent {protected $table = 'craft_entries_i18n';
// ...}class Nominee extends Eloquent {protected $table = 'craft_entries_i18n';private $sectionId = 2;
public function scopeListing($query){return $query->select( /* ... */ )->join( /* ... */ )->where( /* ... */ );}
public function scopeListing($query){return $query->select( /* ... */ )->join('craft_content', 'craft_content.elementId', '=', 'craft_entries_i18n.entryId')->join('craft_entries', 'craft_entries.id', '=', 'craft_entries_i18n.entryId')->join('craft_elements', 'craft_elements.id', '=', 'craft_entries_i18n.entryId')->where('craft_entries_i18n.sectionId','=',$this->sectionId)->where('craft_entries.postDate','<=',date_format(new DateTime(),'Y-m-d G:i:s'))->where(function($query){$query->where('craft_entries.expiryDate','=',NULL)->orWhere('craft_entries.expiryDate','>=',date_format(new DateTime(),'Y-m-d G:i:s'));})->where('craft_elements.enabled','=',1);}
->where('craft_entries_i18n.sectionId','=',$this->sectionId)
->join('craft_content','craft_content.elementId', '=','craft_entries_i18n.entryId')
->join('craft_entries','craft_entries.id', '=','craft_entries_i18n.entryId')
->where('craft_entries.postDate','<=',date_format(new DateTime(),'Y-m-d G:i:s'))
->where(function($query){$query->where('craft_entries.expiryDate','=',NULL)->orWhere('craft_entries.expiryDate','>=',date_format(new DateTime(),'Y-m-d G:i:s'));})
->join('craft_elements','craft_elements.id', '=','craft_entries_i18n.entryId')
->where('craft_elements.enabled','=',1)
$nominees = Nominee::listing()->orderBy('craft_entries_i18n.title')->get();
Users
// ...}class User extends Eloquent {
// ...}class User extends Eloquent {protected $table = 'craft_users';
craft_usersidusernamefirstNamelastNamestatus
oma_usersuserIdavatarbioproviderDataproviderTokenscraft_usersidusernamefirstNamelastNamestatus
Voting
public function cast($voterId, $nomineeId, $categoryId, $influencerId = 0){!// ...!}
$redis = Redis::connection('oma4-votes');!$voter = "user[{$voterId}]";$nominee = "nominee[{$nomineeId}]";$category = "category[{$categoryId}]";$influencer = “user[{$influencerId}]”;!$datetime = new DateTime();$date['day'] = $datetime->format('Y-m-d');$date['hour'] = $datetime->format('Y-m-d-H');
// Vote Counts$redis->incrby('votes',1);$redis->hincrby("votes:{$voter}",'total',1);$redis->hincrby("votes:{$voter}",'cast',1);
// Nominee Standings$redis->zincrby("standings:nominee",1,$nominee);$redis->zincrby("standings:nominee:{$category}",1,$nominee);$redis->zincrby("standings:nominee:{$voter}",1,$nominee);
$redis->zrevrange("standings:nominee", 0, -1, 'WITHSCORES');
// Activity Trends$redis->hincrby("trends:{$voter}",$date['day'],1);$redis->hincrby("trends:{$voter}",$date['hour'],1);$redis->hincrby("trends:{$nominee}",$date['hour'],1);$redis->hincrby("trends:{$category}",$date['hour'],1);
$hourOne = $redis->hget("trends:{$nominee}", '2013-06-19-20');$hourTwo = $redis->hget("trends:{$nominee}", '2013-06-19-21');$hourThree = $redis->hget("trends:{$nominee}", '2013-06-19-22');
Be Pragmatic.
@acolangelo