DEV Community


Posted on

Task Counter v2.0 Update

I have updated my Task Counter project and thanks to the suggestion provided by @milhod in my previous post:

This is the result.
I have added icon from to sweeten up my project appearance and added activity type field for bonus point.
Image description

Image description

And if you're wondering how I put those green check marks, check out @cassidoo's great post:

Now, bonus point can be achieved by selecting activity type.

Image description

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'))

        //collecting bonus point from activity with Career type
        $bonus_career= DB::table('activities')
            ->select(DB::raw('COUNT(type)*25 AS point'))
            ->where('type', "Career")

        //collecting bonus point from activity other than Career and other type
        $bonus_else= DB::table('activities')
            ->select(DB::raw('COUNT(type)*15 AS point'))

        //collecting bonus point from activity with Other type
        $bonus_other= DB::table('activities')
            ->select(DB::raw('COUNT(type)*5 AS point'))
            ->where('type', "Other")

        //sum all collected point + bonus point

            $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]);
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)