WEBVTT

00:00.530 --> 00:05.840
Okay guys, so we've got this dashboard page, the only page so far in the admin.

00:05.930 --> 00:10.580
And as the dashboard should display something useful.

00:10.610 --> 00:15.980
It should display some kind of an overview of what's happening inside the system.

00:16.850 --> 00:25.040
I think we can just go with displaying the recent posts and the most recent comments.

00:25.040 --> 00:32.960
So maybe in the future we're going to be able to somehow moderate those comments so you can expand the

00:32.960 --> 00:35.420
system further if you wish.

00:35.990 --> 00:40.490
So now let's see a way of how can we get this data.

00:42.500 --> 00:46.850
So we need a way to get the total number of posts.

00:46.880 --> 00:49.520
Well I think we can do that easily.

00:49.520 --> 00:53.930
We've got the count method inside the post model.

00:53.930 --> 00:58.850
If we skip the search we can easily calculate the total posts.

00:58.850 --> 01:03.830
But do we have a way to do the same with comments?

01:04.970 --> 01:06.980
So let's jump to the comment model.

01:08.660 --> 01:10.550
So jumping to comment.

01:10.550 --> 01:19.670
We haven't created the count method, nor we don't really have a based base method in the model class.

01:19.910 --> 01:29.450
So I think we can jump to post now and see if maybe couple of those methods like this get reset method

01:29.510 --> 01:31.700
or the count method.

01:31.730 --> 01:39.770
Maybe we can have a more generic versions of those that can be placed inside the model class, and they

01:39.770 --> 01:44.270
only would have to be extended like we did in post model.

01:44.270 --> 01:52.640
If we have some special requirements like we need to take some search query into the account.

01:54.110 --> 01:55.910
So let's do it.

01:55.940 --> 01:58.640
Let me copy those methods.

01:59.850 --> 02:05.040
They get resent and count, move them to the model or not move them.

02:05.040 --> 02:06.720
Just paste them there.

02:06.720 --> 02:12.240
And let's create a base method that can work with any table.

02:13.290 --> 02:17.490
We are assuming there is no search query in this base.

02:18.120 --> 02:22.830
Base get recent method and I keep saying it is based.

02:22.980 --> 02:27.630
Maybe it is, but I mean base method.

02:27.870 --> 02:30.870
So we don't need the search query.

02:33.060 --> 02:40.710
But we'd like to limit to limit the amount of returned whatever we want to fetch.

02:40.740 --> 02:42.210
Posts comments, whatever.

02:42.240 --> 02:43.830
We also have.

02:43.860 --> 02:46.710
Or we can have some generic pagination.

02:46.710 --> 02:52.170
So I'm going to squeeze this code just so we can see as much as possible.

02:52.650 --> 02:53.430
Or maybe not.

02:53.460 --> 02:54.690
It won't be readable.

02:54.990 --> 03:03.810
So I think it is a good Generic code that really can work with any database table.

03:03.810 --> 03:05.640
It will get the recent.

03:05.670 --> 03:12.090
Models and gives us an option to limit the results or to paginate.

03:12.120 --> 03:18.480
Next up with the count, we can have a base method that doesn't have a search query.

03:20.070 --> 03:25.110
So if there is no parameters, this means we don't have the search query.

03:25.110 --> 03:34.200
But also we don't need this params array and instead we can just pass an empty array here.

03:34.320 --> 03:37.950
And I think this would work fine.

03:39.960 --> 03:46.860
This would be extended in the post model, which I can easily check by going to posts.

03:46.890 --> 03:54.690
Everything still works, so post model just extends those base methods.

03:54.840 --> 04:02.190
But now by adding those to the base model class, we magically have the possibility to get the count

04:02.190 --> 04:03.300
of comments.

04:04.200 --> 04:10.800
This would be total comments and now I can do comment count.

04:11.130 --> 04:16.200
Next up I can get recent posts.

04:16.860 --> 04:21.210
So I'm doing post get recent.

04:21.480 --> 04:23.640
Let's take five.

04:23.640 --> 04:25.800
And same with comments.

04:26.130 --> 04:33.600
This is recent comments and we can do the same with the comment model.

04:34.080 --> 04:37.650
So it's time that we pass this data to the view.

04:39.060 --> 04:48.180
So we've got the total posts which is the total posts variable.

