2022-01-29, 13:45

Feb 27, 2012 — Notify Users module, ver. 0.5 released — user can choose between sending single message (...) »

2013-01-28, 08:32

19 студзеня 2013 у Гродне трагічна загінуў паэт, журналіст і мой сябар (...) »

2009-10-14, 07:19

The site Litaratura.org is devoted to Belarusian literary works and translations. (...) »

2009-01-12, 20:46

Late November 2008 marked the 20th anniversary of the official founding of the Belarusian (...) »

Registered User Area Log into This Site
Show Credits... Credits
~ / Public Domain Software / Extensions to Ditto / Sorting by Date TV with Formatter $_
Sorting by Date TV with Formatter
Click To View A Full Size Image...
2010-06-04, 03:15

The following small piece of code should serve as a good example for Ditto’s custom sort without altering the core code of the snippet.

The problem was originally formulated in this post on the MODx forum. Documents have template variable of type date attached, moreover, formatter widget was selected for this date TV thus enabling user for convenient insertion of a specific value. However, it significantly complicated using this TV as a sort criterion. Formatter widget transforms Unix timestamp (easy-to-use for sorting purposes) to human-readable textual format.

In order to sort documents by this „malformed date”, we need to convert it back to Unix timestamp:

Code of Ditto’s extender for custom sorting

if (!function_exists('sortByDatePicker')) {
    function sortByDatePicker($a_doc, $b_doc) {
        $a_stamp = strtotime($a_doc['date']);
        $b_stamp = strtotime($b_doc['date']);
        return ($a_stamp < $b_stamp ? -1 : ($a_stamp > $b_stamp ? 1 : 0));

$orderBy['custom'][] = array('date', 'sortByDatePicker');
$ditto->advSort = TRUE;

date in the above code stands for the name of a user-inserted TV of type date. We need to put this code into, for example, sortByDatePicker.extender.inc.php file, move the file to assets/snippets/ditto/extenders folder, and call Ditto with newly-created extender.

Ditto call

[[Ditto? ... &extenders=`sortByDatePicker` ... ]]

Download This Attachment... sortByDatePicker Extender — the very latest version
Last modified: 2010-06-02, 00:00 — Size: 360,00 B