private function setRedirection(SimpleXMLElement $element, string $field, string $tag_name)
    {
        $page = $element->addChild($tag_name);
        switch ($this->nb_data_object->getValue("nb_site_${field}_target_use_uri")) {
            case 'T':
                $id = $this->nb_data_object->getValue("nb_site_${field}_target_id");
                if (is_numeric($id) && is_string($hash = $this->grantTargetHash($id))) {
                    $page->addAttribute('useURI', 'T');
                    $page->addAttribute('id', $hash);
                    $this->putAttributesFromList($page, array(
                        "nb_site_${field}_error_code" => "errorCode"
                    ));
                }
                break;
            case 'U':
                $translations = $this->nb_data_object->getTranslations();
                $urls = array();
                $translations->iterate(function($lang, $nb_translation) use(&$urls, $field) {
                    $urls[$lang] = $nb_translation->getValue("nb_site_lang_${field}_target_url");
                    return true;
                });
                if (count($urls) > 0) {
                    $page->addAttribute('useURI', 'U');
                    foreach ($urls as $lang => $url) {
                        if (strlen($url) > 0) {
                            $nb_language = $this->nb_data_object->getLanguage($lang);
                            $address = $page->addChild('url');
                            $address->addAttribute('lang', $nb_language->getHash());
                            $address->addAttribute('url', $url);
                        }
                    }
                }
                $this->putAttributesFromList($page, array(
                    "nb_site_${field}_error_code" => "errorCode"
                ), true);
                break;
        }
    }
private function setRedirection(SimpleXMLElement $element, string $field, string $tag_name)
    {
        $page = $element->addChild($tag_name);
        switch ($this->nb_data_object->getValue("nb_site_${field}_target_use_uri")) {
            case 'T':
                $id = $this->nb_data_object->getValue("nb_site_${field}_target_id");
                if (is_numeric($id) && is_string($hash = $this->grantTargetHash($id))) {
                    $page->addAttribute('useURI', 'T');
                    $page->addAttribute('id', $hash);
                    $this->putAttributesFromList($page, array(
                        "nb_site_${field}_error_code" => "errorCode"
                    ));
                }
                break;
            case 'U':
                $translations = $this->nb_data_object->getTranslations();
                $urls = array();
                $translations->iterate(function($lang, $nb_translation) use(&$urls, $field) {
                    $urls[$lang] = $nb_translation->getValue("nb_site_lang_${field}_target_url");
                    return true;
                });
                if (count($urls) > 0) {
                    $page->addAttribute('useURI', 'U');
                    foreach ($urls as $lang => $url) {
                        if (strlen($url) > 0) {
                            $nb_language = $this->nb_data_object->getLanguage($lang);
                            $address = $page->addChild('url');
                            $address->addAttribute('lang', $nb_language->getHash());
                            $address->addAttribute('url', $url);
                        }
                    }
                }
                $this->putAttributesFromList($page, array(
                    "nb_site_${field}_error_code" => "errorCode"
                ), true);
                break;
        }
    }
private function setRedirection ( SimpleXMLElement $ element , string $ field , string $ tag_name ) { $ page = $ element -> addChild ( $ tag_name ) ; switch ( $ this -> nb_data_object -> getValue ( "nb_site_${field}_target_use_uri" ) ) { case 'T' : $ id = $ this -> nb_data_object -> getValue ( "nb_site_${field}_target_id" ) ; if ( is_numeric ( $ id ) && is_string ( $ hash = $ this -> grantTargetHash ( $ id ) ) ) { $ page -> addAttribute ( 'useURI' , 'T' ) ; $ page -> addAttribute ( 'id' , $ hash ) ; $ this -> putAttributesFromList ( $ page , array ( "nb_site_${field}_error_code" => "errorCode" ) ) ; } break ; case 'U' : $ translations = $ this -> nb_data_object -> getTranslations ( ) ; $ urls = array ( ) ; $ translations -> iterate ( function ( $ lang , $ nb_translation ) use ( & $ urls , $ field ) { $ urls [ $ lang ] = $ nb_translation -> getValue ( "nb_site_lang_${field}_target_url" ) ; return true ; } ) ; if ( count ( $ urls ) > 0 ) { $ page -> addAttribute ( 'useURI' , 'U' ) ; foreach ( $ urls as $ lang => $ url ) { if ( strlen ( $ url ) > 0 ) { $ nb_language = $ this -> nb_data_object -> getLanguage ( $ lang ) ; $ address = $ page -> addChild ( 'url' ) ; $ address -> addAttribute ( 'lang' , $ nb_language -> getHash ( ) ) ; $ address -> addAttribute ( 'url' , $ url ) ; } } } $ this -> putAttributesFromList ( $ page , array ( "nb_site_${field}_error_code" => "errorCode" ) , true ) ; break ; } }
Build a redirection element.
@param SimpleXMLElement $element Parent element.
@param string $field Field part name in the original data object.
@param string $tag_name Tag name of the element.
Build a redirection element .