We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33114
    • 518 Posts
    Here’s a contribution from russian community: a brand new doc management api class.

    Author: ur001

    Area of use: guestbooks, blogs, forums, frontend manager modules

    Example of use:
    require_once(’assets/libs/docapi/docmanager.class.inc.php’);
    $doc = new Document();
    $doc->Set(’parent’,$folder);
    $doc->Set(’alias’,’post’.rand());
    $doc->Set(’content’,’Document text’);
    $doc->Set(’template’,’GuestBookComments’);
    $doc->Save();

    Hope u people find it useful
      http://modx.ru - российская поддержка MODx
      http://newscup.ru - экспериментальный проект
      http://yentsun.com - персональный сайт
      • 15914
      • 145 Posts
      This is fantastic! It works a treat. Kudos ur001! I wonder if the same can be done with Web Users and have a nice API to manage them too?
        Kunal Kapoor
        Technical Director
        Limesharp Internet Limited - Effective, Functional, Standards Compliant

        IRC Nick: KingKoopa
        Skype ID: KingKoopa16
        • 22303 MODX Staff
        • 10,725 Posts
        Very cool yentsun, thanks for sharing this, and happy belated birthday (meant to post yesterday)!

        And yes the same can be done with Web Users; in fact, there will be an official release of a complete object-oriented API (similar to this) for all of MODx 0.9.x. It is being built on top of the new xPDO project I am working on, and will serve as both an alternative API for use with your existing MODx, and as a preview of what 1.0 will be utilizing to take the MODx framework to the next level.
          • 15914
          • 145 Posts
          *Droools!*

          Sounds great. I’d love to be able to manipulate users from a snippet or two. It’ll make integrating with other open source project a lot easier!
            Kunal Kapoor
            Technical Director
            Limesharp Internet Limited - Effective, Functional, Standards Compliant

            IRC Nick: KingKoopa
            Skype ID: KingKoopa16
            • 21647
            • 9 Posts
            Hi all, admittedly, I am very new to modx, but I have been around various cms’s for a long time, mainly xoops, but having stumbled across modx, I really am impressed, and I am trying hard to get up to speed. From what I see, modx solves all the issues I have had with other cms’s, and then some..
            I have a current project I want to use modx for, but I am stumbling around trying to get my head around how I can use these doc api’s, to solve a particular problem. I hope someone can give me a bit of a handhold to just get me started.
            My problem:
            I need to create a webside form to create a new document that will reside in an existing folder "Gigs" in similar fashion to "Add a blog entry".
            Each gig needs the usual document stuff, but additionally a few custom tv’s. e.g. gigvenue, gigdate, gigtickets, and gigimage.
            Lets keep this simple, and just say I want to create a webside form "Add a Gig", with one template variable "gigVenue", in addition to the fields that say, the example "Add a Blog entry" form provides.
            I know this is a big ask, but using ur001 or Jason’s api, how would I go about this? .
            I can get as far as creating the tv, linking it to the template, but a simple example, of the snippet, and usage of api class would go a long way to helping me along.
            If anyone has a few minutes to share an example, that would be *SO* appreciated.
            Thanks guys!
            Neil.

            Anyone? A simple example is all I need to get me going.
              • 31113
              • 45 Posts
              Sample1 (creating document):
              <?php
              require_once('assets/libs/docapi/document.class.inc.php');
              $doc = new Document();
              $doc->Set('parent',$folder);
              $doc->Set('alias','post'.time());
              $doc->Set('content','document content');
              $doc->Set('template','GuestBookComments');
              $doc->Set('tvComment','post to comment');
              $doc->Save();
              php?>
              


              Sample2 (editing document):
              <?php
              require_once('assets/libs/docapi/document.class.inc.php');
              $doc = new Document($id,'content');
              $content=$doc->Get('content');
              $doc->Set('content', '<p>'.$content.'</p>');
              $doc->Save();
              php?>
              


              Sample3 (frontend document editing, deleting):
              <?php
              require_once('assets/libs/docapi/document.class.inc.php');
              
              $id=$_POST['doc_id'];
              $delete=$_POST['delete'];
              $title=$_POST['title'];
              $content=$_POST['content'];
              
              $doc = new Document($id,'content,longtitle');
              if($delete) 
                $doc->Delete();
              else {
                $doc->Set('longtitle',$title);
                $doc->Set('content',$content);
                $doc->Save();
              }
              php?>
              
                • 33114
                • 518 Posts
                Quote from: OpenGeek at Jul 23, 2006, 03:18 PM

                Very cool yentsun, thanks for sharing this, and happy belated birthday (meant to post yesterday)!

                thanks Jason:)

                and let all the thanks for thit class go to ur001 as well:)
                  http://modx.ru - российская поддержка MODx
                  http://newscup.ru - экспериментальный проект
                  http://yentsun.com - персональный сайт
                  • 21647
                  • 9 Posts
                  Thanks for these replies, but I don’t think I am making it clear what I just can’t get a handle on...
                  You have kindly provided some example of the code used to invoke the class, and use its methods, but there is no context? Do I put this in a snippet? Do I have to create a chunk with a form on to post to the page and have the snippet use postvars?
                  Do I have to create a plugin? or a module.
                  Like I said, I am new to modx, and I can see that this api will do what I need to do, but there is no context on HOW to actually use this in practice? I know I am missing something?
                  Thanks for any pointers.
                  Neil.
                    • 31113
                    • 45 Posts
                    nmac:

                    you need:
                    1) Chunk with form template, i.e. "AddBlogEntryForm" - html form with placeholders instead values ([+content+], [+tvigvenue+], etc)
                    2) TVs for blog record (igvenue, gigdate, gigtickets, and gigimage)
                    3) Snipet (AddBlog)

                    How to write snippet:

                    1) include docmanager.class.inc.php (copy this file to assets/libs/docapi/)
                    <?php
                    require_once('assets/libs/docapi/docmanager.class.inc.php');
                    php?>

                    2) Check to form is posted, i.e.:
                    <?php
                    $submited=isset($_POST['submit']);
                    php?>

                    3) if(!$submited) - show the AddBlogEntryForm:
                    <?php
                    return $modx->getChunk('AddBlogEntryForm');
                    php?>

                    4) else - you need to create new document (if all fields filled correctly):
                    <?php
                    $doc = new Document();
                    $doc->Set('parent',$GigsID);
                    $doc->Set('content',$_POST['content']);
                    $doc->Set('tvgigdate',$_POST['tvgigdate']);
                    ...
                    $doc->Save();
                    php?>


                    You also can use (don’t forget exclude $_POST[’submit’] and other, my class don’t check for document field existing)
                    <?php
                    foreach($_POST as $name=>$value) $doc->Set($name=>$value);
                    php?>


                    Sorry for my english

                    P.S. cut "<php" tags, it’s for syntax highlighting
                      • 21647
                      • 9 Posts
                      Отлично! Thanks ur0001! That was all I needed. In fact, I poked around today, and hacked the newspublisher, replacing the db insert with your api, and finally made some progress. Context was all i needed and your post really helped. Thanks again!
                      Neil.
                      PS: really appreciate your english! Way better than my russian! Отлично!