We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22897 ☆ A M B ☆
    • 209 Posts
    I’ve been trying to write a custom filter in order to solve this problem, however the lack of documentation is making it extremely hard to get started.

    I’d like to write up some documentation when I’ve finished and got the code working; until that point can someone explain what’s wrong with the following please?
    <?php
    
    $filters["custom"]["personnelFilter"] = array("PersonnelCompany1,PersonnelCompany2,PersonnelCompany3","personnelFilter"); 
    
    if (!function_exists("personnelFilter")) {
    	function personnelFilter($resource) {
    		global $modx;
    		if ($resource['PersonnelCompany1'] == $modx->documentIdentifier || $resource['PersonnelCompany2'] == $modx->documentIdentifier || $resource['PersonnelCompany3'] == $modx->documentIdentifier) {
    			return 0;
    		} else {
    			return 1;
    		}
    	}
    }
    
    ?>


    PersonnelCompany1,2&3 are custom template variables defined in this document.

    Currently no matter whether I switch return 0 and return 1 around the entire set of results show. I cannot echo any data to screen from the extender for some reason, to see what’s going on, but the Ditto debug console shows the filter as being in place.
      MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
      • 18397
      • 3,250 Posts
      An important thing to note is that $modx->documentIdentifier returns the current documents ID and not the document being filtered by Ditto. Use $resource[’id’] instead.
        • 22897 ☆ A M B ☆
        • 209 Posts
        Quote from: Mark at Jul 24, 2007, 04:59 PM

        An important thing to note is that $modx->documentIdentifier returns the current documents ID and not the document being filtered by Ditto. Use $resource[’id’] instead.

        That’s the correct behaviour for my code - the page calling Ditto is the one I need to compare the values of PersonnelCompany1 etc to.

        I’m finding that my extender isn’t being called at all - nothing I do is producing any output from it (whether I write in a call to mail() or any other function). In the $filters["custom"]["personnelFilter"] entry, what’s the first item in the array do?
          MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
          • 18397
          • 3,250 Posts
          The first item in the array is the source of the filter comma separated.

          Can you copy and paste your snippet call here?

          For other’s reading this thread, here is the example extender’s filter: http://mirror3.cvsdude.com/trac/ditto/codebase/browser/trunk/assets/snippets/ditto/extenders/example.extender.inc.php#L57
            • 22897 ☆ A M B ☆
            • 209 Posts
            Quote from: Mark at Jul 25, 2007, 05:59 PM

            The first item in the array is the source of the filter comma separated.
            Looking at the example filter, there’s no usage of thsi first parameter within the callback function. Does it mean these ’source of the filter’ are the only variables passed into the callback function?

            Can you copy and paste your snippet call here?
            I don’t have the original any longer but it was something like:
            [!Ditto? &parents=`19` &display=`5` &debug=`0` &extenders=`personnel`!]


            where the file name of the extender was personnel.extender.inc.php.
              MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
              • 18397
              • 3,250 Posts
              The filter has access the resource array for that item (includes the fields specified in the first parameter of the the callback). If you want to pass parameters to your function you need to either use global variables or a class.

              However, in a future version of Ditto it will be possible to directly pass a variable to the callback function.
                • 22897 ☆ A M B ☆
                • 209 Posts
                So do you see why this extender should not be executed?
                  MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
                  • 18397
                  • 3,250 Posts
                  From what I can see, you’ve done everything correctly. Try putting echo "test 123"; right after the opening php tag in the extender to see if it is being loaded.
                    • 22897 ☆ A M B ☆
                    • 209 Posts
                    I did that and no, it’s not being loaded. Not sure why, I’ll try and get a test case working.
                      MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
                      • 18397
                      • 3,250 Posts
                      Using the same call, can you successfully load and use other extenders? Also, you might want to give the development version a try.