SHARE
TWEET

Untitled

a guest Aug 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class ffViewDataManager extends ffBasicObject {
  4.     /**********************************************************************************************************************/
  5.     /* OBJECTS
  6.     /**********************************************************************************************************************/
  7.     /**
  8.      * @var ffWPLayer
  9.      */
  10.     private $_WPLayer = null;
  11.  
  12.     /**
  13.      * @var ffDataStorage_WPPostMetas
  14.      */
  15.     private $_postMeta = null;
  16.  
  17.     /**
  18.      * @var ffSiteMapper
  19.      */
  20.     private $_siteMapper = null;
  21.  
  22.     /**
  23.      * @var ffOptionsCollection
  24.      */
  25.     private $_templatesCollection = null;
  26.  
  27.     /**
  28.      * @var ffOptionsCollection
  29.      */
  30.     private $_viewsMapCollection = null;
  31.  
  32.  
  33.     /**********************************************************************************************************************/
  34.     /* PRIVATE VARIABLES
  35.     /**********************************************************************************************************************/
  36.  
  37.  
  38.     /**********************************************************************************************************************/
  39.     /* CONSTRUCT
  40.     /**********************************************************************************************************************/
  41.     public function __construct() {
  42.         $this->_setSiteMapper( ffContainer()->getThemeFrameworkFactory()->getSitePreferencesFactory()->getSiteMapper() );
  43.  
  44.         $this->_setWPLayer( ffContainer()->getWPLayer());
  45.         $this->_setPostMeta( ffContainer()->getDataStorageFactory()->createDataStorageWPPostMetas() );
  46.  
  47.  
  48.  
  49.         $templatesCollection = ffContainer()->getDataStorageFactory()->createOptionsCollection();
  50.         $viewsMapCollection = ffContainer()->getDataStorageFactory()->createOptionsCollection();
  51.  
  52.         $templatesCollection->setNamespace('templates');
  53.         $templatesCollection->addDefaultItemCallbacksFromThemeFolder();
  54.  
  55.         $viewsMapCollection->setNamespace('views_map');
  56.         $viewsMapCollection->addDefaultItemCallbacksFromThemeFolder();
  57.  
  58.         $this->_setTemplatesCollection( $templatesCollection );
  59.         $this->_setViewsMapCollection( $viewsMapCollection );
  60.     }
  61.  
  62.     public function getCurrentHeader() {
  63.         $currentLayoutInfo = $this->getCurrentLayoutInfo();
  64.  
  65.  
  66.         $headerId = $currentLayoutInfo->get('header');
  67.  
  68.         if( $headerId == 'none' ) {
  69.             return 'none';
  70.         }
  71.  
  72.         $headersCollection = ffContainer()->getDataStorageFactory()->createOptionsCollection();
  73.         $headersCollection->setNamespace('header');
  74.         $headersCollection->addDefaultItemCallbacksFromThemeFolder();
  75.         $headerDefault = $headersCollection->getItemById( $headerId );
  76.  
  77.         if( $headerDefault->getData() == null ) {
  78.             $headerDefault = $headersCollection->getItemById('header_default');
  79.         }
  80.  
  81.         return $headerDefault;
  82.     }
  83.  
  84.     public function getCurrentBoxedWrapper() {
  85.         $currentLayoutInfo = $this->getCurrentLayoutInfo();
  86.  
  87.         $headerId = $currentLayoutInfo->get('boxed_wrapper');
  88.  
  89.         if( $headerId == 'none' ) {
  90.             return 'none';
  91.         }
  92.  
  93.         $itemCollection = ffContainer()->getDataStorageFactory()->createOptionsCollection();
  94.         $itemCollection->setNamespace('boxed_wrapper');
  95.         $itemCollection->addDefaultItemCallbacksFromThemeFolder();
  96.         $itemDefault = $itemCollection->getItemById( $headerId );
  97.  
  98.         if( $itemDefault->getData() == null ) {
  99.             $itemDefault = $itemCollection->getItemById('default_boxed_wrapper');
  100.         }
  101.  
  102.         return $itemDefault;
  103.     }
  104.  
  105.     public function getCurrentTitleBar() {
  106.         $currentLayoutInfo = $this->getCurrentLayoutInfo();
  107.  
  108.         $titleBarId = $currentLayoutInfo->get('titlebar');
  109.  
  110.         if( $titleBarId == 'none' ) {
  111.             return 'none';
  112.         }
  113.  
  114.         $titleBarsCollection = ffContainer()->getDataStorageFactory()->createOptionsCollection();
  115.         $titleBarsCollection->setNamespace('titlebar');
  116.         $titleBarsCollection->addDefaultItemCallbacksFromThemeFolder();
  117.         $titleBarDefault = $titleBarsCollection->getItemById( $titleBarId );
  118.  
  119.         if( $titleBarDefault->getData() == null ) {
  120.             $titleBarDefault = $titleBarsCollection->getItemById('titlebar_default');
  121.         }
  122.  
  123.         return $titleBarDefault;
  124.     }
  125.  
  126.     public function getCurrentFooter() {
  127.         $currentLayoutInfo = $this->getCurrentLayoutInfo();
  128.  
  129.         $footerId = $currentLayoutInfo->get('footer');
  130.  
  131.         if( $footerId == 'none' ) {
  132.             return 'none';
  133.         }
  134.  
  135.         $footersCollection = ffContainer()->getDataStorageFactory()->createOptionsCollection();
  136.         $footersCollection->setNamespace('footer');
  137.         $footersCollection->addDefaultItemCallbacksFromThemeFolder();
  138.         $footerDefault = $footersCollection->getItemById( $footerId );
  139.  
  140.         if( $footerDefault->getData() == null ) {
  141.             $footerDefault = $footersCollection->getItemById('footer_default');
  142.         }
  143.  
  144.         return $footerDefault;
  145.     }
  146.  
  147.  
  148.     private $_currentLayoutInfo = null;
  149.  
  150.     private $_consoleInfo = null;
  151.  
  152.     /**
  153.      * @return ffDataHolder
  154.      *
  155.      * go trough Post Single Meta -> Sitemap -> Theme Options
  156.      */
  157.     public function getCurrentLayoutInfo() {
  158.  
  159.         if( $this->_currentLayoutInfo != null ) {
  160.             return $this->_currentLayoutInfo;
  161.         }
  162.  
  163.         /*----------------------------------------------------------*/
  164.         /* CURRENT VIEW
  165.         /*----------------------------------------------------------*/
  166.         $currentView = $this->getCurrentViewInfo();
  167.  
  168.  
  169.  
  170.  
  171.         if( $currentView == null ) {
  172.             $layoutInfo = new ffDataHolder();
  173.             $layoutInfo->header = 'inherited';
  174.             $layoutInfo->titlebar = 'inherited';
  175.             $layoutInfo->layout = 'inherited';
  176.             $layoutInfo->footer = 'inherited';
  177.             $layoutInfo->boxed_wrapper = 'inherited';
  178.             if( in_array( $layoutInfo->header, array('inherit', 'inherited' ) ) ) {
  179.                 $layoutInfo->header = ffThemeOptions::getQuery()->getWithoutComparationDefault('theme_options global-layout header', 'header_default');
  180.             }
  181.  
  182.             if( in_array( $layoutInfo->titlebar, array('inherit', 'inherited' ) ) ) {
  183.                 $layoutInfo->titlebar = ffThemeOptions::getQuery()->getWithoutComparationDefault('theme_options global-layout titlebar', 'titlebar_default');
  184.             }
  185.  
  186.             if( in_array( $layoutInfo->footer, array('inherit', 'inherited' ) ) ) {
  187.                 $layoutInfo->footer = ffThemeOptions::getQuery()->getWithoutComparationDefault('theme_options global-layout footer', 'footer_default');
  188.             }
  189.  
  190.             if( in_array( $layoutInfo->boxed_wrapper, array('inherit', 'inherited' ) ) ) {
  191.                 $layoutInfo->boxed_wrapper = ffThemeOptions::getQuery()->getWithoutComparationDefault('theme_options global-layout boxed_wrapper', 'none');
  192.             }
  193.  
  194.             // $layoutInfo->layout = 'default_page__full_body';
  195.  
  196.             // $template = $this->getTemplate('default_page__full_body');
  197.             // $layoutInfo->layoutContent = $template->get('builder');
  198.  
  199.             $layoutInfo = apply_filters('ff_empty_layout', $layoutInfo);
  200.  
  201.             if( $layoutInfo->layout != 'inherited' ) {
  202.                 $template = $this->getTemplate( $layoutInfo->layout );
  203.                 $layoutInfo->layoutContent = $template->get('builder');
  204.             }
  205.  
  206.             return $layoutInfo;
  207.         }
  208.  
  209.  
  210.  
  211. //
  212.  
  213.  
  214.  
  215.         // we dont have any info for this
  216.         if( $currentView == null ) {
  217.             return null;
  218.         }
  219.  
  220.         /*----------------------------------------------------------*/
  221.         /* LAYOUT INFO
  222.         /*----------------------------------------------------------*/
  223.         $layoutInfo = new ffDataHolder();
  224.         $layoutInfo->header = 'inherited';
  225.         $layoutInfo->titlebar = 'inherited';
  226.         $layoutInfo->layout = 'inherited';
  227.         $layoutInfo->footer = 'inherited';
  228.         $layoutInfo->boxed_wrapper = 'inherited';
  229.  
  230.         $layoutInfo->setMeta('viewName', $currentView->name);
  231.         $layoutInfo->setMeta('viewType', $currentView->type );
  232.         $layoutInfo->setMeta('viewSubType', $currentView->sub_type );
  233.  
  234.         /*----------------------------------------------------------*/
  235.         /* LAYOUT CONSOLE INFO
  236.         /*----------------------------------------------------------*/
  237.         $consoleInfo = new ffDataHolder();
  238.         $consoleInfo->header = 'inherited';
  239.         $consoleInfo->header_set = 'inherited';
  240.  
  241.         $consoleInfo->titlebar = 'inherited';
  242.         $consoleInfo->titlebar_set = 'inherited';
  243.  
  244.         $consoleInfo->footer = 'inherited';
  245.         $consoleInfo->footer_set = 'inherited';
  246.  
  247.         $consoleInfo->boxed_wrapper = 'inherited';
  248.         $consoleInfo->boxed_wrapper_set = 'inherited';
  249.  
  250.         $consoleInfo->layout = 'inherited';
  251.         $consoleInfo->layout_set = 'inherited';
  252.  
  253.         $consoleInfo->viewName = $currentView->get('name');
  254.  
  255.  
  256.         $placements = array('header', 'titlebar', 'footer', 'boxed_wrapper' );
  257.         $inherit = array('inherit', 'inherited');
  258.  
  259.  
  260.  
  261.         if( $currentView->type == 'singular') {
  262.             $currentPostId = $this->_getWPLayer()->get_current_post()->ID;
  263.  
  264.             $builderSettings = new ffDataHolder();
  265.             $builderSettings->setDataJSON( $this->_getPostMeta()->getOption( $currentPostId, 'ff_builder_status'));
  266.  
  267.             $postLayoutSettings = new ffDataHolder($this->_getPostMeta()->getOptionCodedJSON( $currentPostId, 'ff-layout-settings', null ));
  268.  
  269.             $layoutInfo->header = $postLayoutSettings->get('settings header', 'inherited');
  270.             $layoutInfo->titlebar = $postLayoutSettings->get('settings titlebar', 'inherited');
  271.             $layoutInfo->layout = $postLayoutSettings->get('settings layout', 'inherited');
  272.             $layoutInfo->footer = $postLayoutSettings->get('settings footer', 'inherited');
  273.             $layoutInfo->boxed_wrapper = $postLayoutSettings->get('settings boxed_wrapper', 'inherited');
  274.  
  275.             $layoutInfo->builderUsage = $builderSettings->usage;
  276.             $layoutInfo->builderPrintingMode = $postLayoutSettings->get('settings builder-printing-mode', 'in-content');
  277.  
  278.  
  279.             foreach( $placements as $onePlacement ) {
  280.                 if( !in_array( $layoutInfo->$onePlacement, $inherit) ) {
  281.                     $setPlacement = $onePlacement .'_set';
  282.                     if( $consoleInfo->$setPlacement == 'inherited' ) {
  283.                         $consoleInfo->$setPlacement = 'singular';
  284.                     }
  285. //
  286.                 }
  287.             }
  288.  
  289.             $consoleInfo->layout_set = 'singular';
  290.  
  291.  
  292.         }
  293.  
  294.  
  295.  
  296.         // is layout inherit from sitemap, or has been set up in post writepanel?
  297.         if( $layoutInfo->layout == 'inherited' || $layoutInfo->layout == 'inherit' ) {
  298.  
  299.             $currentViewTemplate = $this->getTemplateForView( $currentView->name );
  300.  
  301.  
  302.  
  303.             $viewName = $currentView->name;
  304.             $wpmlBridge =$this->_getWPLayer()->getWPMLBridge();
  305.             if( $wpmlBridge->isWPMLActive() ) {
  306.                 $currentLangueage = $wpmlBridge->getCurrentLanguage();
  307.                 $viewName .= '-|-' . $currentLangueage;
  308.             }
  309.  
  310.             $currentViewTemplate = $this->getTemplateForView( $viewName );
  311.  
  312.  
  313.  
  314.  
  315. //          var_dump( $currentViewTemplate);
  316. //          die();
  317.             $consoleInfo->layout_set = 'sitepref';
  318.  
  319.         } else {
  320.             $currentViewTemplate = $this->getTemplate( $layoutInfo->layout );
  321.         }
  322.         $currentViewTemplate = new ffDataHolder( $currentViewTemplate->getData());
  323.  
  324.  
  325.         $consoleInfo->layout_name = $currentViewTemplate->get('name');
  326. //      $consoleInfo->layout = $currentViewTemplate->get('id');
  327.  
  328.  
  329.         /*----------------------------------------------------------*/
  330.         /* GETTING INFOS FROM LAYOUTS
  331.         /*----------------------------------------------------------*/
  332.         if( $layoutInfo->layout != 'none' ) {
  333.             if( $layoutInfo->header == 'inherited' || $layoutInfo->header == 'inherit' ) {
  334.                 $layoutInfo->header = $currentViewTemplate->get('options sitepref header');
  335.             }
  336.  
  337.             if( $layoutInfo->titlebar == 'inherited' || $layoutInfo->titlebar == 'inherit' ) {
  338.                 $layoutInfo->titlebar = $currentViewTemplate->get('options sitepref titlebar');
  339.             }
  340.  
  341.             if( $layoutInfo->footer == 'inherited' || $layoutInfo->footer == 'inherit' ) {
  342.                 $layoutInfo->footer = $currentViewTemplate->get('options sitepref footer');
  343.             }
  344.  
  345.             if( $layoutInfo->boxed_wrapper == 'inherited' || $layoutInfo->boxed_wrapper == 'inherit' ) {
  346.                 $layoutInfo->boxed_wrapper = $currentViewTemplate->get('options sitepref boxed_wrapper', 'inherit');
  347.             }
  348.  
  349.             foreach( $placements as $onePlacement ) {
  350.                 if( !in_array( $layoutInfo->$onePlacement, $inherit) ) {
  351.                     $setPlacement = $onePlacement .'_set';
  352.                     if( $consoleInfo->$setPlacement == 'inherited' ) {
  353.                         $consoleInfo->$setPlacement = 'sitepref';
  354.                     }
  355. //
  356.                 }
  357.             }
  358.         }
  359.         else {
  360.  
  361.             if( $layoutInfo->header == 'inherited' || $layoutInfo->header == 'inherit' ) {
  362.                 $layoutInfo->header = 'none';
  363.             }
  364.  
  365.             if( $layoutInfo->titlebar == 'inherited' || $layoutInfo->titlebar == 'inherit' ) {
  366.                 $layoutInfo->titlebar = 'none';
  367.             }
  368.  
  369.             if( $layoutInfo->footer == 'inherited' || $layoutInfo->footer == 'inherit' ) {
  370.                 $layoutInfo->footer = 'none';
  371.             }
  372.  
  373.             if( $layoutInfo->boxed_wrapper == 'inherited' || $layoutInfo->boxed_wrapper == 'inherit' ) {
  374.                 $layoutInfo->boxed_wrapper = 'none';
  375.             }
  376.  
  377.             foreach( $placements as $onePlacement ) {
  378. //              if( !in_array( $layoutInfo->$onePlacement, $inherit) ) {
  379.                 $setPlacement = $onePlacement .'_set';
  380.                 if( $consoleInfo->$setPlacement == 'inherited' ) {
  381.                     $consoleInfo->$setPlacement = 'singular';
  382.                 }
  383. //
  384. //              }
  385.             }
  386.         }
  387.  
  388.  
  389.         if( in_array( $layoutInfo->header, array('inherit', 'inherited' ) ) ) {
  390.             $layoutInfo->header = ffThemeOptions::getQuery()->getWithoutComparationDefault('theme_options global-layout header', 'header_default');
  391.         }
  392.  
  393.         if( in_array( $layoutInfo->titlebar, array('inherit', 'inherited' ) ) ) {
  394.             $layoutInfo->titlebar = ffThemeOptions::getQuery()->getWithoutComparationDefault('theme_options global-layout titlebar', 'titlebar_default');
  395.         }
  396.  
  397.         if( in_array( $layoutInfo->footer, array('inherit', 'inherited' ) ) ) {
  398.             $layoutInfo->footer = ffThemeOptions::getQuery()->getWithoutComparationDefault('theme_options global-layout footer', 'footer_default');
  399.         }
  400.  
  401.         if( in_array( $layoutInfo->boxed_wrapper, array('inherit', 'inherited' ) ) ) {
  402.             $layoutInfo->boxed_wrapper = ffThemeOptions::getQuery()->getWithoutComparationDefault('theme_options global-layout boxed_wrapper', 'none');
  403.         }
  404.  
  405.         if( ($layoutInfo->builderUsage == 'used' && $layoutInfo->builderPrintingMode == 'override-layout') || $layoutInfo->layout == 'none' ) {
  406.             $layoutInfo->layout = 'singular';
  407.             $layoutInfo->layoutContent = $this->_getWPLayer()->get_current_post()->post_content;
  408.         } else if( $currentViewTemplate->get('builder') != null ) {
  409.             $layoutInfo->layout = 'layout';
  410.             $layoutInfo->layoutContent = $currentViewTemplate->get('builder');
  411.         } else {
  412.             $layoutInfo->layout = null;
  413.  
  414.  
  415.         }
  416.  
  417.         foreach( $placements as $onePlacement ) {
  418.             if( !in_array( $layoutInfo->$onePlacement, $inherit) ) {
  419.                 $setPlacement = $onePlacement .'_set';
  420.                 if( $consoleInfo->$setPlacement == 'inherited' ) {
  421.                     $consoleInfo->$setPlacement = 'themeopt';
  422.                 }
  423. //
  424.             }
  425.  
  426.             $consoleInfo->$onePlacement = $layoutInfo->$onePlacement;
  427.         }
  428.  
  429.  
  430.         $this->_currentLayoutInfo = $layoutInfo;
  431.         $this->_consoleInfo = $consoleInfo;
  432.  
  433.         $layoutInfo = apply_filters('ff_layout_info', $layoutInfo);
  434.  
  435.         return $layoutInfo;
  436.     }
  437.  
  438.     public function getConsoleInfo() {
  439.         return $this->_consoleInfo;
  440.     }
  441.  
  442.     private $_currentViewInfo = null;
  443.  
  444.     private function getCurrentViewInfo() {
  445.  
  446.         if( $this->_currentViewInfo != null ) {
  447.             return $this->_currentViewInfo;
  448.         }
  449.  
  450.         $currentView = new ffDataHolder();
  451.  
  452.         $identificator = ffContainer()->getFrontendQueryIdentificator();
  453.         $WPLayer = ffContainer()->getWPLayer();
  454.  
  455.         $queryInformations = $identificator->getQueryInformations();
  456.  
  457.  
  458.         if( !isset( $queryInformations->query) ) {
  459.             return null;
  460.         }
  461.  
  462.  
  463. //      $viewName = null;
  464.  
  465.         if( $queryInformations->query == 'singular' ) {
  466.             $currentView->type = 'singular';
  467.  
  468.             if( $queryInformations->post_type == 'post' ) {
  469.                 $currentView->name = 'post';
  470.             } else if( $queryInformations->post_type == 'page' ) {
  471.                 $currentView->name = str_replace('.php', '', basename($WPLayer->get_page_template()) );
  472.             } else {
  473.                 $currentView->name = $queryInformations->post_type;
  474.             }
  475.  
  476.         }
  477.  
  478.         else if( $queryInformations->query == 'taxonomy' ) {
  479.             $currentView->type = 'archive';
  480.             $currentView->sub_type = 'taxonomy';
  481.  
  482.  
  483.             if( $queryInformations->taxonomy_type == 'category' || $queryInformations->taxonomy_type == 'post_tag' ) {
  484.                 $currentView->name = 'blog-archive';
  485.             }
  486.  
  487.             else if( $queryInformations->taxonomy_type == 'ff-portfolio-category' || $queryInformations->taxonomy_type == 'ff-portfolio-tag' ) {
  488.                 $currentView->type = 'archive';
  489.                 $currentView->sub_type = 'post_type_archive';
  490.                 $currentView->name = 'portfolio_archive';
  491.             } else if( $queryInformations->taxonomy_type == 'product_cat' || $queryInformations->taxonomy_type == 'product_tag' ) {
  492.                 $currentView->type = 'archive';
  493.                 $currentView->sub_type = 'post_type_archive';
  494.                 $currentView->name = 'product_archive';
  495.             } else {
  496.                 $currentView->name = $queryInformations->taxonomy_type;
  497. //              var_Dump( $queryInformations );
  498. //              die();
  499.             }
  500.  
  501.  
  502.  
  503.  
  504.         }
  505.         else if( $queryInformations->query == 'author') {
  506.             $currentView->type = 'archive';
  507.             $currentView->sub_type = 'author';
  508.             $currentView->name = 'blog-archive';
  509.         }
  510.         else if( $queryInformations->query == 'date' ) {
  511.             $currentView->type = 'archive';
  512.             $currentView->sub_type = 'date';
  513.             $currentView->name = 'blog-archive';
  514.         }
  515.         else if( $queryInformations->query == 'search' ) {
  516. //          var_Dump( $queryInformations );
  517. //          die();
  518.             if( $queryInformations->posts_found == 0 ) {
  519.                 $currentView->type='search-not';
  520.                 $currentView->name = 'search-not';
  521.             } else {
  522.                 $currentView->type='search';
  523.                 $currentView->name = 'search';
  524.             }
  525.         } else if( $queryInformations->query == '404' ) {
  526.             $currentView->type = '404';
  527.             $currentView->name ='404';
  528.         }
  529.  
  530.         else if( $queryInformations->query == 'home' ) {
  531.  
  532.  
  533.  
  534. //          $currentView->type = 'home';
  535. //          $currentView->name ='home';
  536.             $currentView->type = 'archive';
  537.             $currentView->sub_type = 'author';
  538.             $currentView->name = 'blog-archive';
  539.         }
  540.  
  541.         else if( $queryInformations->query == 'post_type_archive' ) {
  542.             $currentView->type = 'archive';
  543.             $currentView->sub_type = 'post_type_archive';
  544.             $currentView->name = $queryInformations->type . '_archive';
  545.         }
  546.  
  547.  
  548.  
  549.  
  550.         $this->_currentViewInfo = $currentView;
  551.         return $currentView;
  552.     }
  553.  
  554.  
  555.     /**********************************************************************************************************************/
  556.     /* PUBLIC FUNCTIONS
  557.     /**********************************************************************************************************************/
  558.     public function getTemplate( $templateId ) {
  559.         return $this->_getTemplatesCollection()->getItemById( $templateId );
  560.     }
  561.  
  562.     public function setTemplate( $templateId, $item ) {
  563.         return $this->_getTemplatesCollection()->setItemToDb( $templateId, $item );
  564.     }
  565.  
  566.     public function addTemplate( $templateId, $templateName ) {
  567.         $this->_getTemplatesCollection()->setItemToDb( $templateId, array('name'=> $templateName ) );
  568.     }
  569.  
  570.     public function deleteTemplate( $templateId ) {
  571.         return $this->_getTemplatesCollection()->deleteItemFromDB( $templateId );
  572.     }
  573.  
  574.     public function saveTemplatesCollection() {
  575.         $this->_getTemplatesCollection()->save();
  576.     }
  577.  
  578.  
  579.     public function getTemplateForView( $viewId ) {
  580.  
  581. //      var_dump( $viewId );
  582. //      die();
  583. //      $wpmlBridge =$this->_getWPLayer()->getWPMLBridge();
  584. //      if( $wpmlBridge->isWPMLActive() ) {
  585. //          $currentLangueage = $wpmlBridge->getCurrentLanguage();
  586. //          $viewId .= '-|-' . $currentLangueage;
  587. //      }
  588.  
  589.  
  590.  
  591.         $parents = $this->_getSiteMapper()
  592.             ->getViewParents( $viewId  );
  593.  
  594.  
  595.         $assignedTemplate = null;
  596.  
  597.         foreach( $parents as $key => $oneParent ) {
  598.             $assignedTemplate = $this->_getViewsMapCollection()->getItemById( $oneParent );
  599.  
  600.             if( $assignedTemplate->getData() != null ) {
  601.                 $assignedTemplate = $this->_getTemplatesCollection()->getItemById( $assignedTemplate->getData() );
  602.  
  603.                 if( $key > 0 ) {
  604.                     $viewInfo = $this->_getSiteMapper()->getViewFromId( $oneParent );
  605.  
  606.                     $assignedTemplate->setAttr('inherited', true);
  607.                     $assignedTemplate->setAttr('parent-name', $viewInfo['name'] );
  608.                     $assignedTemplate->setAttr('parent-id', $viewInfo['id'] );
  609.                 } else {
  610.                     $assignedTemplate->setAttr('inherited', false);
  611.                 }
  612.  
  613.                 break;
  614.             }
  615.         }
  616.  
  617.         return $assignedTemplate;
  618.     }
  619.  
  620.     public function assignTemplateForView( $templateId, $viewId ) {
  621.         $this->_getViewsMapCollection()->setItemToDb( $viewId, $templateId);
  622.     }
  623.  
  624.     public function deleteTemplateForView( $viewId ) {
  625.         $this->_getViewsMapCollection()->deleteItemFromDB( $viewId );
  626.     }
  627.  
  628.  
  629.     public function getViewsWithMappedItems() {
  630.  
  631.  
  632.         $views = array();
  633.  
  634.  
  635.         foreach( $this->_getViewsMapCollection() as $itemId =>  $oneItemToViewMap ) {
  636.  
  637.             $viewId = $oneItemToViewMap->getData();
  638. //          var_Dump( $viewId );
  639.             if( !isset($views[ $viewId ]) ) {
  640.                 $views[$viewId] = array();
  641.             }
  642.  
  643.  
  644.  
  645.             $views[ $viewId ][] = $itemId;
  646.         }
  647.  
  648.         foreach( $this->_getTemplatesCollection() as $itemId => $oneItem ) {
  649.             if( isset( $views[ $itemId ] ) ) {
  650.                 $oneItem->set('assigned_items', $views[$itemId] );
  651.             }
  652.         }
  653.  
  654. //      var_dump( $this->_getTemplatesCollection() );
  655. //      die();
  656.  
  657.         return $this->_getTemplatesCollection();
  658.  
  659.     }
  660.  
  661.  
  662. //
  663.     public function getOptionsForView( $viewId ) {
  664.         $viewData = $this->getDataForView( $viewId );
  665.         return $viewData->get('options');
  666.  
  667.     }
  668.  
  669.     public function getTemplatesCollection() {
  670.         return $this->_getTemplatesCollection();
  671.     }
  672.  
  673.     public function getViewsMapCollection() {
  674.         return $this->_getViewsMapCollection();
  675.     }
  676.  
  677.  
  678.     /**********************************************************************************************************************/
  679.     /* PUBLIC PROPERTIES
  680.     /**********************************************************************************************************************/
  681.  
  682.  
  683.     /**********************************************************************************************************************/
  684.     /* PRIVATE FUNCTIONS
  685.     /**********************************************************************************************************************/
  686.  
  687.  
  688.     /**********************************************************************************************************************/
  689.     /* ABSTRACT FUNCTIONS
  690.     /**********************************************************************************************************************/
  691.  
  692.  
  693.     /**********************************************************************************************************************/
  694.     /* PRIVATE GETTERS & SETTERS
  695.     /**********************************************************************************************************************/
  696.  
  697.     /**
  698.      * @return ffOptionsCollection
  699.      */
  700.     private function _getViewsMapCollection() {
  701.         return $this->_viewsMapCollection;
  702.     }
  703.  
  704.     /**
  705.      * @param ffOptionsCollection $viewsMapCollection
  706.      */
  707.     private function _setViewsMapCollection($viewsMapCollection) {
  708.         $this->_viewsMapCollection = $viewsMapCollection;
  709.     }
  710.  
  711.     /**
  712.      * @return ffOptionsCollection
  713.      */
  714.     private function _getTemplatesCollection() {
  715.         return $this->_templatesCollection;
  716.     }
  717.  
  718.     /**
  719.      * @param ffOptionsCollection $viewsDataCollection
  720.      */
  721.     private function _setTemplatesCollection($templatesCollection) {
  722.         $this->_templatesCollection = $templatesCollection;
  723.     }
  724.  
  725.     /**
  726.      * @return ffSiteMapper
  727.      */
  728.     private function _getSiteMapper() {
  729.         return $this->_siteMapper;
  730.     }
  731.  
  732.     /**
  733.      * @param ffSiteMapper $siteMapper
  734.      */
  735.     private function _setSiteMapper($siteMapper) {
  736.         $this->_siteMapper = $siteMapper;
  737.     }
  738.  
  739.     /**
  740.      * @return ffWPLayer
  741.      */
  742.     private function _getWPLayer() {
  743.         return $this->_WPLayer;
  744.     }
  745.  
  746.     /**
  747.      * @param ffWPLayer $WPLayer
  748.      */
  749.     private function _setWPLayer($WPLayer) {
  750.         $this->_WPLayer = $WPLayer;
  751.     }
  752.  
  753.     /**
  754.      * @return ffDataStorage_WPPostMetas
  755.      */
  756.     private function _getPostMeta() {
  757.         return $this->_postMeta;
  758.     }
  759.  
  760.     /**
  761.      * @param ffDataStorage_WPPostMetas $postMeta
  762.      */
  763.     private function _setPostMeta($postMeta) {
  764.         $this->_postMeta = $postMeta;
  765.     }
  766.  
  767.  
  768. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top