PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/Core/widgets/container-tabs/Controller.php

https://github.com/shopaholiccompany/shopaholic
PHP | 83 lines | 50 code | 6 blank | 27 comment | 8 complexity | d8931c8f661d4d64e643f1dfd617f45f MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * SocialEngine
  4. *
  5. * @category Application_Core
  6. * @package Core
  7. * @copyright Copyright 2006-2010 Webligo Developments
  8. * @license http://www.socialengine.net/license/
  9. * @version $Id: Controller.php 7244 2010-09-01 01:49:53Z john $
  10. * @author John
  11. */
  12. /**
  13. * @category Application_Core
  14. * @package Core
  15. * @copyright Copyright 2006-2010 Webligo Developments
  16. * @license http://www.socialengine.net/license/
  17. */
  18. class Core_Widget_ContainerTabsController extends Engine_Content_Widget_Abstract
  19. {
  20. public function indexAction()
  21. {
  22. // Set up element
  23. $element = $this->getElement();
  24. $element->clearDecorators()
  25. //->addDecorator('Children', array('placement' => 'APPEND'))
  26. ->addDecorator('Container');
  27. $activeTab = $this->_getParam('tab');
  28. if( empty($activeTab) ) {
  29. $activeTab = Zend_Controller_Front::getInstance()->getRequest()->getParam('tab');
  30. }
  31. // Iterate over children
  32. $tabs = array();
  33. $childrenContent = '';
  34. foreach( $element->getElements() as $child ) {
  35. // First tab is active if none supplied
  36. if( null === $activeTab ) {
  37. $activeTab = $child->getIdentity();
  38. }
  39. // If not active, set to display none
  40. if( $child->getIdentity() !== $activeTab ) {
  41. $child->getDecorator('Container')->setParam('style', 'display:none;');
  42. }
  43. // Set specific class name
  44. $child_class = $child->getDecorator('Container')->getParam('class');
  45. $child->getDecorator('Container')->setParam('class', $child_class . ' tab_'.$child->getIdentity());
  46. // Remove title decorator
  47. $child->removeDecorator('Title');
  48. // Render to check if it actually renders or not
  49. $childrenContent .= $child->render() . PHP_EOL;
  50. // Get title and childcount
  51. $title = $child->getTitle();
  52. $childCount = null;
  53. if( method_exists($child, 'getWidget') && method_exists($child->getWidget(), 'getChildCount') ) {
  54. $childCount = $child->getWidget()->getChildCount();
  55. }
  56. if( !$title ) $title = $child->getName();
  57. // If it does render, add it to the tab list
  58. if( !$child->getNoRender() ) {
  59. $tabs[] = array(
  60. 'id' => $child->getIdentity(),
  61. 'name' => $child->getName(),
  62. 'containerClass' => $child->getDecorator('Container')->getClass(),
  63. 'title' => $title,
  64. 'childCount' => $childCount
  65. );
  66. }
  67. }
  68. // Don't bother rendering if there are no tabs to show
  69. if( empty($tabs) ) {
  70. return $this->setNoRender();
  71. }
  72. $this->view->activeTab = $activeTab;
  73. $this->view->tabs = $tabs;
  74. $this->view->childrenContent = $childrenContent;
  75. $this->view->max = $this->_getParam('max');
  76. }
  77. }