We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6726
    • 7,075 Posts
    Here is what I need to do : I need to be able to sort items by pub_date if the publication date is defined, and if no pub_date is defined, I need Ditto to fall back to createdon.

    Is this doable and if so, how would you go about it ?

    Thanks !

      .: COO - Commerce Guys - Community Driven Innovation :.


      MODx est l'outil id
      • 33114
      • 518 Posts
      I wonder if it can be done with Ditto too... For now to be able to modify sortable date I made a hack, that adds an option to edit createdon date. Then I could sort docs by createdon only and can actually modify those dates.

      Before this I was thinking about something like yours, davidm. And I guess Ditto can’t sort by multiple parmeters... at least for now.
      In some cases u could maka date TV that if not defined, equals to createdon.
        http://modx.ru - российская поддержка MODx
        http://newscup.ru - экспериментальный проект
        http://yentsun.com - персональный сайт
        • 18397
        • 3,250 Posts
        This should be the native behavior of Ditto. Just set &sortBy=`pub_date` and Ditto should take care of the rest.

        @yetsun: Ditto version 2.1b3 actually supports basic multisort similar to MySQL using the &sort parameter.
          • 6726
          • 7,075 Posts
          That’s great Mark, you mean if there is not pub_date, it will fallback to createdon ?

          Cool cool
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l'outil id
            • 18397
            • 3,250 Posts
            Yes.
              • 7231
              • 4,205 Posts
              This should be the native behavior of Ditto. Just set &sortBy=`pub_date` and Ditto should take care of the rest.
              Ditto rocks!
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don't know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 36592
                • 970 Posts
                Hi! Mark.
                Quote from: Mark at Jan 18, 2008, 01:04 AM

                This should be the native behavior of Ditto. Just set &sortBy=`pub_date` and Ditto should take care of the rest.
                But Reflect doesn’t... :’(
                  • 18397
                  • 3,250 Posts
                  Reflect should as well since it uses Ditto as the data source.
                    • 36592
                    • 970 Posts
                    Quote from: Mark at Jan 18, 2008, 09:05 PM

                    Reflect should as well since it uses Ditto as the data source.
                    I don’t think so... Actually when I set &dateSource=`pub_date` in Reflect option, the document with its pub_date blank goes to Unixtime ’Zero’ ( Jan, 1970). ’createdon’ is not used as substitution.... So I made a modification in Reflect Snippet.
                    function reflect($templatesDocumentID, $showItems, $groupByYears, $resource, $templatesDateSource, $dateFormat, $ditto, $templates,$id,$start,$yearSortDir,$monthSortDir) {
                    	global $modx;
                    	$cal = array();
                    	$output = '';
                    	$ph = array('year'=>'','month'=>'','item'=>'','out'=>'');
                    	$build = array();
                    	$stop = count($resource);
                    
                    	// loop and fetch all the results
                    	for ($i = $start; $i < $stop; $i++) {
                    		// $date = getdate($resource[$i][$templatesDateSource]);
                                    $date = ($resource[$i][$templatesDateSource] != "0") ? getdate($resource[$i][$templatesDateSource]) : getdate($resource[$i]["createdon"]);  // <- I changed here.
                    		$year = $date["year"];
                    		$month = $date["mon"];
                    		$cal[$year][$month][] = $resource[$i];
                    	}
                    

                    Is this a bad usage of Reflect ?
                      • 18397
                      • 3,250 Posts
                      Ditto, which retrieves the data for Reflect, substitutes the createdon date when the pub_date value is 0. Thus, $resource[$i][$templatesDateSource] should contain the desired date if &dateSource is set to pub_date.