autonav / pagelist combo

Permalink
my autonav has a link to "calendar". however, the "calendar" page doesn't actually exists (no content). what it needs to do is link to the earliest from today "calendar_event" page type.

my upcoming page list does it nicely. i have the controller telling it to not pull any page types dated before today. then in the template, i have a "view full calendar" which basically pulls the 1st value from the page list array.

SO, i was wondering if the "calendar" link in the autonav could grab the same value as the "view full calendar".

hopeful,
jesse

 
jhart replied on at Permalink Reply
some sort of if statement in my autonav template or something?
jhart replied on at Permalink Reply
please... any hints/advice? just want to finish this &$WU#R*(U# site.
okhayat replied on at Permalink Reply
okhayat
My best guess is using templates you can do it.
Create a template for autonav block, place it under your_site/block/autonav/templates/, edit your block and select it.
To create a template, simply copy the /concrete/blocks/autonav/view.php or any of the files under templates/ in the same directory.
jhart replied on at Permalink Reply
ya, i'm using a custom template already. the question is how to get a specific nav item to go to a certain page type.
okhayat replied on at Permalink Reply
okhayat
If you define a relation between the 'Nav Item' => 'Page Type' it will be easy.
For example, you mentioned the calendar_event at the beginning. So, you would:
+ Check for the page type using $c->getCollectionTypeHandle() which will return 'calendar' or 'calendar_event' based on the page type.
+ Check for additional information, to help you determine what to do, like the Public Date of the page ($c->getCollectionDatePublic()) or an attribute ($c->getCollectionAttributeValue('attrib')).
It's really not clear to me what you're doing exactly, so I'm just suggesting these things.
Hope it helps.
jhart replied on at Permalink Reply
i really appreciate your help. alright let me try and clear it up. its a global main nav that links to a variety of page types. however, i need this one link (calendar) to link to a specific page type (calendar_event)

1. in my autonav template how do i have it look for "calendar" as the nav item?

2. once it knows its the "calendar" link how do i have it specify to link to the page (any page that has calendar_event as its page type) closest to today's date.
okhayat replied on at Permalink Reply
okhayat
I created this sample code and used it in header_menu.php autonav template, after line 47:
1. The code assumes your Calendar page/section is under /calendar.
2. The page type you're looking for is calendar_event.
3. The date to compare is the Public Date (getCollectionDatePublic()).
<?php
  $calPage = Page::getByPath('/calendar');
  $calChildren = $calPage->getCollectionChildrenArray();
  $latDate = 0;
  foreach ($calChildren as $eID) {
    $eventPage = Page::getByID($eID);
    // Find calendar_event pages only
    if ($eventPage->getCollectionTypeHandle() == 'calendar_event') {
      // Check if it's the latest page
      $curDate = strtotime($eventPage->getCollectionDatePublic());
      if ($curDate > $latDate) {
        $curEventPage = $eventPage;
        $latDate = $curDate;
      }
    }

Hope this helps.
jhart replied on at Permalink Reply
wow great. thanks! i'm really new to this stuff. let me get even more specific...

1. my calendar_event page types are all over the site. they aren't just children under "calendar". so it needs to globally search for them.

2. i don't need the name of the page just the link. in my nav template i have this which works good. if the nav link name is "calendar" then the pagelink should be...
if ($ni->getName() == 'calendar' {
    $pageLink = ????
}


i don't need the "latest" page. but rather the nearest event to "today". in my pagelist controller i had it working with this:
$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$pl->filterByPublicDate(date('c',($today)), '>=');


by the way, give me your paypal address (via email) and ill send some cash your way.

where i'm at (bad attempt at trying to rework your code)... which results in ugly errors:
if ($ni->getName() == 'calendar') {
   $calPages = $_c->getCollectionChildrenArray();
   foreach ($calPages as $eID) {
      $eventPage = Page::getByID($eID);
      if ($eventPage->getCollectionTypeHandle() == 'calendar_event') {
         $today = mktime(0,0,0,date("m"),date("d"),date("Y"));
         $eventPage->filterByPublicDate(date('c',($today)), '>='); 
         $pageLink = $eventPage;
      }
   }
}


i think filterByPublicDate only works for page list.
okhayat replied on at Permalink Reply
okhayat
You can either begin the search from the Home - Page::getByID(1) instead of Page::getByPath('/calendar') - or simply use SQL statement and get a list of all pages of 'calendar_event' type (which is faster I guess):
<?php
  $myDB = Loader::db();
  $calIDs = $myDB->execute("
SELECT p.cID FROM Pages p
JOIN CollectionVersions cv ON p.cID = cv.cID
JOIN PageTypes pt ON p.ctID = pt.ctID
WHERE pt.ctHandle = 'calendar_event' -- the page type
AND cIsTemplate = 0 -- get pages and not templates
AND cvName = 'calendar' -- get pages named calendar
AND cvDatePublic >= SYSDATE() -- sysdate() is DB Server Date
AND cvIsApproved = 1 -- get the approved version of the page
ORDER BY cvDatePublic -- ordered result to get dates by nearest
LIMIT 1 -- Get the nearest event only
  ");
  $eID = $calIDs->fetchRow();

Explanation of the code is inline, but here's a quick overview.
Using SQL, I lookup the nearest upcoming event (calendar_event) to today's date (thus ordering by Date Public and LIMITing the result to 1 record). Then get the page by its ID and then the path.
Please note that the pages looked up are the Approved ones (version) only and not the latest version.
If you need the solution using C5's code, I can do it.
Cool, I'm getting some cash :-P I'm really just trying to help whenever I can, to learn and hope I get help as well when I need it.
My PayPal email is: okhayat@gmail.com
Thanks in advance!