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

    Using evo 1.02, on a windows xp machine running wamp with php 5.3.0 and mysql 5.1.36.


    I want to use a combination of two tv’s to override the db entries of the doc_groups table. This because I want to use the new ajaxSearch function to filter on TV’s. I wrote the following plugin:

    global $modx;
    
    $table_docgroup = $modx->getFullTableName("document_groups");
    $table_groupname = $modx->getFullTableName("documentgroup_names");
    $tvpubliek = $modx->getTemplateVarOutput("publiek", "61", "1"); //get publiek
    
    $publiek = $tvpubliek[publiek];
    //if value != public we need a value in db
    if($publiek != "Publiek") {
    $tvgroup = $modx->getTemplateVarOutput("documentcategorie", "61", "1"); //get value of documentcategorie
    $groupname = $tvgroup[documentcategorie]; //get the value out of the array
    $groupid=$modx->db->getValue($modx->db->select("id", $table_groupname, "name= '". $groupname . "'")); //get groupid
    $query = "INSERT INTO " . $table_docgroup . " (document_group, document) VALUES (" . $groupid . ", 61)"; //query to insert new value
    $modx->db->delete($table_docgroup, "document=61"); //first delete all entrys for this id, since it's possible they changed
    $modx->db->query($query); //insert values in db
    }
    else {
    $modx->db->delete($table_docgroup, "document=61"); //first delete all entrys for this id, since it's possible they changed
    }
    


    This works fine, except for the fact that when I replace the 61 value with $modx->documentIdentifier, I get an error which points to an empty value for $modx->documentIdentifier.

    I think this might be because I run the plugin on the OnDocFormSave event. Perhaps there is no docid at that event? Does someone know a way to do it after it was saved? Or did I miss the way to get the id of the document I am saving?

    Thanks in advance,

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The OnDocFormSave event provides the ID of the document it just saved. It provides an array with the mode (new or edit) and the document ID.
      array (
      "mode" => "new",
      "id" => $key
      
        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
        • 15076
        • 43 Posts
        that’s nice:) do you also know the name of the array?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You can just use $id.
            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
            • 15076
            • 43 Posts
            thank you very much! with $id it works nicely:)