private function setTarget(SimpleXMLElement $element)
    {
        $target = $element->addChild('target');
        switch ($this->nb_data_object->getUseURI()) {
            case 'T':
                if (($nb_site = $this->nb_data_object->getSite()) instanceof CNabuSite &&
                    ($nb_site_target = $nb_site->getTarget($this->nb_data_object->getSiteTargetId())) instanceof CNabuSiteTarget
                ) {
                    $target->addAttribute('useURI', 'T');
                    $target->addAttribute('target', $nb_site_target->getHash());
                } else {
                    error_log("Target not exists");
                }
                break;
            case 'U':
                $translations = $this->nb_data_object->getTranslations();
                $urls = array();
                $translations->iterate(function ($lang, $nb_translation) use (&$urls) {
                    $urls[$lang] = array(
                        'url' => $nb_translation->getURL(),
                        'match' => $nb_translation->getMatchURLFragment()
                    );
                    return true;
                });
                if (count($urls) > 0) {
                    $target->addAttribute('useURI', 'U');
                    foreach ($urls as $lang => $url) {
                        if (strlen($url) > 0) {
                            $nb_language = $this->nb_data_object->getLanguage($lang);
                            $address = $target->addChild('url');
                            $address->addAttribute('lang', $nb_language->getHash());
                            $address->addAttribute('url', $url['url']);
                            $address->addAttribute('match', $url['match']);
                        }
                    }
                }
                break;
            default:
        }
    }
private function setTarget(SimpleXMLElement $element)
    {
        $target = $element->addChild('target');
        switch ($this->nb_data_object->getUseURI()) {
            case 'T':
                if (($nb_site = $this->nb_data_object->getSite()) instanceof CNabuSite &&
                    ($nb_site_target = $nb_site->getTarget($this->nb_data_object->getSiteTargetId())) instanceof CNabuSiteTarget
                ) {
                    $target->addAttribute('useURI', 'T');
                    $target->addAttribute('target', $nb_site_target->getHash());
                } else {
                    error_log("Target not exists");
                }
                break;
            case 'U':
                $translations = $this->nb_data_object->getTranslations();
                $urls = array();
                $translations->iterate(function ($lang, $nb_translation) use (&$urls) {
                    $urls[$lang] = array(
                        'url' => $nb_translation->getURL(),
                        'match' => $nb_translation->getMatchURLFragment()
                    );
                    return true;
                });
                if (count($urls) > 0) {
                    $target->addAttribute('useURI', 'U');
                    foreach ($urls as $lang => $url) {
                        if (strlen($url) > 0) {
                            $nb_language = $this->nb_data_object->getLanguage($lang);
                            $address = $target->addChild('url');
                            $address->addAttribute('lang', $nb_language->getHash());
                            $address->addAttribute('url', $url['url']);
                            $address->addAttribute('match', $url['match']);
                        }
                    }
                }
                break;
            default:
        }
    }
private function setTarget ( SimpleXMLElement $ element ) { $ target = $ element -> addChild ( 'target' ) ; switch ( $ this -> nb_data_object -> getUseURI ( ) ) { case 'T' : if ( ( $ nb_site = $ this -> nb_data_object -> getSite ( ) ) instanceof CNabuSite && ( $ nb_site_target = $ nb_site -> getTarget ( $ this -> nb_data_object -> getSiteTargetId ( ) ) ) instanceof CNabuSiteTarget ) { $ target -> addAttribute ( 'useURI' , 'T' ) ; $ target -> addAttribute ( 'target' , $ nb_site_target -> getHash ( ) ) ; } else { error_log ( "Target not exists" ) ; } break ; case 'U' : $ translations = $ this -> nb_data_object -> getTranslations ( ) ; $ urls = array ( ) ; $ translations -> iterate ( function ( $ lang , $ nb_translation ) use ( & $ urls ) { $ urls [ $ lang ] = array ( 'url' => $ nb_translation -> getURL ( ) , 'match' => $ nb_translation -> getMatchURLFragment ( ) ) ; return true ; } ) ; if ( count ( $ urls ) > 0 ) { $ target -> addAttribute ( 'useURI' , 'U' ) ; foreach ( $ urls as $ lang => $ url ) { if ( strlen ( $ url ) > 0 ) { $ nb_language = $ this -> nb_data_object -> getLanguage ( $ lang ) ; $ address = $ target -> addChild ( 'url' ) ; $ address -> addAttribute ( 'lang' , $ nb_language -> getHash ( ) ) ; $ address -> addAttribute ( 'url' , $ url [ 'url' ] ) ; $ address -> addAttribute ( 'match' , $ url [ 'match' ] ) ; } } } break ; default : } }
Set the target branch.
@param SimpleXMLElement $element Parent element to anidate branch.
Set the target branch .