04:48.360 --> 04:52.050
Then we've got the total comments.

04:53.490 --> 04:55.380
That's total comments.

04:55.890 --> 04:59.880
Then we've got recent posts.

05:02.490 --> 05:06.600
And finally we've got the recent comments.

05:09.990 --> 05:13.860
And by having this data we can now jump to the view.

05:14.490 --> 05:17.430
So let me find the view for the dashboard.

05:17.430 --> 05:19.860
And let's display all that data.

05:19.890 --> 05:21.390
Let's jump to admin.

05:23.400 --> 05:34.530
Let me turn this element into an H2 saying maybe an overview like this.

05:34.530 --> 05:42.720
Then let's get a section of the page with an H3 that can say stats.

05:43.410 --> 05:46.920
And first we display the total posts.

05:46.950 --> 05:53.490
Now obviously you can just try and make it more beautiful, but that's just not our focus right now.

05:55.480 --> 06:02.620
So we've got three total posts and then the comments.

06:03.940 --> 06:08.560
So we should have more eight total comments.

06:08.560 --> 06:09.610
That's nice.

06:09.880 --> 06:17.800
And next up let's add another section in this dashboard overview that will be H3.

06:17.800 --> 06:23.320
And we're gonna just list the recent posts.

06:23.350 --> 06:29.170
Let's use an unordered list and a for each loop.

06:29.170 --> 06:36.250
So we're gonna loop over all the recent posts as post column.

06:37.120 --> 06:42.220
Let me finish this off with an end for each.

06:43.570 --> 06:49.870
And I think we can display a link to the post.

06:49.870 --> 06:54.820
And we might actually have two links.

06:54.820 --> 07:02.440
Um, we might have a link to the post itself so we can preview it and another one to edit the post.

07:02.440 --> 07:04.720
Since we don't really have an editor yet.

07:04.720 --> 07:08.110
For now, let it be the post preview.

07:08.140 --> 07:15.790
So this would be post ID and maybe I'm not going to say preview.

07:15.790 --> 07:27.460
Instead I'm going to output HTML special chars post title like this.

07:28.510 --> 07:35.950
I think it's fine and let me copy paste this section to be quicker.

07:38.770 --> 07:41.860
And now let's display some comments.

07:41.860 --> 07:47.620
So with comments we probably don't really have a way to link.

07:47.620 --> 07:51.100
We would have to link to a specific post.

07:53.770 --> 07:57.010
Um, this is recent comments.

07:57.370 --> 08:04.000
Okay, so maybe let's link to the posts from which the comments come from.

08:04.000 --> 08:11.380
And in here let's use the comment content.

08:11.410 --> 08:16.630
The link can be to the comment posted.

08:16.990 --> 08:18.040
This is a column.

08:18.040 --> 08:19.630
We've got a foreign key.

08:19.630 --> 08:21.940
And also the comment can be longer.

08:21.970 --> 08:32.020
That's why I think we should use Substr to just get the fragment of the comment, maybe the first 50

08:32.050 --> 08:37.030
characters, and then let's add three dots at the end.

08:39.250 --> 08:46.810
And now let me fix this one and I think it looks okay.

08:46.840 --> 08:50.440
We can go to the post which had that comment.

08:50.470 --> 08:53.360
We can also work on making a better link.

08:53.360 --> 08:58.610
That would, um, take us directly to a specific comment.

08:58.610 --> 09:01.400
I think this is easily achievable.

09:01.400 --> 09:03.680
We can do it later on.

09:03.830 --> 09:06.710
For now, I think this is enough.

09:07.220 --> 09:16.640
So we were successful in listing only five recent comments and well, we are free to build functionality

09:16.640 --> 09:23.600
that would let us moderate the comments, remove them, change them, do whatever we need for now.

09:23.600 --> 09:25.430
This dashboard is enough.

09:25.430 --> 09:31.130
And next up we're going to build the post managing uh panel.

09:31.130 --> 09:38.090
And then we're going to add the authorization to this system, because currently it's enough to have

09:38.090 --> 09:42.590
an account to be able to do anything with those blog posts.

09:42.590 --> 09:46.070
So we can go to the dashboard and see our stats.

09:46.070 --> 09:49.730
You shouldn't be able to do that if you don't have privileges.

09:49.730 --> 09:52.010
So we're going to work on that later on.
