To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Show
Ignore:
Timestamp:
04/26/10 17:08:58 (2 years ago)
Author:
tboutell
Message:

New default behavior of navigation components is appropriate for use on large sites with many pages. On small sites it may be slightly slower, in which case you can set app_a_many_pages to false to get the old "fetch the entire page tree and reuse it in each navigation component as needed" behavior back. This worked quite well up to about 1,000 pages but became a serious problem on an 8,000-page site.

aPage::getAncestorsInfo now has an optional 'includeSelf' parameter which defaults to false for backwards compatibility.

aPage::getInfo provides a page info array about the current page. Useful when merging information from the Info methods with information about pages you already have as objects.

aPage::getAccordionInfo now has an optional final parameter, 'root', which specifies the slug of the root page of the accordion tree. The page on which getAccordionInfo is called should be a descendant of that page (or the root page itself).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/trunk/lib/model/doctrine/PluginaPage.class.php

    r970 r1065  
    570570  protected $ancestorsInfo; 
    571571   
    572   public function getAncestorsInfo() 
     572  public function getAncestorsInfo($includeSelf = false) 
    573573  { 
    574574    if (!isset($this->ancestorsInfo)) 
     
    577577      // Since our presence on an admin page implies we know about it, it's OK to include 
    578578      // admin pages in the breadcrumb. It's not OK in other navigation 
    579       $this->ancestorsInfo = $this->getPagesInfo(false, '( p.lft < ' . $this->lft . ' AND p.rgt > ' . $this->rgt . ' )', true); 
     579      $less = '<'; 
     580      $greater = '>'; 
     581      if ($includeSelf) 
     582      { 
     583        $less = '<='; 
     584        $greater = '>='; 
     585      } 
     586      $this->ancestorsInfo = $this->getPagesInfo(false, "( p.lft $less " . $this->lft . " AND p.rgt $greater " . $this->rgt . ' )', true); 
    580587    } 
    581588    return $this->ancestorsInfo; 
     
    602609      { 
    603610        // It's the home page. Return a stub: the home page is its only peer 
    604         $this->peerInfo = array(array('id' => $this->id, 'title' => $this->getTitle(), 'slug' => $this->slug, 'view_is_secure' => $this->view_is_secure, 'archived' => $this->archived, 'level' => $this->level, 'lft' => $this->lft, 'rgt' => $this->rgt)); 
     611        $this->peerInfo = array($this->getInfo()); 
    605612      } 
    606613      else 
     
    615622  } 
    616623 
     624  // Sometimes it is useful to have an info structure describing a page object 
     625  // (the aNavigation classes exploit this) 
     626   
     627  public function getInfo() 
     628  { 
     629    return array('id' => $this->id, 'title' => $this->getTitle(), 'slug' => $this->slug, 'view_is_secure' => $this->view_is_secure, 'archived' => $this->archived, 'level' => $this->level, 'lft' => $this->lft, 'rgt' => $this->rgt); 
     630  } 
     631   
    617632  protected $childrenInfo; 
    618633   
     
    709724  //   Two 
    710725   
     726  // You can now specify the root slug, which defaults to the home page. 
     727   
    711728  // Note that children of Two, 1a, and 1c are NOT returned. Only the siblings of 
    712729  // the current page's ancestors, the current page and its siblings, and the immediate 
    713730  // children of the current page are returned. For a full tree use getTreeInfo(). 
    714731   
    715   public function getAccordionInfo($livingOnly = true, $depth = null) 
     732  public function getAccordionInfo($livingOnly = true, $depth = null, $root = '/') 
    716733  { 
    717734    // As far as I can tell there is no super-elegant, single-query way to do this 
     
    724741    // an accordion contro. in the first place 
    725742    $ancestors = $this->getAncestorsInfo(); 
     743     
     744    // Dump ancestors we don't care about 
     745    for ($i = 0; ($i < count($ancestors)); $i++) 
     746    { 
     747      if ($ancestors[$i]['slug'] === $root) 
     748      { 
     749        $ancestors = array_slice($ancestors, $i); 
     750        break; 
     751      } 
     752    } 
     753    if ($i === count($ancestors)) 
     754    { 
     755      throw new sfException("Root slug $root never found among ancestors in getAccordionInfo"); 
     756    } 
    726757    $result = array(); 
    727758    // Ancestor levels