We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30884
    • 142 Posts
    Hi there,

    I’ve tied in a couple of add gallery options into the code of news publisher snippet
    $content_and_gallery=’[Maxigallery?etc, etc, etc]<BR>’;
    $content=$content.$content_and_gallery;

    which lets me manage the gallery post article publishing but I would love to integrate the gallery into the newspublisher entry chunk page. To do this successfully I need to get the id of the page that ’will’ be generated. Anyone done this or know how to?

    cheers!
    TXRX

      p i x e l p u s h e r e x t r o d i n a i r e
      A x i s A n i m a t i o n . c o m
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That would be a neat trick, since the document’s ID is automatically generated by the database when the document is saved. I suppose you could force the creation of an empty document, then just open it for editing.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 7455
        • 2,204 Posts
        you could look at the doc id’s and get the latest one and add 1 to it.
          follow me on twitter: @dimmy01
          • 1511
          • 144 Posts
          Quote from: Dimmy at Apr 13, 2007, 08:38 AM

          you could look at the doc id’s and get the latest one and add 1 to it.

          Not good if you create a document, delete it (and remove from the db table) and then create a new one.
          The first ID is "used", since the auto increment index in the table is increased.
          The "+1" method would fail.

          First, create a new document, set it "not visible in menu", set it "unpublished", and insert it into the database.
          Second, get ID of last created document (function $MODx->db->getInsertId or the result of function $MODx->db->insert) and edit the content, then save it and publish it.
          Just like Susan said.

          Basically, you create a new document in two steps, but the user knows and cares nothing about this. smiley
            • 30884
            • 142 Posts
            That indeed sounds like it would work quite well. I’d have to make sure that there was some redundancy when articles weren’t completed/aborted but aside from that this sounds like a capital idea. I’ve just been playing about with 7-bit’s Newspublisher revision that includes tags so I’ve been busy on that today, I’ll turn my focus on implementing the suggestions after I’m wrapped up on the TV’s through NewsPublisher. (Just gotta figure out how to use text entry as opposed to checkboxes for TV tags etc.)

            Edit: I discovered this across my travels in the ModX forums and it’s what I’ve implemented into the NewsPublisher system here. Works quite well out of the box for me. Tho I don’t know one word of Japanese!
            http://nanabit.net/modx/modx-newspublishertagging.html

            Then I’ll no doubt be harrassing all and sundry on the Modx forums with my lack of ModX know how when I get round to this revision on newspublishers behaviour.
            ;)

            Cheers!
            TXRX
              p i x e l p u s h e r e x t r o d i n a i r e
              A x i s A n i m a t i o n . c o m
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I once got the NewsEditor to be able to edit the TVs for a new document, borrowing the code from the mutate_content action file in the manager/actions folder and the save_content processor file, but I was never able to figure out how to get an existing document’s TVs’ values to display for editing an existing document. The variables have to be shifted around since it’s not actually in the Manager. So it is doable, just takes a bit more persistence (or a better understanding of how TVs are accessed!) at the latter feature than I put into it.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 7455
                • 2,204 Posts
                Quote from: andrazk at Apr 13, 2007, 09:04 AM

                Quote from: Dimmy at Apr 13, 2007, 08:38 AM

                you could look at the doc id’s and get the latest one and add 1 to it.

                Not good if you create a document, delete it (and remove from the db table) and then create a new one.
                The first ID is "used", since the auto increment index in the table is increased.
                The "+1" method would fail.

                First, create a new document, set it "not visible in menu", set it "unpublished", and insert it into the database.
                Second, get ID of last created document (function $MODx->db->getInsertId or the result of function $MODx->db->insert) and edit the content, then save it and publish it.
                Just like Susan said.

                Basically, you create a new document in two steps, but the user knows and cares nothing about this. smiley


                you can also ask mysql the next id number i know that there is an option to do that. somthing like this I think:

                $SQL = "SHOW
                            TABLE STATUS
                        FROM
                            databaseName
                        LIKE
                            'tableName'";
                
                $result = mysql_query($SQL);
                $row = mysql_fetch_assoc($result);
                $nextInsertId = $row['Auto_increment'];
                


                hope this helps, would save some database time and programing time I think
                  follow me on twitter: @dimmy01
                  • 1511
                  • 144 Posts
                  Of course, that is an option. Thank you for the tutorial, I’ve learned something new.

                  But to be on the safe side, consider this: you get the next ID from the table "auto increment" property in advance, you prepare the content for the new document (it might take I while, I don’t know) and yet_to_be_your_id AND in the meantime another user adds a document.
                  And just like that, your ID is gone. smiley

                  But of course, it depends on te site usage, database traffic, time to prepare the content... but stilll. wink
                    • 7455
                    • 2,204 Posts
                    just get the nextinsertID just befor you write the whole lot to the db I think that it will be fast. but yes maybe there is a slim chance that this goes wrong you could alway do an extra chenk after posting if newID is the same as the nextinsertID you just got 2milisecents before. if not give an error or try again with a new id.

                      follow me on twitter: @dimmy01
                      • 30884
                      • 142 Posts
                      Hi there,

                      Thanks for your help on this on folks! I managed to insert the following code into the ’top’ of the newspublishertags snippet and I’m now getting an accurate prediction of the new articles expected id. Most helpful!
                      
                      $New_id_SQL = "SHOW TABLE STATUS FROM modx LIKE 'modx_site_content'";
                      $result = mysql_query($New_id_SQL);
                      $row = mysql_fetch_assoc($result);
                      $Next_Insert_Id = $row['Auto_increment'];
                      
                      


                      Please note I’ve hard coded the table and database names to match our MySQL databases. You’ll need to implement the ModX solver or change them to match your MySQL tables.

                      Superb!
                        p i x e l p u s h e r e x t r o d i n a i r e
                        A x i s A n i m a t i o n . c o m