Source for file View.php
Documentation is available at View.php
* DotBoost Technologies Inc.
* DotKernel Application Framework
* @copyright Copyright (c) 2009 DotBoost Technologies (http://www.dotboost.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @version $Id: View.php 161 2010-06-29 11:17:38Z teo $
* abstract over the Dot_Template class
* @author DotKernel Team <team@dotkernel.com>
protected static $_instance = null;
* Returns an instance of Dot_View
* Singleton pattern implementation
* @param string $root Template root directory
* @param string $unknowns How to handle unknown variables
* @param array $fallback Fallback paths
public static function getInstance($root = '.', $unknowns = 'remove', $fallback= '')
if (null === self::$_instance) {
self::$_instance = new self($root, $unknowns, $fallback);
self::$_instance->settings = Zend_Registry::get('settings');
* Initalize some parameter
* @param string $requestModule
* @param string $requestController
* @param string $requestAction
public function init($requestModule, $requestController, $requestAction)
$this->requestModule = $requestModule;
$this->requestController = $requestController;
$this->requestAction = $requestAction;
$this->setFile('tpl_index', 'index.tpl');
* Set different paths url(site, templates, images)
* @param Zend_Config_Ini $config
$this->setVar('TEMPLATES_URL', $config->website->params->url . TEMPLATES_DIR);
$this->setVar('IMAGES_URL', $config->website->params->url . IMAGES_DIR . '/' . $this->requestModule);
$this->setVar('SITE_URL', $config->website->params->url);
* @param string $pageTitle [optional]
$option = $seo->getOption();
$this->setVar('PAGE_KEYWORDS', $option->defaultMetaKeywords);
$this->setVar('PAGE_DESCRIPTION', $option->defaultMetaDescription);
$this->setVar('PAGE_TITLE', $option->defaultPageTitle . ' | ' . $pageTitle);
$this->setVar('PAGE_CONTENT_TITLE', $pageTitle);
$this->setVar('SITE_NAME', $option->siteName);
* Display the specific menu that were declared in configs/menu.xml file
* @param Zend_Config_Ini $config
* Display the specific menu that were declared in configs/menu.xml file
* @param Zend_Config_Ini $config
$menu_xml = new Zend_Config_Xml(CONFIGURATION_PATH . '/' . $this->requestModule . '/' . 'menu.xml', 'config');
// if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero)
$menu = new Zend_Config(array(0=> $menu_xml->menu));
foreach ($menu as $child)
if(0 == $child->display) continue;
$this->setFile('tpl_menu_'. $child->id, 'blocks/menu_'. $child->type. '.tpl');
$this->setBlock('tpl_menu_'. $child->id, 'top_normal_sub_menu_item', 'top_normal_sub_menu_item_block');
$this->setBlock('tpl_menu_'. $child->id, 'top_sub_menu_item', 'top_sub_menu_item_block');
$this->setBlock('tpl_menu_'. $child->id, 'top_normal_menu_item', 'top_normal_menu_item_block');
$this->setBlock('tpl_menu_'. $child->id, 'top_menu_item', 'top_menu_item_block');
$this->setBlock('tpl_menu_'. $child->id, 'top_menu', 'top_menu_block');
$tplVariables = array('TOP_MENU_SEL',
$tplBlocks = array('top_menu_block',
'top_normal_menu_item_block',
'top_sub_menu_item_block',
'top_normal_submenu_item_block');
//Initialize all the tag variables and blocks
// if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero)
$items = new Zend_Config(array(0=> $child->item));
foreach ($items as $key => $val)
$this->setVar('TOP_MENU_ID', $i);
$tplVariables = array('TOP_MENU_SEL',
'TOP_SUB_MENU_ITEM_SEL');
if (FALSE !== stripos($val->link, $this->requestController. '/'))
{ //if curent menu is the curent viewed page
$this->setVar('TOP_MENU_SEL', '_selected');
$this->setVar('TOP_MENU_TITLE', $val->title);
$this->setVar('TOP_MENU_LINK', $config->website->params->url. '/'. $this->requestModule. '/'. $val->link);
$this->setVar('TOP_MENU_DESCRIPTION', $val->description);
$this->parse('top_normal_menu_item_block', 'top_normal_menu_item', true);
if (isset ($val->subItems->subItem) && count($val->subItems->subItem) > 0)
$subItems = $val->subItems->subItem;
// if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero)
$subItems = new Zend_Config(array(0=> $subItems));
$this->parse('top_normal_sub_menu_item_block', '');
foreach ($subItems as $k2 => $v2)
$this->setVar('TOP_SUB_MENU_SEL', '');
$this->setVar('TOP_SUB_MENU_TITLE', $v2->title);
$this->setVar('TOP_SUB_MENU_LINK', $config->website->params->url. '/'. $this->requestModule. '/'. $v2->link);
$this->setVar('TOP_SUB_MENU_DESCRIPTION', $v2->description);
if (FALSE !== stripos($v2->link, $this->requestController. '/'. $this->requestAction. '/'))
{ //if curent menu is the curent viewed page
$this->setVar('TOP_SUB_MENU_SEL', '_selected');
$this->parse('top_normal_sub_menu_item_block', 'top_normal_sub_menu_item', true);
$this->parse('top_sub_menu_item_block', 'top_sub_menu_item', true);
$this->parse('top_menu_item_block', 'top_menu_item', true);
$this->parse('top_normal_menu_item_block', '');
$this->parse('top_normal_sub_menu_item_block', 'top_normal_sub_menu_item',true);
$this->parse('top_menu_block', 'top_menu', true);
$this->parse('MENU_'. $child->id, 'tpl_menu_'. $child->id);
* Display the info bar only if user is logged id
$this->setFile('tpl_info', 'blocks/info_bar.tpl');
$session = Zend_Registry::get('session');
$this->setVar('ADMIN_USERNAME', $session->admin['username']);
$this->parse('INFO_BAR', 'tpl_info');
* Create the pagination, based on how many data
* @param int $current_page [optional]
protected function paginator($adapter, $currentPage = 1)
$paginator = new Zend_Paginator($adapter);
$paginator->setItemCountPerPage($this->settings->resultsPerPage);
$paginator->setCurrentPageNumber($currentPage);
$paginator->totalItems = $adapter->count();
$page = $paginator->getPages();
$this->setFile('page_file', 'paginator.tpl');
$this->setVar('TOTAL_RECORDS', $paginator->totalItems);
$this->setVar('TOTAL_PAGES', $page->pageCount );
$this->setBlock('page_file', 'previous', 'previous_row');
$this->setBlock('page_file', 'next', 'next_row');
$this->setBlock('page_file', 'current_page', 'current_row');
$this->setBlock('page_file', 'other_page', 'other_row');
$this->setBlock('page_file', 'pages', 'pages_row');
$param = Zend_Registry::get('param');
if ($page->first != $page->current)
$this->parse('previous_row', 'previous', TRUE);
$this->parse('previous_row', '');
if ($page->last> 0 && $page->last != $page->current)
$this->parse('next_row', 'next', TRUE);
$this->parse('next_row', '');
foreach ($page->pagesInRange as $val)
$this->setVar('PAGE_NUMBER', $val);
$this->parse('other_row','');
$this->parse('current_row','');
$this->parse('current_row','current_page', TRUE);
//$this->parse('other_row','');
$this->setVar('PAGE_LINK', $link. $val);
//$this->parse('current_row','');
$this->parse('other_row','other_page', TRUE);
$this->parse('pages_row', 'pages', TRUE);
$this->parse('PAGINATION', 'page_file');
* Display message - error, warning, info
$session = Zend_Registry::get('session');
if(isset ($session->message))
$this->setFile('tpl_msg', 'blocks/message.tpl');
$this->setBlock('tpl_msg', 'msg_array', 'msg_array_row');
$this->setVar('MESSAGE_TYPE', $session->message['type']);
foreach ($session->message['txt'] as $k => $msg)
$this->parse('msg_array_row', 'msg_array', true);
$this->parse('msg_array_row', '');
$this->setVar('MESSAGE_STRING', $session->message['txt']);
$this->parse('MESSAGE_BLOCK', 'tpl_msg');
unset ($session->message);
|