[phpBB Debug] PHP Warning: in file [ROOT]/ext/tas2580/seourls/event/listener.php on line 213: Undefined array key "FORUM_NAME"
REDAXO Forum • [gelöst] "Online vom - bis zum" in den Meta-Daten
Seite 1 von 1

[gelöst] "Online vom - bis zum" in den Meta-Daten

Verfasst: 26. Feb 2010, 15:22
von argon
Ich würde gerne das folgende Navigations-Template so anpassen das die Änderungen im BackEnd (Meta-Daten), im FrontEnd (Navi) wirksam werden. (Online vom - bis zum)
Ich benutze REDAXO 4.2.1.

Ich finde leider keine Code-Fragmente die mir an dieser Stelle weiterhelfen. Würde mir bitte jemand weiterhelfen, oder eine kleine Anregung geben? Ich finde im Moment keinen Ansatz.

Code: Alles auswählen

<?php

/* 

Templatename: 3 Ebenen / Liste mit li-Tags

 Navi Kurzbeschreibung:
 ----------------------
 - 3 Ebenen,
 - Navigation als ul-Liste,
 - nur Online,
 - Kind-Kategorie wird angezeigt nach Klick auf Eltern-Kategorie
*/

// EXPLODE PATH
$PATH = explode("|",$this->getValue("path").$this->getValue("article_id")."|");

// GET CURRENTS
$path1 = $PATH[1];
$path2 = $PATH[2];
$path3 = $PATH[3];


/* START 1st level categories */
$nav .= '<ul class="nav1st">';
foreach (OOCategory::getRootCategories() as $lev1) {
      
   if ($lev1->isOnline(true)):
      if ($lev1->getId() == $path1) {
         $nav .= '<li><a class="current" href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
      }
      // 2nd level - no active link
      else {
         $nav .= '<li><a href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
      }
         
      // 1st level had categories? -> go on
      $lev1Size = sizeof($lev1->getChildren());
   
      if ($lev1->getId() == $path1) {
         if ($lev1Size != "0") {
            $nav .= '<ul class="nav2nd">';

            // START 2nd level categories
            foreach ($lev1->getChildren() as $lev2):
               if ($lev2->isOnline(true)) {
                  // 2nd level - active link
                  if ($lev2->getId() == $path2) {
                     $nav .= '<li><a class="current" href="'.$lev2->getUrl().'">'.$lev2->getName().'</a>';
                  }
                  // 2nd level - no active link
                  else {
                     $nav .= '<li><a href="'.$lev2->getUrl().'">'.$lev2->getName().'</a>';
                  }
                  
                  // 2nd level had categories? -> go on
                  $lev2Size = sizeof($lev2->getChildren());
   
                  if ($lev2->getId() == $path2) {
                     if ($lev2Size != "0") {
                        $nav .= '<ul class="nav3rd">';

                        // START 3rd level categories
                        foreach ($lev2->getChildren() as $lev3):
                           if ($lev3->isOnline(true)) {
                              // 3rd level - active link
                              if ($lev3->getId() == $path3) {
                                 $nav .= '<li><a class="current" href="'.$lev3->getUrl().'">'.$lev3->getName().'</a></li>';
                              }
                              // 3rd level - no active link
                              else {
                                 $nav .= '<li><a href="'.$lev3->getUrl().'">'.$lev3->getName().'</a></li>';
                              }
                           }
                        endforeach;
                        // END 3rd level categories
      
                        $nav .= '</ul>';
                     } // END by if ($lev2Size != "0"):
                  }
                  $nav .= '</li>';
               }
            endforeach;
            // END 2nd level categories
      
            $nav .= '</ul>';
         } // END by if ($lev1Size != "0"):
      }
      $nav .= '</li>';

   endif; // END by if ($lev1->isOnline())
}
$nav .= '</ul>';
// END 1st level categories

print $nav;
?> 

Verfasst: 26. Feb 2010, 17:06
von timo.huber
Hi,

ich hab sowas zwar nicht im Einsatz, aber so sollte es gehen ;)

Code: Alles auswählen

<?php
$currTime = time();

