We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8880
    • 29 Posts
    Applying Document Groups to new Documents

    I added some Code to ’fdm.db.class.inc.php’ which I got from the ’NewsPublisher’ Snippet.
    With it the newly created Pages inherit their parents’ Document Groups.

    Can anyone validate that this is actually happening smiley and maybe if the code is ok that way?

    Here’s the code, I changed in fdm.db.class.inc.php:

    [...]
    	/***************************************************
    	  Saving/Updating FdmDocument (escape fields added)
    	****************************************************/
    	function Save(){ //escape added
    		global $modx;
    		$this->fields['editedon']=time();
    		$tablename=$modx->getFullTableName('site_content');
    	  	$escapedFields = array_map(create_function('$n', 'global $modx;if (get_magic_quotes_gpc()) { $n = stripslashes($n);	}return $modx->db->escape($n);'), $this->fields);
    		if($this->isNew){
    			$this->fields['id']=$modx->db->insert($escapedFields, $tablename);
    			$this->isNew = false;
    		} else {
    			$id=$this->fields['id'];
    			$modx->db->update($escapedFields, $tablename, "id=$id");
    		}
    		unset($escapedFields);// free the array
    		//
    		// ###########################
    		//	a little hack from end if
    		// ###########################
    		//	Add the documents parent Document Groups to the document
    		//
    		$folder = $this->fields['parent'];
    		//
    		//	got the following code from Newseditor 1.4
    		//
    		// Doc group thing
    		// look in save_content.processor.php for tips (or below)
    		$lastInsertId = $modx->db->getInsertId();
    
    		// Get doc groups based on $folder (parent id)
    		$parentDocGroupsSql = "SELECT * FROM " . $modx->getFullTableName('document_groups'). " where document=".$folder;
    		$parentDocGroupsRs = $modx->db->query($parentDocGroupsSql);
    		$parentDocGroupsLimit = $modx->db->getRecordCount($parentDocGroupsRs);
    		for ($pdgi = 0; $pdgi < $parentDocGroupsLimit; $pdgi++) { 
    			$currentDocGroup = $modx->db->getRow($parentDocGroupsRs);
    			$parentDocGroupsArray[$pdgi] = $currentDocGroup['document_group'];
    		}
    
    		// put the document in the document_groups it should be in
    		// check that up_perms are switched on!
    		if($modx->config['use_udperms']==1) {
    			if(is_array($parentDocGroupsArray)) {
    				foreach ($parentDocGroupsArray as $dgKey=>$dgValue) {
    					$insertDocSql = "INSERT INTO ".$modx->getFullTableName('document_groups')."(document_group, document) values(".stripslashes($dgValue).", $lastInsertId)";
    					$insertDocRs = $modx->db->query($insertDocSql);
    					if(!$insertDocRs){
    						exit;
    					}
    				} // end foreach
    			} // end if doc group array exists
    		} // end if perms are used
    		//
    		// Handle privateweb
    		$modx->db->query("UPDATE ".$modx->getFullTableName("site_content")." SET privateweb = 0 WHERE id='$lastInsertId';");
    		$privatewebSql =    "
    			SELECT DISTINCT ".$modx->getFullTableName('document_groups').".document_group 
    			FROM ".$modx->getFullTableName('document_groups').", ".$modx->getFullTableName('webgroup_access')." 
    			WHERE 
    			".$modx->getFullTableName('document_groups').".document_group = ".$modx->getFullTableName('webgroup_access').".documentgroup 
    			AND 
    			".$modx->getFullTableName('document_groups').".document = $lastInsertId;";
    			$privatewebIds = $modx->db->getColumn("document_group",$privatewebSql);
    			if(count($privatewebIds)>0) {
    				$modx->db->query("UPDATE ".$modx->getFullTableName("site_content")." SET privateweb = 1 WHERE id = $lastInsertId;");    
    			}
    		
    			// And privatemgr
    			$modx->db->query("UPDATE ".$modx->getFullTableName("site_content")." SET privatemgr = 0 WHERE id='$lastInsertId';");
    			$privatemgrSql =    "
    				SELECT DISTINCT ".$modx->getFullTableName('document_groups').".document_group 
    				FROM ".$modx->getFullTableName('document_groups').", ".$modx->getFullTableName('membergroup_access')." 
    				WHERE 
    				".$modx->getFullTableName('document_groups').".document_group = ".$modx->getFullTableName('membergroup_access')." .documentgroup 
    				AND 
    				".$modx->getFullTableName('document_groups').".document = $lastInsertId;";
    				$privatemgrIds = $modx->db->getColumn("document_group",$privatemgrSql);
    				if(count($privatemgrIds)>0) {
    					$modx->db->query("UPDATE ".$modx->getFullTableName("site_content")." SET privatemgr = 1 WHERE id = $lastInsertId;");    
    				}
    		// end of document_groups stuff!
    		//
    		// ###########################
    		//  / hack
    		// ###########################
    		//
    		if(is_array($this->tvs)) $this->saveTVs();
    	}
    
    	/************************************************************
    	  Saving TV values, maintenance function. Only $tvNames values are saved,
            If a TV exists in oldTVs, then updating, else inserting
    	*************************************************************/
    [...]
    


    Cheers,
    Sascha
      • 21361
      • 3 Posts
      Hi, I’ve managed to get the doc manager up and running, but I need to just post new documents to a particular parent. Is there a way of doing this?
      Thanks
        • 11975
        • 2,542 Posts
        Hi,

        the simplest way is to add an hidden input with name="parent" and value="Id to put childs"

        :-)
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 29720
          • 1 Posts
          Is there a new guide for using this with Maxigallery to make a product catalogue? This fits the needs for a project I am working on, but without knowing where the old Wiki page is outdated its hard to get a good starting point.
            • 18862
            • 70 Posts
            Anyone else run into an issue of not being able to supply any parameters?

            It works fine if I just use [!FDM!] for the call, but if I try to add any parameters such as [!FDM &debug=`all`!] there is no output. I check the page that it renders and it is as though my call isn’t even there.

            Thoughts?

            Thanks! smiley
              • 6726
              • 7,075 Posts
              Strange... never encountered this issue... could you post the snippet call please ?
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id
                • 25547
                • 61 Posts
                Quote from: mbrinson at May 02, 2008, 06:48 PM

                Anyone else run into an issue of not being able to supply any parameters?

                It works fine if I just use [!FDM!] for the call, but if I try to add any parameters such as [!FDM &debug=`all`!] there is no output. I check the page that it renders and it is as though my call isn’t even there.

                Thoughts?

                Thanks! smiley

                What about the ?

                you wrote [!FDM &debug=`all`!]
                but ut should be [!FDM? &debug=`all`!]
                  • 18862
                  • 70 Posts
                  Thanks Ross!! smiley

                  Doh! rolleyes
                    • 18862
                    • 70 Posts
                    Can anyone give an example of what the parameter "aliastype" would be used for?

                      • 6726
                      • 7,075 Posts
                      &aliastype allow you to control how the alias is generated when a web user creates a document with FDM, in fact a higher control than the manager can give. With this parameter you can set the way you want alias to be set upon document save.

                      You can set it with the date and title for example using [tt]&aliastype=`%b%-%d%-%y%-%pagetitle%`[/tt] will give you something for today like http://www.mysite.com/05-04-08-mydocumentitle.html

                      Of course there are lots of combination you can come up with, check FDM’s documentation for more info smiley

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


                        MODx est l&#39;outil id