示例#1
0
 /**
  * 
  * We've fetched a page on our own using aPageTable::queryWithSlots and we want
  * to make Apostrophe aware of it so that areas on the current page that live on
  * that virtual page don't generate a superfluous second query. Can accept an array,
  * a collection or a single page object. Hydrates pages if needed (app_a_fasthydrate).
  * Returns an array of page objects for convenience in mapping them back to 
  * other objects they are associated with (necessary to leverage app_a_fasthydrate
  * in code like our blog plugin that associates a page with an object).
  *
  * @param array, Doctrine_Collection, aPage $pages
  */
 public static function cacheVirtualPages($pages)
 {
     $results = array();
     if (is_object($pages) && $pages instanceof Doctrine_Collection || is_array($pages)) {
         foreach ($pages as $page) {
             $results[] = aTools::cacheVirtualPage($page);
         }
     } else {
         $results[] = aTools::cacheVirtualPage($pages);
     }
     return $results;
 }
示例#2
0
 /**
  * Given an array of blogItems this function will populate its virtual page
  * areas with the current slot versions.
  * @param aBlogItem $blogItems
  */
 public static function populatePages($blogItems)
 {
     $pageIds = array();
     foreach ($blogItems as $aBlogItem) {
         $pageIds[] = $aBlogItem['page_id'];
     }
     $pages = array();
     if (count($pageIds)) {
         $q = aPageTable::queryWithSlots();
         $q->whereIn('id', $pageIds);
         $fast = sfConfig::get('app_a_fasthydrate', false);
         $pagesInfo = $q->execute(array(), $fast ? Doctrine::HYDRATE_ARRAY : Doctrine::HYDRATE_RECORD);
         foreach ($pagesInfo as $pageInfo) {
             $pages[] = aTools::cacheVirtualPage($pageInfo);
         }
     }
     $pagesById = aArray::listToHashById($pages);
     foreach ($blogItems as $aBlogItem) {
         if (isset($pagesById[$aBlogItem->page_id])) {
             $aBlogItem->Page = $pagesById[$aBlogItem->page_id];
         }
     }
 }