Admin
[ class tree: Admin ] [ index: Admin ] [ 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    Admin
  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 161 2010-06-29 11:17:38Z teo $
  11. */
  12.  
  13. /**
  14. * Admin View
  15. * abstract over the Dot_Template class
  16. @category   DotKernel
  17. @package    Admin
  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.      * @static
  35.      * @param string $root     Template root directory
  36.      * @param string $unknowns How to handle unknown variables
  37.      * @param array  $fallback Fallback paths
  38.      * @return Dot_Template 
  39.      */
  40.     public static function getInstance($root '.'$unknowns 'remove'$fallback='')
  41.     {
  42.         if (null === self::$_instance{
  43.             self::$_instance new self($root$unknowns$fallback);
  44.             self::$_instance->settings Zend_Registry::get('settings');
  45.         }
  46.         return self::$_instance;
  47.     }    
  48.     /**
  49.      * Initalize some parameter
  50.      * @access public
  51.      * @param string $requestModule 
  52.      * @param string $requestController 
  53.      * @param string $requestAction 
  54.      * @return void 
  55.      */
  56.     public function init($requestModule$requestController$requestAction)
  57.     {
  58.         $this->requestModule $requestModule;
  59.         $this->requestController $requestController;
  60.         $this->requestAction $requestAction;
  61.     }
  62.     /**
  63.      * Set the template file
  64.      * @access public
  65.      * @return void 
  66.      */
  67.     public function setViewFile()
  68.     {
  69.         $this->setFile('tpl_index''index.tpl');
  70.     }    
  71.     /**
  72.      * Set different paths url(site, templates, images)
  73.      * @access public
  74.      * @param Zend_Config_Ini $config 
  75.      * @return void 
  76.      */
  77.     public function setViewPaths($config)
  78.     {
  79.         $this->setVar('TEMPLATES_URL'$config->website->params->url TEMPLATES_DIR);
  80.         $this->setVar('IMAGES_URL'$config->website->params->url IMAGES_DIR '/' .$this->requestModule);
  81.         $this->setVar('IMAGES_SHORT_URL'$config->website->params->url IMAGES_DIR);
  82.         $this->setVar('SITE_URL'$config->website->params->url);
  83.     }
  84.     /**
  85.      * Set SEO values
  86.      * @access public
  87.      * @param string $pageTitle [optional]
  88.      * @return void 
  89.      */
  90.     public function setSeoValues($pageTitle '')
  91.     {
  92.         $seo new Dot_Seo();
  93.         $option $seo->getOption();
  94.         $this->setVar('PAGE_KEYWORDS'$option->defaultMetaKeywords);
  95.         $this->setVar('PAGE_DESCRIPTION'$option->defaultMetaDescription);
  96.         $this->setVar('PAGE_TITLE'$option->defaultPageTitle .  ' | ' $pageTitle);
  97.         $this->setVar('PAGE_CONTENT_TITLE'$pageTitle);
  98.         $this->setVar('SITE_NAME'$option->siteName);
  99.     }
  100.     /**
  101.      * Display the specific menu that were declared in configs/menu.xml file
  102.      * @access public
  103.      * @param Zend_Config_Ini $config 
  104.      * @return void 
  105.      */
  106.         /**
  107.      * Display the specific menu that were declared in configs/menu.xml file
  108.      * @access public
  109.      * @param Zend_Config_Ini $config 
  110.      * @return void 
  111.      */
  112.     public function setViewMenu($config)
  113.     {        
  114.         if(Dot_Auth::hasIdentity('admin'))
  115.         {
  116.             $menu_xml new Zend_Config_Xml(CONFIGURATION_PATH '/' $this->requestModule '/' 'menu.xml''config');
  117.             $menu $menu_xml->menu;
  118.             // if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero)
  119.             if(is_null($menu->{0}))
  120.             {
  121.                 $menu new Zend_Config(array(0=>$menu_xml->menu));                        
  122.             }
  123.             foreach ($menu as $child)
  124.             {    
  125.                 //don't display the menu
  126.                 if(== $child->displaycontinue;        
  127.                 $this->setFile('tpl_menu_'.$child->id'blocks/menu_'.$child->type.'.tpl');
  128.                 $this->setBlock('tpl_menu_'.$child->id'top_normal_sub_menu_item''top_normal_sub_menu_item_block');
  129.                 $this->setBlock('tpl_menu_'.$child->id'top_sub_menu_item''top_sub_menu_item_block');
  130.                 $this->setBlock('tpl_menu_'.$child->id'top_normal_menu_item''top_normal_menu_item_block');
  131.                 $this->setBlock('tpl_menu_'.$child->id'top_menu_item''top_menu_item_block');
  132.                 $this->setBlock('tpl_menu_'.$child->id'top_menu''top_menu_block');                
  133.                 $tplVariables array('TOP_MENU_SEL'
  134.                                       'TOP_MENU_LINK'
  135.                                       'TOP_MENU_TARGET'
  136.                                       'TOP_MENU_TITLE'
  137.                                       'TOP_SUB_MENU_LINK'
  138.                                       'TOP_SUB_MENU_TARGET'
  139.                                       'TOP_SUB_MENU_TITLE');                
  140.                 $tplBlocks array('top_menu_block'
  141.                                    'top_menu_item_block'
  142.                                    'top_normal_menu_item_block'
  143.                                    'top_sub_menu_item_block',
  144.                                    'top_normal_submenu_item_block');                
  145.                 //Initialize all the tag variables and blocks
  146.                 $this->initVar($tplVariables,'');            
  147.                 $this->initBlock($tplBlocks,'');
  148.                 $i 0;                    
  149.                 $items $child->item;
  150.                 // if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero)
  151.                 if(is_null($items->{0}))
  152.                 {
  153.                     $items new Zend_Config(array(0=>$child->item));                        
  154.                 }            
  155.                 foreach ($items as $key => $val)
  156.                 {        
  157.                     $this->setVar('TOP_MENU_ID'$i);
  158.                     $tplVariables array('TOP_MENU_SEL'
  159.                                           'TOP_SUB_MENU_SEL'
  160.                                           'TOP_SUB_MENU_ITEM_SEL');
  161.                     $this->initVar($tplVariables,'');
  162.                     if (FALSE !== stripos($val->link$this->requestController.'/'))
  163.                     {    //if curent menu is the curent viewed page
  164.                         $this->setVar('TOP_MENU_SEL''_selected');
  165.                     }                            
  166.                     $this->setVar('TOP_MENU_TITLE'$val->title);
  167.                     $this->setVar('TOP_MENU_LINK'$config->website->params->url.'/'.$this->requestModule.'/'.$val->link);
  168.                     $this->setVar('TOP_MENU_DESCRIPTION'$val->description);                                                    
  169.                     $this->parse('top_normal_menu_item_block''top_normal_menu_item'true);
  170.                     if (isset($val->subItems->subItem&& count($val->subItems->subItem0)
  171.                     {                                            
  172.                         $subItems $val->subItems->subItem;
  173.                         // if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero)
  174.                         if(is_null($subItems->{0}))
  175.                         {
  176.                             $subItems new Zend_Config(array(0=>$subItems));                        
  177.                         }    
  178.                         $this->parse('top_normal_sub_menu_item_block''');                        
  179.                         foreach ($subItems as $k2 => $v2)
  180.                         {            
  181.                             $this->setVar('TOP_SUB_MENU_SEL''');
  182.                             $this->setVar('TOP_SUB_MENU_TITLE'$v2->title);
  183.                             $this->setVar('TOP_SUB_MENU_LINK'$config->website->params->url.'/'.$this->requestModule.'/'.$v2->link);
  184.                             $this->setVar('TOP_SUB_MENU_DESCRIPTION'$v2->description);
  185.                             if (FALSE !== stripos($v2->link$this->requestController.'/'.$this->requestAction.'/'))
  186.                             {    //if curent menu is the curent viewed page
  187.                                 $this->setVar('TOP_SUB_MENU_SEL''_selected');
  188.                             }    
  189.                             $this->parse('top_normal_sub_menu_item_block''top_normal_sub_menu_item'true);
  190.                         }
  191.                         $this->parse('top_sub_menu_item_block''top_sub_menu_item'true);    
  192.                     }
  193.                     $this->parse('top_menu_item_block''top_menu_item'true);
  194.                     $this->parse('top_normal_menu_item_block''');                                                                    
  195.                     $i++;
  196.                 }                    
  197.                     $this->parse('top_normal_sub_menu_item_block''top_normal_sub_menu_item',true);
  198.                 $this->parse('top_menu_block''top_menu'true);
  199.                 $this->parse('MENU_'.$child->id'tpl_menu_'.$child->id);
  200.             }
  201.         }
  202.     }
  203.     /**
  204.      * Display the info bar only if user is logged id
  205.      * @access public
  206.      * @return void 
  207.      */
  208.     public function setInfoBar()
  209.     {        
  210.         if(Dot_Auth::hasIdentity('admin'))
  211.         {            
  212.             $this->setFile('tpl_info''blocks/info_bar.tpl');
  213.             $session Zend_Registry::get('session');
  214.             $this->setVar('ADMIN_USERNAME'$session->admin['username']);
  215.             $this->parse('INFO_BAR''tpl_info');            
  216.         }
  217.     }
  218.     /**
  219.      * Create the pagination, based on how many data
  220.      * @access public
  221.      * @param array $data 
  222.      * @param int $current_page [optional]
  223.      * @return string 
  224.      */
  225.     protected function paginator($adapter$currentPage 1)
  226.     {        
  227.         $paginator new Zend_Paginator($adapter);
  228.         $paginator->setItemCountPerPage($this->settings->resultsPerPage);
  229.         $paginator->setCurrentPageNumber($currentPage);
  230.         $paginator->totalItems $adapter->count();
  231.         $page $paginator->getPages();    
  232.         $this->setFile('page_file''paginator.tpl');
  233.         $this->setVar('TOTAL_RECORDS'$paginator->totalItems);
  234.         $this->setVar('TOTAL_PAGES'$page->pageCount );
  235.         $this->setBlock('page_file''previous''previous_row');
  236.         $this->setBlock('page_file''next''next_row');
  237.         $this->setBlock('page_file''current_page''current_row');
  238.         $this->setBlock('page_file''other_page''other_row');        
  239.         $this->setBlock('page_file''pages''pages_row');
  240.  
  241.         $param Zend_Registry::get('param');
  242.         $link (array_key_exists('page',$param)) ?  '' 'page/';
  243.         
  244.         if ($page->first != $page->current)
  245.         {
  246.             $this->setVar('PREVIOUS_LINK',$link.($page->current-1));
  247.             $this->parse('previous_row''previous'TRUE);
  248.         }
  249.         else
  250.         {
  251.             $this->parse('previous_row''');
  252.         }
  253.         if ($page->last>&& $page->last != $page->current)
  254.         {
  255.             $this->setVar('NEXT_LINK',$link.$page->next);
  256.             $this->parse('next_row''next'TRUE);
  257.         }
  258.         else
  259.         {
  260.             $this->parse('next_row''');
  261.         }
  262.         foreach ($page->pagesInRange as $val)
  263.         {
  264.             $this->setVar('PAGE_NUMBER'$val);
  265.             $this->parse('other_row','');
  266.             $this->parse('current_row','');
  267.             if($val == $page->current)
  268.             {
  269.                 $this->parse('current_row','current_page'TRUE);
  270.                 //$this->parse('other_row','');
  271.             }
  272.             else
  273.             {
  274.                 $this->setVar('PAGE_LINK'$link.$val);
  275.                 //$this->parse('current_row','');
  276.                 $this->parse('other_row','other_page'TRUE);
  277.             }                
  278.             $this->parse('pages_row''pages'TRUE);
  279.         }
  280.         $this->parse('PAGINATION''page_file');                
  281.     }
  282.     /**
  283.      * Display message - error, warning, info
  284.      * @access public
  285.      * @return void 
  286.      */
  287.     public function displayMessage()
  288.     {
  289.         $session Zend_Registry::get('session');        
  290.         if(isset($session->message))
  291.         {
  292.             $this->setFile('tpl_msg''blocks/message.tpl');
  293.             $this->setBlock('tpl_msg''msg_array''msg_array_row');
  294.             $this->setVar('MESSAGE_TYPE'$session->message['type']);
  295.             if(is_array($session->message['txt']))
  296.             {            
  297.                 foreach ($session->message['txt'as $k => $msg)
  298.                 {
  299.                     $this->setVar('MESSAGE_ARRAY'is_string($k$msg ucfirst($k' - ' $msg $msg);
  300.                     $this->parse('msg_array_row''msg_array'true);
  301.                 }
  302.             }
  303.             else
  304.             {
  305.                 $this->parse('msg_array_row''');
  306.                 $this->setVar('MESSAGE_STRING'$session->message['txt']);
  307.             }
  308.             $this->parse('MESSAGE_BLOCK''tpl_msg');
  309.             unset($session->message);
  310.         }        
  311.     }
  312. }

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