/**
  * Finds the currently selected template object by climbing up the root line.
  *
  * @param	array		$row: A page record
  * @return	mixed		The template object record or FALSE if none was found
  * @access	protected
  */
 function getContentTree_fetchPageTemplateObject($row)
 {
     $templateObjectUid = $row['tx_templavoila_ds'] ? intval($row['tx_templavoila_to']) : 0;
     if (!$templateObjectUid) {
         $rootLine = t3lib_beFunc::BEgetRootLine($row['uid'], '', TRUE);
         foreach ($rootLine as $rootLineRecord) {
             $pageRecord = t3lib_beFunc::getRecord('pages', $rootLineRecord['uid']);
             if ($row['uid'] != $pageRecord['uid'] && $pageRecord['tx_templavoila_next_ds'] && $pageRecord['tx_templavoila_next_to']) {
                 // If there is a next-level TO:
                 $templateObjectUid = $pageRecord['tx_templavoila_next_to'];
                 break;
             } elseif ($pageRecord['tx_templavoila_ds'] && $pageRecord['tx_templavoila_to']) {
                 // Otherwise try the NORMAL TO:
                 $templateObjectUid = $pageRecord['tx_templavoila_to'];
                 break;
             }
         }
     }
     return t3lib_beFunc::getRecordWSOL('tx_templavoila_tmplobj', $templateObjectUid);
 }
 /**
  * Returns the uid of the TemplaVoila page template for the given page uid
  *
  * @param $pageUid
  * @return int
  */
 public function getTvPageTemplateUid($pageUid)
 {
     $pageRecord = $this->getPage($pageUid);
     $tvTemplateObjectUid = 0;
     if ($pageRecord['tx_templavoila_to'] != '' && $pageRecord['tx_templavoila_to'] != 0) {
         $tvTemplateObjectUid = $pageRecord['tx_templavoila_to'];
     } else {
         $rootLine = t3lib_beFunc::BEgetRootLine($pageRecord['uid'], '', TRUE);
         foreach ($rootLine as $rootLineRecord) {
             $myPageRecord = t3lib_beFunc::getRecordWSOL('pages', $rootLineRecord['uid']);
             if ($myPageRecord['tx_templavoila_next_to']) {
                 $tvTemplateObjectUid = $myPageRecord['tx_templavoila_next_to'];
                 break;
             }
         }
     }
     return $tvTemplateObjectUid;
 }