Frontend
[ class tree: Frontend ] [ index: Frontend ] [ all elements ]

Source for file View.php

Documentation is available at View.php

  1. <?php
  2. /**
  3. * DotBoost Technologies Inc.
  4. * DotKernel Application Framework
  5. *
  6. @category   DotKernel
  7. @package    Frontend
  8. @copyright  Copyright (c) 2009 DotBoost  Technologies (http://www.dotboost.com)
  9. @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  10. @version    $Id: View.php 158 2010-06-25 08:59:20Z teo $
  11. */
  12.  
  13. /**
  14. * View Model
  15. * abstract over the Dot_Template class
  16. @category   DotKernel
  17. @package    Frontend
  18. @author     DotKernel Team <team@dotkernel.com>
  19. */
  20.  
  21. class View extends Dot_Template
  22. {
  23.     /**
  24.      * Singleton instance
  25.      * @access protected
  26.      * @static
  27.      * @var Dot_Template 
  28.      */
  29.     protected static $_instance null;
  30.     /**
  31.      * Returns an instance of Dot_View
  32.      * Singleton pattern implementation
  33.      * @access public
  34.      * @param string $root     Template root directory
  35.      * @param string $unknowns How to handle unknown variables
  36.      * @param array  $fallback Fallback paths
  37.      * @return Dot_Template 
  38.      */
  39.     public static function getInstance($root '.'$unknowns 'remove'$fallback='')
  40.     {
  41.         if (null === self::$_instance{
  42.             self::$_instance new self($root$unknowns$fallback);
  43.         }
  44.         return self::$_instance;
  45.     }    
  46.     /**
  47.      * Initalize some parameter
  48.      * @access public
  49.      * @param string $requestModule 
  50.      * @param string $requestController 
  51.      * @param string $requestAction 
  52.      * @return void 
  53.      */    
  54.     public function init($requestModule$requestController$requestAction)
  55.     {
  56.         $this->requestModule $requestModule;
  57.         $this->requestController $requestController;
  58.         $this->requestAction $requestAction;
  59.     }
  60.     /**
  61.      * Set the template file
  62.      * @access public
  63.      * @return void 
  64.      */
  65.     public function setViewFile()
  66.     {
  67.         $this->setFile('tpl_index''index.tpl');
  68.     }
  69.     /**
  70.      * Set different paths url(site, templates, images)
  71.      * @access public
  72.      * @param Zend_Config_Ini $config 
  73.      * @return void 
  74.      */
  75.     public function setViewPaths($config)
  76.     {
  77.         $this->setVar('TEMPLATES_URL'$config->website->params->url TEMPLATES_DIR);
  78.         $this->setVar('IMAGES_URL'$config->website->params->url IMAGES_DIR '/' .$this->requestModule);
  79.         $this->setVar('SITE_URL'$config->website->params->url);
  80.     }
  81.     /**
  82.      * Set SEO values
  83.      * @access public
  84.      * @param string $pageTitle [optional]
  85.      * @return void 
  86.      */
  87.     public function setSeoValues($pageTitle '')
  88.     {
  89.         $seo new Dot_Seo();
  90.         $option $seo->getOption();
  91.         $this->setVar('PAGE_KEYWORDS'$option->defaultMetaKeywords);
  92.         $this->setVar('PAGE_DESCRIPTION'$option->defaultMetaDescription);
  93.         $this->setVar('PAGE_TITLE'$option->defaultPageTitle .  ' | ' $pageTitle);
  94.         $this->setVar('PAGE_CONTENT_TITLE'$pageTitle);
  95.         $this->setVar('SITE_NAME'$option->siteName);
  96.         $this->setVar('CANONICAL_URL'$option->canonicalUrl);
  97.     }
  98.     /**
  99.      * Display the specific menu that were declared in configs/menu.xml file
  100.      * @access public
  101.      * @param Zend_Config_Ini $config 
  102.      * @param string $requestController 
  103.      * @param string $requestAction 
  104.      * @return void 
  105.      */
  106.     public function setViewMenu($config)
  107.     {        
  108.         $menu_xml new Zend_Config_Xml(CONFIGURATION_PATH '/' $this->requestModule '/' 'menu.xml''config');
  109.         $menu $menu_xml->menu;
  110.         // if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero)
  111.         if(is_null($menu->{0}))
  112.         {
  113.             $menu new Zend_Config(array(0=>$menu_xml->menu));                        
  114.         }
  115.         foreach ($menu as $child)
  116.         {    
  117.             //don't display the menu
  118.             if(== $child->displaycontinue;        
  119.             $this->setFile('tpl_menu_'.$child->id'blocks/menu_'.$child->type.'.tpl');
  120.             //is not simple menu, so let's set the submenu blocks and variables
  121.             if(strpos($child->type,'simple'=== FALSE)
  122.             {                
  123.                 $this->setBlock('tpl_menu_'.$child->id'top_sub_menu_item''top_sub_menu_item_block');
  124.                 $this->setBlock('tpl_menu_'.$child->id'top_sub_menu''top_sub_menu_block');
  125.                 $this->setBlock('tpl_menu_'.$child->id'top_normal_menu_item''top_normal_menu_item_block');
  126.                 $this->setBlock('tpl_menu_'.$child->id'top_parent_menu_item''top_parent_menu_item_block');
  127.                 $tplVariables1 array('TOP_MENU_ID'
  128.                                        'TOP_SUB_MENU_SEL'
  129.                                        'TOP_SUB_MENU_ITEM_SEL'
  130.                                        'TOP_SUB_MENU_LINK'
  131.                                        'TOP_SUB_MENU_TARGET'
  132.                                        'TOP_SUB_MENU_TITLE');                
  133.                 $tplBlocks1 array('top_sub_menu_item_block'
  134.                                     'top_sub_menu_block'
  135.                                     'top_normal_menu_item_block'
  136.                                     'top_parent_menu_item_block');
  137.             }            
  138.             $this->setBlock('tpl_menu_'.$child->id'top_menu_item''top_menu_item_block');
  139.             $this->setBlock('tpl_menu_'.$child->id'top_menu''top_menu_block');
  140.             
  141.             $tplVariables2 array('TOP_MENU_SEL'
  142.                                    'TOP_MENU_LINK'
  143.                                    'TOP_MENU_TARGET'
  144.                                    'TOP_MENU_TITLE');
  145.             $tplBlocks2 array('top_menu_item_block''top_menu_block');
  146.             
  147.             //Initialize all the tag variables and blocks
  148.             $this->initVar(array_merge($tplVariables1,$tplVariables2),'');            
  149.             $this->initBlock(array_merge($tplBlocks1,$tplBlocks2),'');
  150.             
  151.             $i 0;                    
  152.             $items $child->item;
  153.             // if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero)
  154.             if(is_null($items->{0}))
  155.             {
  156.                 $items new Zend_Config(array(0=>$child->item));                        
  157.             }            
  158.             foreach($items as $key => $val)
  159.             {                        
  160.                 if ((Dot_Auth::hasIdentity('user'&& == $val->isLogged|| (!Dot_Auth::hasIdentity('user'&& == $val->notLogged))
  161.                 {    // display menus based on user is logged in or not
  162.                     $this->setVar('TOP_MENU_ID'$i);
  163.                     $tplVariables array('TOP_MENU_SEL'
  164.                                           'TOP_SUB_MENU_SEL'
  165.                                           'TOP_SUB_MENU_ITEM_SEL');
  166.                     $this->initVar($tplVariables,'');    
  167.                     if (false !== stripos($val->link$this->requestController.'/'.$this->requestAction.'/'))
  168.                     {    //if current menu is the current viewed page
  169.                         $this->setVar('TOP_MENU_SEL''_selected');
  170.                         $this->setVar('TOP_SUB_MENU_SEL''_selected');
  171.                     }
  172.                     elseif('vertical' == $child->type && FALSE === strpos($child->type,'simple'))
  173.                     {
  174.                         $this->parse('top_sub_menu_block''');
  175.                     }
  176.                     foreach ($val as $k => $v
  177.                     {    
  178.                         $this->setVar('TOP_MENU_'.strtoupper($k)is_string($v$v '');
  179.                     }    
  180.                     if (== $val->external
  181.                     {
  182.                         $this->setVar('TOP_MENU_LINK'$val->link);
  183.                     }
  184.                     else
  185.                     {
  186.                         $this->setVar('TOP_MENU_LINK'$config->website->params->url.'/'.$val->link);    
  187.                     
  188.                     if(FALSE === strpos($child->type,'simple'))
  189.                     {                                                        
  190.                         if ((string)$val->link != '')
  191.                         {
  192.                             $this->parse('top_normal_menu_item_block''top_normal_menu_item'true);
  193.                         }                                 
  194.                         else
  195.                         {
  196.                             $this->parse('top_parent_menu_item_block''top_parent_menu_item'true);
  197.                         
  198.                         if (isset($val->subItems->subItem&& count($val->subItems->subItem0)
  199.                         {
  200.                                                 
  201.                             $subItems $val->subItems->subItem;
  202.                             // if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero)
  203.                             if(is_null($subItems->{0}))
  204.                             {
  205.                                 $subItems new Zend_Config(array(0=>$subItems));                        
  206.                             }                            
  207.                             foreach ($subItems as $k2 => $v2)
  208.                             {            
  209.                                 if ((Dot_Auth::hasIdentity('user'&& == $v2->isLogged|| (!Dot_Auth::hasIdentity('user'&& == $v2->notLogged))
  210.                                 {                
  211.                                     // display menus based on user is logged in or not        
  212.                                     $this->setVar('TOP_SUB_MENU_ITEM_SEL''');                                                
  213.                                     foreach ($v2 as $k => $v)
  214.                                     {
  215.                                         $this->setVar('TOP_SUB_MENU_'.strtoupper($k)is_string($v$v '');
  216.                                     }
  217.                                     if (== $v2->external
  218.                                     {
  219.                                         $this->setVar('TOP_SUB_MENU_LINK'$v2->link);
  220.                                     }
  221.                                     else 
  222.                                     {
  223.                                         $this->setVar('TOP_SUB_MENU_LINK'$config->website->params->url.'/'.$v2->link);
  224.                                     }
  225.                                     if (FALSE  !==stripos($v2->link$this->requestController.'/'.$this->requestAction.'/'))
  226.                                     {    //if curent menu is the curent viewed page then parent menu will be selected and sub menu shown
  227.                                         $tplVariables array('TOP_MENU_SEL'
  228.                                                               'TOP_SUB_MENU_SEL'
  229.                                                               'TOP_SUB_MENU_ITEM_SEL');
  230.                                         $this->initVar($tplVariables,'_selected');                                            
  231.                                     }    
  232.                                     $this->parse('top_sub_menu_item_block''top_sub_menu_item'true);                                                
  233.                                 }
  234.                             }
  235.                         }                        
  236.                     }
  237.                     if(strpos($child->type,'simple'=== FALSE)
  238.                     {
  239.                         $this->parse('top_sub_menu_block''top_sub_menu'true);
  240.                         $this->parse('top_sub_menu_item_block''');    
  241.                     }
  242.                     $this->parse('top_menu_item_block''top_menu_item'true);    
  243.                     if(strpos($child->type,'simple'=== FALSE)
  244.                     {
  245.                         $this->parse('top_normal_menu_item_block''');
  246.                         $this->parse('top_parent_menu_item_block''');
  247.                     }                                                
  248.                     $i++;                
  249.                 }    
  250.             }                    
  251.             $this->parse('top_menu_block''top_menu'true);
  252.             $this->parse('top_menu_item_block''');
  253.             $this->parse('MENU_'.$child->id'tpl_menu_'.$child->id);
  254.         }
  255.     }
  256.     /**
  257.      * Display login box if user is not logged
  258.      * @access public
  259.      * @return void 
  260.      */
  261.     public function setLoginBox()
  262.     {
  263.         if (!Dot_Auth::hasIdentity('user'))
  264.         {
  265.             $this->setFile('tpl_login''blocks/login_box.tpl');
  266.             $this->parse('LOGIN_BOX''tpl_login');
  267.         }
  268.         else
  269.         {
  270.             $this->setVar('LOGIN_BOX''');
  271.         }
  272.     }
  273.     /**
  274.      * Display message - error, warning, info
  275.      * @access public
  276.      * @return void 
  277.      */
  278.     public function displayMessage()
  279.     {
  280.         $session Zend_Registry::get('session');        
  281.         if(isset($session->message))
  282.         {
  283.             $this->setFile('tpl_msg''blocks/message.tpl');
  284.             $this->setBlock('tpl_msg''msg_array''msg_array_row');
  285.             $this->setVar('MESSAGE_TYPE'$session->message['type']);
  286.             if(is_array($session->message['txt']))
  287.             {            
  288.                 foreach ($session->message['txt'as $k => $msg)
  289.                 {
  290.                     $this->setVar('MESSAGE_ARRAY'is_string($k$msg ucfirst($k' - ' $msg $msg);
  291.                     $this->parse('msg_array_row''msg_array'true);
  292.                 }
  293.             }
  294.             else
  295.             {
  296.                 $this->parse('msg_array_row''');
  297.                 $this->setVar('MESSAGE_STRING'$session->message['txt']);
  298.             }
  299.             $this->parse('MESSAGE_BLOCK''tpl_msg');
  300.             unset($session->message);
  301.         }        
  302.     }
  303. }

Documentation generated on Wed, 21 Jul 2010 07:34:49 +0000 by phpDocumentor 1.4.3