We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8694
    • 61 Posts
    I got the same problem.
    I want call dokuments with getResources from all contexts.
    The site_url etc. is set.

    The option "&context=`all`" did not work with getResource.

    What is the final solution? Do I have to hack getResource?
    • Quote from: elgato at Jul 30, 2010, 07:13 AM

      The option "&context=`all`" did not work with getResource.

      What is the final solution? Do I have to hack getResource?
      There will be a new release out today with some features that may address your issue.
        • 26575
        • 57 Posts
        In my case I edited the code of getResource to fit my needs.
        For getting the resources of all contexts i deleted this line:
        ,"(`modResource`.`context_key` != {$context} OR EXISTS(SELECT 1 FROM {$contextResourceTbl} `ctx`
          christian seel - www.christianseel.com
          web developer & designer at chsmedien.de
          twitter: @christianseel / @chsmedien
        • The new release from Friday should support your needs without modification. Let us know.
            • 26575
            • 57 Posts
            hey jason, yes it does!

            I had an error for both of my contexts ("de" and "en") after updating getResources:
            [2010-08-07 14:57:37] (ERROR @ /kunden/99742_65929/transkriptionen_net/core/model/modx/modtemplatevar.class.php : 422) PHP warning: DirectoryIterator::__construct(/kunden/99742_65929/transkriptionen_net/core/model/modx/processors/element/tv/renders/de/output/) [<a href=’directoryiterator.--construct’>directoryiterator.--construct</a>]: failed to open dir: No such file or directory
            solution: after I added the folder "/de/output/" and "/en/output/" getResources works!

            another question to the snippet: is it possible to have an universial parents parameter? (to get the resources of "all" parents)
            Setting parents to 0 doesnt work for documents which are in a container...


            here is my "changelanguage"-snippet, maybe you have some hints:
            <?php
            /**
             * changelanguage
             *
             * snippet for change-language-links between contexts
             *
             * @version beta - 07.08.2010
             */
             
            // default properties
            //$current_lang = $modx->getOption('current_lang',$scriptProperties,'');
            $field = 'internationalkey';
            $current_internationalkey = $modx->resource->getTVValue($field);
            $current_context = $modx->context->get('key');
            
            /*
             * generate array ($contextlist) with all contextkeys that are public (site_status)
             */
            $contexts = $modx->getCollectionGraph('modContext', '{"ContextSettings":{}}', array(
                'modContext.key:!=' => 'mgr'
                ,'ContextSettings.key' => 'site_status'
            ));
            
            $contextlist = array();
            foreach ($contexts as $context) {
                $data = $context->toArray();
                if (!empty($context->ContextSettings)) {
                    //$siteStart = reset($context->ContextSettings);
                    //$data = array_merge($data, array('site_start' => $siteStart->get('value')));
                    $siteStatus = reset($context->ContextSettings);
                    $data = array_merge($data, array('site_status' => $siteStatus->get('value')));
                }
                if($data['site_status'] != 0) {
                	$contextlist[] = $data['key'];
                }
            }
            
            // sort contextkeys
            sort($contextlist);
            
            
            /*
             * check if there is a resource in every context whith the same "internationalkey" (tv)
             * as the current resource. if not, generate for the resource a link to site_start-
             */
            $output = array();
            foreach ($contextlist as $thiscontext) {
            
            	$keyoutput= $modx->runSnippet('getResources',array(
            		'context' => $thiscontext,
            		'tvFilters' => $field.'=='.$current_internationalkey,
            		'tpl' => 'selectlang',
            		'parents' => '0,2,11'
            	));
            	
            	if ($keyoutput != '') { // if resource with same key was found, add to output
            		$output[] = $keyoutput;
            		
            	} else { // if no resource with same key was found, generate link to the homepage of the context
            		$contextsb = $modx->getCollectionGraph('modContext', '{"ContextSettings":{}}', array(
            		    'modContext.key' => $thiscontext
            		    ,'ContextSettings.key' => 'site_start'
            		));
            		foreach ($contextsb as $contextb) {
            		    $datab = $contextb->toArray();
            		    if (!empty($contextb->ContextSettings)) {
            		        $siteStartb = reset($contextb->ContextSettings);
            		        $datab = array_merge($datab, array('site_start' => $siteStartb->get('value')));
            		    }
            		   $idoutput = $modx->getChunk('selectlang_id', $datab);
            		}
            		$output[] = $idoutput;
            	}//end of if
            }//end of foreach
            
            return implode("\n", $output);
            //return htmlspecialchars(implode("\n", $output));
            ?>
              christian seel - www.christianseel.com
              web developer & designer at chsmedien.de
              twitter: @christianseel / @chsmedien