Page List Block to show edited pages
Permalink
I currently have a page list block on our site to show items sorted for most recent first which works well for newly created pages. However, I would like it to show newly edited pages as well so when a pages gets edited it will appear at the top of the page list just like a new created one would.
anyone know if that's possible?
anyone know if that's possible?
Thanks KD what you posted makes some sense to my novice eyes but something isn't working and I don't know what.
I put the hardcode part on my template page and I put the PageActivityList.php into a src folder in my application folder.
and got a "Call to a member function entities() on a non-object" error.
Any ideas what I've done wrong?
I put the hardcode part on my template page and I put the PageActivityList.php into a src folder in my application folder.
and got a "Call to a member function entities() on a non-object" error.
Any ideas what I've done wrong?
@gavthompson
You can change:
To this:
The $th was a text helper $th = Core::make('helper/text');. It isn't necessary here.
You can change:
$title = $th->entities($page->getCollectionName());
To this:
$title = $page->getCollectionName();
The $th was a text helper $th = Core::make('helper/text');. It isn't necessary here.
That's done the trick, thanks!
Just need to try tweak it now, like getting the modified date under the page name and the page description under that, then applying my custom pagelist template hehe.
Do you think this could be made into a block easy enough? instead of hard coding it?
Just need to try tweak it now, like getting the modified date under the page name and the page description under that, then applying my custom pagelist template hehe.
Do you think this could be made into a block easy enough? instead of hard coding it?
@gavthompson
I believe you could fork, or possibly override, the Page List block.
- In controller.php, use PageActivityList instead of PageList.
- Add the sortByDateModifiedDescending() method in the controller.php "order" switch.
- In page_list_form.php, add the new option for the select drop-down.
I believe you could fork, or possibly override, the Page List block.
- In controller.php, use PageActivityList instead of PageList.
// use PageList; use Application\Src\PageActivityList as PageList;
- Add the sortByDateModifiedDescending() method in the controller.php "order" switch.
switch ($this->orderBy) { case 'modified_desc': $this->list->sortByDateModifiedDescending(); break; case 'display_asc': $this->list->sortByDisplayOrder(); break; case 'display_desc': $this->list->sortByDisplayOrderDescending(); break; case 'chrono_asc': $this->list->sortByPublicDate(); break; case 'random': $this->list->sortBy('RAND()');
Viewing 15 lines of 26 lines. View entire code block.
- In page_list_form.php, add the new option for the select drop-down.
<fieldset> <legend><?php echo t('Sort') ?></legend> <div class="form-group"> <select name="orderBy" class="form-control"> <option value="modified_desc" <?php if ($orderBy == 'modified_desc') { ?> selected <?php } ?>> <?php echo t('Modified Descending') ?> </option> <option value="display_asc" <?php if ($orderBy == 'display_asc') { ?> selected <?php } ?>> <?php echo t('Sitemap order') ?> </option> <option value="chrono_desc" <?php if ($orderBy == 'chrono_desc') { ?> selected <?php } ?>> <?php echo t('Most recent first') ?> </option> <option value="chrono_asc" <?php if ($orderBy == 'chrono_asc') { ?> selected <?php } ?>> <?php echo t('Earliest first') ?>
Viewing 15 lines of 28 lines. View entire code block.
Thanks again KD, I'll see if I can give this a go later today.
I've had a pop at this today and it works great as an override!
Only 1 thing left to solve I think!
In the picture I have attached, you can see that the date and time shown is much earlier than it should be.
For instance the SEN Provision part is showing with the date of 11 Jun 2015, 08:55
Can you work just a tiny bit more magic for me and suggest a bit of code that gets the date and time to change to when it was edited apposed to it's initial creation?
Many Many thanks.
Only 1 thing left to solve I think!
In the picture I have attached, you can see that the date and time shown is much earlier than it should be.
For instance the SEN Provision part is showing with the date of 11 Jun 2015, 08:55
Can you work just a tiny bit more magic for me and suggest a bit of code that gets the date and time to change to when it was edited apposed to it's initial creation?
Many Many thanks.
@gavthompson
The Modified Descending sort should be ordering them by when they were last modified not by date added.
Check out my Page Activity add-on. If you change a page, it will show up first when sorting by "Date Modified".
The Modified Descending sort should be ordering them by when they were last modified not by date added.
Check out my Page Activity add-on. If you change a page, it will show up first when sorting by "Date Modified".
Hi KD,
I haven't explain myself well enough let me try again.
The pages are displaying in the order they are being modified in the block (great!) however the date and time being displayed in the block are displaying the date and time created.
Can I display the modified date and time instead of the creation date and time?
I haven't explain myself well enough let me try again.
The pages are displaying in the order they are being modified in the block (great!) however the date and time being displayed in the block are displaying the date and time created.
Can I display the modified date and time instead of the creation date and time?
@gavthompson
You will need to create a Page List block custom template.
- look for this:
- change it to this:
You will need to create a Page List block custom template.
- look for this:
$date = $dh->formatDateTime($page->getCollectionDatePublic(), true);
- change it to this:
$date = $dh->formatDateTime($page->getCollectionDateLastModified(), true);
Thanks KD,
That looks like what I'm after, will test it at work tomorrow.
That looks like what I'm after, will test it at work tomorrow.
Well I have implemented this on our live site and it works exactly how I want it too, thanks for all your help KD.
I personally think this should be implement as standard in c5 because if you have a site like ours (school website) once you have the bulk of the pages made on the site, you tend to amend the pages apposed to recreating them. So having a pagelist option to show the latest modifications is very useful.
How I'll recap what has been done to get the desired result (more for me then anyone really):
Create a PageActivityList.php in application/src with the following code in it;
Create a page_list directory in application/blocks/
In this directory place the page_list blocks controller.php and amend with the following code;
and
in application/blocks/page_list place the page_list blocks page_list_form.php and amend with the following code;
In a custom Page Block template amend view.php as follow:
Find:
Change to:
I personally think this should be implement as standard in c5 because if you have a site like ours (school website) once you have the bulk of the pages made on the site, you tend to amend the pages apposed to recreating them. So having a pagelist option to show the latest modifications is very useful.
How I'll recap what has been done to get the desired result (more for me then anyone really):
Create a PageActivityList.php in application/src with the following code in it;
<?php namespace Application\Src; use Concrete\Core\Page\PageList; class PageActivityList extends PageList { public function sortByDateModifiedAscending() { $this->query->orderBy('cDateModified', 'asc'); } public function sortByDateModifiedDescending() { $this->query->orderBy('cDateModified', 'desc'); } public function sortByDateAddedAscending() {
Viewing 15 lines of 38 lines. View entire code block.
Create a page_list directory in application/blocks/
In this directory place the page_list blocks controller.php and amend with the following code;
// use PageList; use Application\Src\PageActivityList as PageList;
and
switch ($this->orderBy) { case 'modified_desc': $this->list->sortByDateModifiedDescending(); break; case 'display_asc': $this->list->sortByDisplayOrder(); break; case 'display_desc': $this->list->sortByDisplayOrderDescending(); break; case 'chrono_asc': $this->list->sortByPublicDate(); break; case 'random': $this->list->sortBy('RAND()');
Viewing 15 lines of 26 lines. View entire code block.
in application/blocks/page_list place the page_list blocks page_list_form.php and amend with the following code;
<fieldset> <legend><?php echo t('Sort') ?></legend> <div class="form-group"> <select name="orderBy" class="form-control"> <option value="modified_desc" <?php if ($orderBy == 'modified_desc') { ?> selected <?php } ?>> <?php echo t('Modified Descending') ?> </option> <option value="display_asc" <?php if ($orderBy == 'display_asc') { ?> selected <?php } ?>> <?php echo t('Sitemap order') ?> </option> <option value="chrono_desc" <?php if ($orderBy == 'chrono_desc') { ?> selected <?php } ?>> <?php echo t('Most recent first') ?> </option> <option value="chrono_asc" <?php if ($orderBy == 'chrono_asc') { ?> selected <?php } ?>> <?php echo t('Earliest first') ?>
Viewing 15 lines of 28 lines. View entire code block.
In a custom Page Block template amend view.php as follow:
Find:
$date = $dh->formatDateTime($page->getCollectionDatePublic(), true);
Change to:
$date = $dh->formatDateTime($page->getCollectionDateLastModified(), true);
Just an update to the controller code as since I have finally been able to upgrade from 5.7.5.3 to 5.7.5.6 (PHP issue on webserver) I encounter an error with the controller.
I'm guessing it has something to do with the upgrade requiring more strict coding, anyways:
On the controller.php replace;
With
I'm guessing it has something to do with the upgrade requiring more strict coding, anyways:
On the controller.php replace;
>MetaColumnNames(CollectionAttributeKey::getIndexedSearchTable());
With
>MetaColumnNames(CollectionAttributeKey::getDefaultIndexedSearchTable());
Well this has been working flawlessly in 5.7, I've just upgraded to 5.8.1.0 on a my test server and I get:
I'm guessing some code has changed a long the way to 5.8 any ideas?
Class 'Application\Src\PageActivityList' not found
I'm guessing some code has changed a long the way to 5.8 any ideas?
Well this has been working flawlessly in 5.7, I've just upgraded to 5.8.1.0 on a my test server and I get:
I'm guessing some code has changed a long the way to 5.8 any ideas?
Class 'Application\Src\PageActivityList' not found
I'm guessing some code has changed a long the way to 5.8 any ideas?
@gavthompson
Class autoloading has changed in v8.
You will need to create a custom autoloader or enable the enable_legacy_src_namespace config setting.
https://documentation.concrete5.org/developers/extending-concrete5-w...
Class autoloading has changed in v8.
You will need to create a custom autoloader or enable the enable_legacy_src_namespace config setting.
https://documentation.concrete5.org/developers/extending-concrete5-w...
Think I'll try the compatibility option in the short term.
Thanks again KD.
Thanks again KD.
I did something similar to make the Page Activity add-on.
http://www.concrete5.org/marketplace/addons/mrkdilkington-page-acti...
I extended the PageList class and added a new method sortByDateModifiedDescending().
I think you can override or extend the PageList class and use that to create the page list.
Here is a quick example using the extended PageActivityList class:
- application\src\PageActivityList.php
http://documentation.concrete5.org/developers/working-with-pages/se...