kevincp17
Posted on April 11, 2022
I have updated my Task Counter project and thanks to the suggestion provided by @milhod in my previous post:
https://dev.to/kevincp17/making-task-counter-web-for-fun-2h54
This is the result.
I have added icon from https://fontawesome.com/ to sweeten up my project appearance and added activity type field for bonus point.
And if you're wondering how I put those green check marks, check out @cassidoo's great post:
https://dev.to/cassidoo/use-unicode-characters-for-bullet-points-in-css-using-marker-3bnj
Now, bonus point can be achieved by selecting activity type.
Bonus point for each type:
- Other, +5 point
- Career, +25 point
- Anything but the previous types, +15 point
Here is the code:
public function index(Request $request)
{
$acts = DB::table('activities')->orderBy('id')->cursorPaginate(10);
$counter = DB::table('activities')
->select(DB::raw('SUM(time * rating) AS point'))
->first();
//collecting bonus point from activity with Career type
$bonus_career= DB::table('activities')
->select(DB::raw('COUNT(type)*25 AS point'))
->where('type', "Career")
->first();
//collecting bonus point from activity other than Career and other type
$bonus_else= DB::table('activities')
->select(DB::raw('COUNT(type)*15 AS point'))
->where('type','!=',"Career")
->where('type','!=',"Other")
->first();
//collecting bonus point from activity with Other type
$bonus_other= DB::table('activities')
->select(DB::raw('COUNT(type)*5 AS point'))
->where('type', "Other")
->first();
//sum all collected point + bonus point
$allPoints=$counter->point+$bonus_career->point+$bonus_else->point+$bonus_other->point;
if($allPoints<1000){
$request->session()->put('quote', "You're just started, let's go!");
}else if($allPoints<2000){
$request->session()->put('quote', "Not bad, for a newbie!");
}else if($allPoints<4000){
$request->session()->put('quote', "Nice, keep it up!");
}else if($allPoints<8000){
$request->session()->put('quote', "You're pretty good, don't get cocky though!");
}else if($allPoints<16000){
$request->session()->put('quote', "Great job, what a chad!");
}else if($allPoints<32000){
$request->session()->put('quote', "Excellent, your highness!");
}else if($allPoints>=100000){
$request->session()->put('quote', "You're a God!");
}
$request->session()->put('point', $allPoints);
return view('activities',['acts'=>$acts]);
}
So, the formula for $allPoints:
SUM(time*rating)+collected bonus point
Yes, I know. The code is way less simplified, it's hurt to see it. If any of you know how to simplified the code, let me know in the comment.
And that's the update I have worked on. Even though the project appearance is a bit lacking because I am not really good at designing something. I am more of a back end guy than front end guy.
If you have any development idea for Task Counter, please let me know.
Posted on April 11, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.