We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15066
    • 27 Posts
    Hello!

    SOLVED smiley

    Thank you very very very much smiley
    I would buy you a beer if i could order by modx wink

    Have a nice day, Jure
      • 15066
      • 27 Posts
      Hello!

      I have a problem again... because i had too many documents in parent, i didn’t see, that one document isn’t echoed out...
      If there is only one document unpublished for today, i get - No documents.

      Here is code, if you could check it out please...

      <?php
      $parent = isset($parent) ? $parent : "67";
      $default = isset($default) ? $default : "1";
      
      $table = $modx->getFullTableName("site_content");
      $fields = "id";
      $where = "(FROM_UNIXTIME( unpub_date, '%Y-%m-%d' ) = CURDATE( )) AND (parent = ".$parent.") AND (published = '1')";
      $rs = $modx->db->select("id",$table,$where,"unpub_date ASC","30");
      if($modx->db->getRecordCount($rs) >= 1) {
      	$row = $modx->db->getRow($rs);
      	while( $row = $modx->db->getRow( $rs ) ) {
      		$today_doc .= $row['id'].",";
      		}
      	$today_doc = substr($today_doc, 0, -1);
      } else {
      	$today_doc = $default;
      } 
      
      $output = $modx->runSnippet("Ditto_dogodki", array(
      	"documents" => $today_doc,
      	"display" => "all",
      	"tpl" => "ditto-prva" ));
      
      return $output;
      ?>


      Thank you for your help, Jure
        • 7231
        • 4,205 Posts
        There is an unneeded instance of $row = $modx->db->getRow($rs); that is offsetting the count (my fault I had it in the original example). I labeled if in the code bellow. Should work now
        <?php
        $parent = isset($parent) ? $parent : "67";
        $default = isset($default) ? $default : "1";
        
        $table = $modx->getFullTableName("site_content");
        $fields = "id";
        $where = "(FROM_UNIXTIME( unpub_date, '%Y-%m-%d' ) = CURDATE( )) AND (parent = ".$parent.") AND (published = '1')";
        $rs = $modx->db->select("id",$table,$where,"unpub_date ASC","30");
        if($modx->db->getRecordCount($rs) >= 1) {
        	// $row = $modx->db->getRow($rs); <- THIS IS NOT NEEDED!
        	while( $row = $modx->db->getRow( $rs ) ) {
        		$today_doc .= $row['id'].",";
        		}
        	$today_doc = substr($today_doc, 0, -1);
        } else {
        	$today_doc = $default;
        } 
        
        $output = $modx->runSnippet("Ditto_dogodki", array(
        	"documents" => $today_doc,
        	"display" => "all",
        	"tpl" => "ditto-prva" ));
        
        return $output;
        ?>
          [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&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 15066
          • 27 Posts
          Hello!

          I was on break wink

          It’s working smiley))

          Thank you very much!

          bye
            • 15066
            • 27 Posts
            Hello again smiley

            Documents are now all printed out, but not in right order - if i have documents that will end at 9 am, 10 am and 11 am I get this order 11 am, 10 am and 9 am...
            I tried to change ASC to DESC... same... I tried to change mysql, but i don’t understand modx code sad

            How would i now get all other documents except documents that will expire today? - Can i order them by day in week?

            Thank you for your help! Jure
              • 7231
              • 4,205 Posts
              I think we might need to add sort information to the ditto call, I don’t recall if Ditto has a default sort method the default seems to be createdon, so you will need to set the sortBy and sortDir in the Ditto call.
              $output = $modx->runSnippet("Ditto_dogodki", array(
              	"documents" => $today_doc,
              	"display" => "all",
              	"sortBy" => "unpub_date",
              	"sortDir" => "ASC",
              	"tpl" => "ditto-prva" ));
                [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&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 15066
                • 27 Posts
                Hi again!

                It worked ... of course smiley

                But, how can i now get opposite of this result - so visitor could look at all other documents - except for those seen at home page? ... Could they be ordered by day in week, because it’s so mixed up if there are more documents (50 or so...)

                Thank you for your help!

                Jure
                  • 7231
                  • 4,205 Posts
                  Use the document list from the query and use it in a filter in the ditto call to exclude those documents. There is a filtering tutorial in the Ditto site:
                  http://ditto.modxcms.com/tutorials/basic_filtering.html
                    [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&#39;t know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 15066
                    • 27 Posts
                    Hi...

                    How can i add date as a criterion in filter? ... &filter=`unpub_date,today_date,2`

                    I’ve tried with TV’s... didn’t work.

                    Thank you for your help, Jure
                      • 7231
                      • 4,205 Posts
                      You need to use the @EVAL binding in the filter for this but I don’t know off the top of my head how to bet the dates in the correct format and can’t stop to figure it out at the moment.

                      Another idea would be to run the query from the first part and then count the results and use the number as the offset in Ditto using the &start parameter:
                      http://ditto.modxcms.com/files/snippet-ditto-php.html#start
                        [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&#39;t know what it is.
                        Do you, Mr. Jones? - [bob dylan]