Okay guys, so we've got this dashboard page, the only page so far in the admin.
And as the dashboard should display something useful.
It should display some kind of an overview of what's happening inside the system.
I think we can just go with displaying the recent posts and the most recent comments.
So maybe in the future we're going to be able to somehow moderate those comments so you can expand the
system further if you wish.
So now let's see a way of how can we get this data.
So we need a way to get the total number of posts.
Well I think we can do that easily.
We've got the count method inside the post model.
If we skip the search we can easily calculate the total posts.
But do we have a way to do the same with comments?
So let's jump to the comment model.
So jumping to comment.
We haven't created the count method, nor we don't really have a based base method in the model class.
So I think we can jump to post now and see if maybe couple of those methods like this get reset method
or the count method.
Maybe we can have a more generic versions of those that can be placed inside the model class, and they
only would have to be extended like we did in post model.
If we have some special requirements like we need to take some search query into the account.
So let's do it.
Let me copy those methods.
They get resent and count, move them to the model or not move them.
Just paste them there.
And let's create a base method that can work with any table.
We are assuming there is no search query in this base.
Base get recent method and I keep saying it is based.
Maybe it is, but I mean base method.
So we don't need the search query.
But we'd like to limit to limit the amount of returned whatever we want to fetch.
Posts comments, whatever.
We also have.
Or we can have some generic pagination.
So I'm going to squeeze this code just so we can see as much as possible.
Or maybe not.
It won't be readable.
So I think it is a good Generic code that really can work with any database table.
It will get the recent.
Models and gives us an option to limit the results or to paginate.
Next up with the count, we can have a base method that doesn't have a search query.
So if there is no parameters, this means we don't have the search query.
But also we don't need this params array and instead we can just pass an empty array here.
And I think this would work fine.
This would be extended in the post model, which I can easily check by going to posts.
Everything still works, so post model just extends those base methods.
But now by adding those to the base model class, we magically have the possibility to get the count
of comments.
This would be total comments and now I can do comment count.
Next up I can get recent posts.
So I'm doing post get recent.
Let's take five.
And same with comments.
This is recent comments and we can do the same with the comment model.
So it's time that we pass this data to the view.
So we've got the total posts which is the total posts variable.
Then we've got the total comments.
That's total comments.
Then we've got recent posts.
And finally we've got the recent comments.
And by having this data we can now jump to the view.
So let me find the view for the dashboard.
And let's display all that data.
Let's jump to admin.
Let me turn this element into an H2 saying maybe an overview like this.
Then let's get a section of the page with an H3 that can say stats.
And first we display the total posts.
Now obviously you can just try and make it more beautiful, but that's just not our focus right now.
So we've got three total posts and then the comments.
So we should have more eight total comments.
That's nice.
And next up let's add another section in this dashboard overview that will be H3.
And we're gonna just list the recent posts.
Let's use an unordered list and a for each loop.
So we're gonna loop over all the recent posts as post column.
Let me finish this off with an end for each.
And I think we can display a link to the post.
And we might actually have two links.
Um, we might have a link to the post itself so we can preview it and another one to edit the post.
Since we don't really have an editor yet.
For now, let it be the post preview.
So this would be post ID and maybe I'm not going to say preview.
Instead I'm going to output HTML special chars post title like this.
I think it's fine and let me copy paste this section to be quicker.
And now let's display some comments.
So with comments we probably don't really have a way to link.
We would have to link to a specific post.
Um, this is recent comments.
Okay, so maybe let's link to the posts from which the comments come from.
And in here let's use the comment content.
The link can be to the comment posted.
This is a column.
We've got a foreign key.
And also the comment can be longer.
That's why I think we should use Substr to just get the fragment of the comment, maybe the first 50
characters, and then let's add three dots at the end.
And now let me fix this one and I think it looks okay.
We can go to the post which had that comment.
We can also work on making a better link.
That would, um, take us directly to a specific comment.
I think this is easily achievable.
We can do it later on.
For now, I think this is enough.
So we were successful in listing only five recent comments and well, we are free to build functionality
that would let us moderate the comments, remove them, change them, do whatever we need for now.
This dashboard is enough.
And next up we're going to build the post managing uh panel.
And then we're going to add the authorization to this system, because currently it's enough to have
an account to be able to do anything with those blog posts.
So we can go to the dashboard and see our stats.
You shouldn't be able to do that if you don't have privileges.
So we're going to work on that later on.