foreach (OOCategory::getRootCategories(true) as $cat)
{
$online_from = $cat->getValue("art_online_from");
$online_to = $cat->getValue("art_online_to");

if ($online_from != "" || $online_to != "")
{
if ($currTime > $online_from && $currTime < $online_to)
{
echo $cat->getName() . "<br />";
}
}
else
{
echo $cat->getName() . "<br />";
}
}
?>

Verfasst: 26. Feb 2010, 18:27
von argon
Herzlichen Dank für diese tolle Anregung, das war der Weg zum Ziel.
Es funktionierte auf Anhieb... :D

Hier die Umsetzung im Navi-Template von oben:
(Nur für die erste Ebene, die anderen Ebenen sind noch nicht umgesetzt, sollte aber nun kein Problem mehr sein.)

Code: Alles auswählen

<?php

// EXPLODE PATH
$PATH = explode("|",$this->getValue("path").$this->getValue("article_id")."|");

// GET CURRENTS
$path1 = $PATH[1];
$path2 = $PATH[2];
$path3 = $PATH[3];

$currTime = time();

/* START 1st level categories */
$nav .= '<ul class="nav1st">';
foreach (OOCategory::getRootCategories() as $lev1) {

   $online_from = $lev1->getValue("art_online_from");
   $online_to = $lev1->getValue("art_online_to");
      
   if ($lev1->isOnline(true)):
    
    if ($online_from != "" || $online_to != ""){      
      if ($currTime > $online_from && $currTime < $online_to){
      
          if ($lev1->getId() == $path1) {
             $nav .= '<li><a class="current" href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
          }
          // 2nd level - no active link
          else {
             $nav .= '<li><a href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
          }
      }
    } else {
          if ($lev1->getId() == $path1) {
             $nav .= '<li><a class="current" href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
          }
          // 2nd level - no active link
          else {
             $nav .= '<li><a href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
          }
    } 

...  //weitere Ebenen ...

?>

Der Abend ist gerettet... :wink:
I'am very happy!!!

VG, argon

Verfasst: 27. Feb 2010, 08:45
von argon
Vollständigkeitshalber hier nochmal der fertige, funktionsfähige Code für alle drei Ebenen. Ist sicherlich nicht der sauberste Weg, aber es funktioniert. :wink:

Danke nochmal Timo für Dein Beispiel-Code :D
Und Danke auch an Thomas Blum, wenn ich mich recht entsinne, stammt der ursprüngliche Template-Code von ihm.

Code: Alles auswählen

<?php

/* 

Templatename: 3 Ebenen / Liste mit li-Tags

 Navi Kurzbeschreibung:
 ----------------------
 - 3 Ebenen,
 - Navigation als ul-Liste,
 - nur Online,
 - Berücksichtigung der Meta-Daten - Online vom .. - bis ..
 - Kind-Kategorie wird angezeigt nach Klick auf Eltern-Kategorie
*/


// EXPLODE PATH
$PATH = explode("|",$this->getValue("path").$this->getValue("article_id")."|");

// GET CURRENTS
$path1 = $PATH[1];
$path2 = $PATH[2];
$path3 = $PATH[3];

$currTime = time();

/* START 1st level categories */
$nav .= '<ul class="nav1st">';
foreach (OOCategory::getRootCategories() as $lev1) {

   $online_from = $lev1->getValue("art_online_from");
   $online_to = $lev1->getValue("art_online_to");
      
   if ($lev1->isOnline(true)):
    
    if ($online_from != "" || $online_to != ""){      
      if ($currTime > $online_from && $currTime < $online_to){
      
          if ($lev1->getId() == $path1) {
             $nav .= '<li><a class="current" href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
          }
          // 2nd level - no active link
          else {
             $nav .= '<li><a href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
          }
      }
    } else {
          if ($lev1->getId() == $path1) {
             $nav .= '<li><a class="current" href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
          }
          // 2nd level - no active link
          else {
             $nav .= '<li><a href="'.$lev1->getUrl().'">'.$lev1->getName().'</a>';
          }
    }     
         
      // 1st level had categories? -> go on
      $lev1Size = sizeof($lev1->getChildren());
   
      if ($lev1->getId() == $path1) {
         if ($lev1Size != "0") {
            $nav .= '<ul class="nav2nd">';

            // START 2nd level categories
            foreach ($lev1->getChildren() as $lev2):
            
           $online_from = $lev2->getValue("art_online_from");
           $online_to = $lev2->getValue("art_online_to");            
            
            if ($lev2->isOnline(true)) {
             if ($online_from != "" || $online_to != ""){      
               if ($currTime > $online_from && $currTime < $online_to){               
               
                  // 2nd level - active link
                  if ($lev2->getId() == $path2) {
                     $nav .= '<li><a class="current" href="'.$lev2->getUrl().'">'.$lev2->getName().'</a>';
                  }
                  // 2nd level - no active link
                  else {
                     $nav .= '<li><a href="'.$lev2->getUrl().'">'.$lev2->getName().'</a>';
                  }
               }
             } else {              
                  // 2nd level - active link
                  if ($lev2->getId() == $path2) {
                     $nav .= '<li><a class="current" href="'.$lev2->getUrl().'">'.$lev2->getName().'</a>';
                  }
                  // 2nd level - no active link
                  else {
                     $nav .= '<li><a href="'.$lev2->getUrl().'">'.$lev2->getName().'</a>';
                  }
             }                    
                  
                  // 2nd level had categories? -> go on
                  $lev2Size = sizeof($lev2->getChildren());
   
                  if ($lev2->getId() == $path2) {
                     if ($lev2Size != "0") {
                        $nav .= '<ul class="nav3rd">';

                        // START 3rd level categories
                        foreach ($lev2->getChildren() as $lev3):
                        
                       $online_from = $lev3->getValue("art_online_from");
                       $online_to = $lev3->getValue("art_online_to");                            
                        
                        if ($lev3->isOnline(true)) {
                          if ($online_from != "" || $online_to != ""){      
                            if ($currTime > $online_from && $currTime < $online_to){                             
                              
                              // 3rd level - active link
                              if ($lev3->getId() == $path3) {
                                 $nav .= '<li><a class="current" href="'.$lev3->getUrl().'">'.$lev3->getName().'</a></li>';
                              }
                              // 3rd level - no active link
                              else {
                                 $nav .= '<li><a href="'.$lev3->getUrl().'">'.$lev3->getName().'</a></li>';
                              }
                             } 
                           } else { 
                              // 3rd level - active link
                              if ($lev3->getId() == $path3) {
                                 $nav .= '<li><a class="current" href="'.$lev3->getUrl().'">'.$lev3->getName().'</a></li>';
                              }
                              // 3rd level - no active link
                              else {
                                 $nav .= '<li><a href="'.$lev3->getUrl().'">'.$lev3->getName().'</a></li>';
                              }
                           }
                         }
                        endforeach;
                        // END 3rd level categories
      
                        $nav .= '</ul>';
                     } // END by if ($lev2Size != "0"):
                  }
                  $nav .= '</li>';
               }
            endforeach;
            // END 2nd level categories
      
            $nav .= '</ul>';
         } // END by if ($lev1Size != "0"):
      }
      $nav .= '</li>';

   endif; // END by if ($lev1->isOnline())
}
$nav .= '</ul>';
// END 1st level categories

print $nav;
?>

Verfasst: 27. Feb 2010, 10:08
von argon
Kleine Ergänzung:
-----------------------

Wenn man möchte, dass am EndTag der Menüpunkt noch den ganzen Tag sichtbar ist, sollte man für "$online_to" die Zeitvariable ändern.

...

if ($currTime > $online_from && $currTime-86400 < $online_to)

...

Das hatte mich noch gestört.

Info stammt von Holger, aus diesem Thread:
http://forum.redaxo.de/ftopic9482.html? ... =time86400


VG, argon

Verfasst: 25. Okt 2010, 00:04
von nik
Frage an die Entwickler: Warum sind die Metadaten überhaupt vorbelegt, wenn Sie gar nicht automatisch aktiv sind? Ist irgendwie verwirrend, vielleicht sollte man das mal dokumentieren, dass diese Eingabefelder nur Deko sind.