PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/app/code/community/EM/Megamenu/Block/Catalognavigation.php

https://bitbucket.org/deniskulikouski/belvg.deniska
PHP | 491 lines | 437 code | 39 blank | 15 comment | 72 complexity | 328697e51228c6fc6ddd29c761069c4b MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. class EM_Megamenu_Block_Catalognavigation extends Mage_Catalog_Block_Navigation
  3. {
  4. public function getStoreCategories()
  5. {
  6. $helper = Mage::helper('megamenu/category');
  7. return $helper->getStoreCategories();
  8. }
  9. protected function _renderCategoryMenuItemHtml($category,$level = 0, $isLast = false, $isFirst = false,
  10. $isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false)
  11. {
  12. $type = Mage::registry('set_layout_menu');
  13. if (!$category->getIsActive()) {
  14. return '';
  15. }
  16. $html = array();
  17. $html1 = array();
  18. // get all children
  19. if (Mage::helper('catalog/category_flat')->isEnabled()) {
  20. $children = (array)$category->getChildrenNodes();
  21. $childrenCount = count($children);
  22. } else {
  23. $children = $category->getChildren();
  24. $childrenCount = $children->count();
  25. }
  26. $hasChildren = ($children && $childrenCount);
  27. // select active children
  28. $activeChildren = array();
  29. foreach ($children as $child) {
  30. if ($child->getIsActive()) {
  31. $activeChildren[] = $child;
  32. }
  33. }
  34. $activeChildrenCount = count($activeChildren);
  35. $hasActiveChildren = ($activeChildrenCount > 0);
  36. // prepare list item html classes
  37. $classes = array();
  38. $classes[] = 'level' . $level;
  39. $classes[] = 'nav-' . $this->_getItemPosition($level);
  40. $linkClass = '';
  41. $classa="";
  42. if($level==0)
  43. {
  44. if($type == 4 || $type ==5 || $type ==6)
  45. $classa="drop";
  46. }
  47. if ($isOutermost && $outermostItemClass) {
  48. $classes[] = $outermostItemClass;
  49. $linkClass = ' class="'.$outermostItemClass." ".$classa.'"';
  50. }
  51. if ($this->isCategoryActive($category)) {
  52. $classes[] = 'active';
  53. }
  54. if ($isFirst) {
  55. if($level == (int)Mage::registry('level_class'))
  56. {
  57. if(Mage::registry('none_li_first_class') == "0")
  58. $classes[] = 'first';
  59. }
  60. else
  61. $classes[] = 'first';
  62. }
  63. if ($isLast) {
  64. if($level == (int)Mage::registry('level_class'))
  65. {
  66. if(Mage::registry('none_li_last_class') == "0")
  67. $classes[] = 'last';
  68. }
  69. else
  70. $classes[] = 'last';
  71. }
  72. if ($hasActiveChildren) {
  73. $classes[] = 'parent';
  74. }
  75. // prepare list item attributes
  76. $attributes = array();
  77. if (count($classes) > 0) {
  78. $attributes['class'] = implode(' ', $classes);
  79. }
  80. if ($hasActiveChildren && !$noEventAttributes) {
  81. $attributes['onmouseover'] = 'toggleMenu(this,1)';
  82. $attributes['onmouseout'] = 'toggleMenu(this,0)';
  83. }
  84. // assemble list item with attributes
  85. //type =1,2,3
  86. switch($type)
  87. {
  88. case 1:
  89. {
  90. $html[] = '<k><li><a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
  91. $html[] = $this->escapeHtml($category->getName());
  92. $html[] = '</a></li>';
  93. // render children
  94. $htmlChildren = '';
  95. $j = 0;
  96. foreach ($activeChildren as $child) {
  97. $htmlChildren .= $this->_renderCategoryMenuItemHtml(
  98. $child,
  99. ($level + 1),
  100. ($j == $activeChildrenCount - 1),
  101. ($j == 0),
  102. false,
  103. $outermostItemClass,
  104. $childrenWrapClass,
  105. $noEventAttributes
  106. );
  107. $j++;
  108. }
  109. if (!empty($htmlChildren)) {
  110. $html[] = $htmlChildren ;
  111. }
  112. break;
  113. }
  114. case 2:
  115. {
  116. if($level==0)
  117. {
  118. $htmlLi='<div class="col_1 ">';
  119. }
  120. else
  121. {
  122. $htmlLi = '<li';
  123. foreach ($attributes as $attrName => $attrValue) {
  124. $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
  125. }
  126. $htmlLi .= '>';
  127. }
  128. $html[] = $htmlLi;
  129. if ($level==0)
  130. {
  131. $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
  132. $html[] = '<span>'. $this->escapeHtml($category->getName()).'</span>';
  133. $html[] = '</a>';
  134. }
  135. else
  136. {
  137. $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
  138. $html[] = $this->escapeHtml($category->getName());
  139. $html[] = '</a>';
  140. }
  141. // render children
  142. $htmlChildren = '';
  143. $j = 0;
  144. foreach ($activeChildren as $child) {
  145. $htmlChildren .= $this->_renderCategoryMenuItemHtml(
  146. $child,
  147. ($level + 1),
  148. ($j == $activeChildrenCount - 1),
  149. ($j == 0),
  150. false,
  151. $outermostItemClass,
  152. $childrenWrapClass,
  153. $noEventAttributes
  154. );
  155. $j++;
  156. }
  157. if (!empty($htmlChildren)) {
  158. if ($childrenWrapClass) {
  159. $html[] = '<div class="' . $childrenWrapClass . '">';
  160. }
  161. $html[] = '<ul class="level' . $level . '">';
  162. $html[] = $htmlChildren;
  163. $html[] = '</ul>';
  164. if ($childrenWrapClass) {
  165. $html[] = '</div>';
  166. }
  167. }
  168. if($level==0)
  169. {
  170. $html[]='</div>';
  171. }
  172. else
  173. {
  174. $html[] = '</li>';
  175. }
  176. break;
  177. }
  178. case 3:
  179. {
  180. $htmlLi = '<li';
  181. foreach ($attributes as $attrName => $attrValue) {
  182. $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
  183. }
  184. $htmlLi .= '>';
  185. $html[] = $htmlLi;
  186. $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
  187. $html[] = $this->escapeHtml($category->getName());
  188. $html[] = '</a>';
  189. // render children
  190. $htmlChildren = '';
  191. $j = 0;
  192. foreach ($activeChildren as $child) {
  193. $htmlChildren .= $this->_renderCategoryMenuItemHtml(
  194. $child,
  195. ($level + 1),
  196. ($j == $activeChildrenCount - 1),
  197. ($j == 0),
  198. false,
  199. $outermostItemClass,
  200. $childrenWrapClass,
  201. $noEventAttributes
  202. );
  203. $j++;
  204. }
  205. if (!empty($htmlChildren)) {
  206. if ($childrenWrapClass) {
  207. $html[] = '<div class="' . $childrenWrapClass . '">';
  208. }
  209. $html[] = '<ul class="level' . $level. '">';
  210. $html[] = $htmlChildren;
  211. $html[] = '</ul>';
  212. if ($childrenWrapClass) {
  213. $html[] = '</div>';
  214. }
  215. }
  216. $html[] = '</li>';
  217. break;
  218. }
  219. case 4:
  220. {
  221. if($level !=0)
  222. {
  223. $f="<f>";
  224. }
  225. if($level==0)
  226. {
  227. $n="<n>";
  228. }
  229. $htmlLi = $n.$f.'<li';
  230. foreach ($attributes as $attrName => $attrValue) {
  231. $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
  232. }
  233. $htmlLi .= '>';
  234. $html[] = $htmlLi;
  235. $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
  236. $html[] = $this->escapeHtml($category->getName());
  237. $html[] = '</a>';
  238. if($level==0)
  239. {
  240. $html[]="<k>";
  241. }
  242. // render children
  243. $htmlChildren = '';
  244. $j = 0;
  245. foreach ($activeChildren as $child) {
  246. $htmlChildren .= $this->_renderCategoryMenuItemHtml(
  247. $child,
  248. ($level + 1),
  249. ($j == $activeChildrenCount - 1),
  250. ($j == 0),
  251. false,
  252. $outermostItemClass,
  253. $childrenWrapClass,
  254. $noEventAttributes
  255. );
  256. $j++;
  257. }
  258. if (!empty($htmlChildren)) {
  259. if ($childrenWrapClass) {
  260. $html[] = '<div class="' . $childrenWrapClass . '">';
  261. }
  262. $ulfirst="";
  263. $ullast="";
  264. //$ulfirst='<ul class="level' . $level . '">';
  265. //$ullast='</ul>';
  266. $html[] =$ulfirst.$htmlChildren.$ullast;
  267. if ($childrenWrapClass) {
  268. $html[] = '</div>';
  269. }
  270. }
  271. $html[] = '</li>';
  272. break;
  273. }
  274. case 5:
  275. {
  276. if($level==1 )
  277. {
  278. $htmlLi='<div class="col_1">';
  279. }
  280. else
  281. {
  282. $htmlLi = '<li';
  283. foreach ($attributes as $attrName => $attrValue) {
  284. $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
  285. }
  286. $htmlLi .= '>';
  287. }
  288. $html[] = $htmlLi;
  289. if ($level==1)
  290. {
  291. $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
  292. $html[] = '<span>'. $this->escapeHtml($category->getName()).'</span>';
  293. $html[] = '</a>';
  294. }
  295. else
  296. {
  297. $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
  298. $html[] = $this->escapeHtml($category->getName());
  299. $html[] = '</a>';
  300. }
  301. // render children
  302. $htmlChildren = '';
  303. $j = 0;
  304. foreach ($activeChildren as $child) {
  305. $htmlChildren .= $this->_renderCategoryMenuItemHtml(
  306. $child,
  307. ($level + 1),
  308. ($j == $activeChildrenCount - 1),
  309. ($j == 0),
  310. false,
  311. $outermostItemClass,
  312. $childrenWrapClass,
  313. $noEventAttributes
  314. );
  315. $j++;
  316. }
  317. if (!empty($htmlChildren)) {
  318. if ($childrenWrapClass) {
  319. $html[] = '<div class="' . $childrenWrapClass . '">';
  320. }
  321. $ulfirst="";
  322. $ullast="";
  323. if($level==0)
  324. {
  325. $count=0;
  326. if( $childrenCount >5 )
  327. {
  328. $count=5;
  329. }
  330. else
  331. {
  332. $count = $childrenCount;
  333. }
  334. $ulfirst='<div class="dropdown_'.$count.'columns">';
  335. $ullast='</div>';
  336. }
  337. else
  338. {
  339. $ulfirst='<ul class="level' . $level . '">';
  340. $ullast='</ul>';
  341. }
  342. $html[] =$ulfirst.$htmlChildren.$ullast;
  343. if ($childrenWrapClass) {
  344. $html[] = '</div>';
  345. }
  346. }
  347. if($level==1)
  348. {
  349. $html[]='</div>';
  350. }
  351. else
  352. {
  353. $html[] = '</li>';
  354. }
  355. break;
  356. }
  357. case 6:
  358. {
  359. $htmlLi = '<li';
  360. foreach ($attributes as $attrName => $attrValue) {
  361. $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
  362. }
  363. $htmlLi .= '>';
  364. $html[] = $htmlLi;
  365. $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
  366. $html[] = $this->escapeHtml($category->getName());
  367. $html[] = '</a>';
  368. // render children
  369. $htmlChildren = '';
  370. $j = 0;
  371. foreach ($activeChildren as $child) {
  372. $htmlChildren .= $this->_renderCategoryMenuItemHtml(
  373. $child,
  374. ($level + 1),
  375. ($j == $activeChildrenCount - 1),
  376. ($j == 0),
  377. false,
  378. $outermostItemClass,
  379. $childrenWrapClass,
  380. $noEventAttributes
  381. );
  382. $j++;
  383. }
  384. if (!empty($htmlChildren)) {
  385. if ($childrenWrapClass) {
  386. $html[] = '<div class="' . $childrenWrapClass . '">';
  387. }
  388. $ulfirst="";
  389. $ullast="";
  390. if($level==0)
  391. {
  392. $ulfirst='<div class="dropdown_1columns"><div class="col_1"><ul class="levels">';
  393. $ullast='</ul></div></div>';
  394. }
  395. else
  396. {
  397. $ulfirst='<ul class="level' . $level. '">';
  398. $ullast='</ul>';
  399. }
  400. $html[] =$ulfirst.$htmlChildren.$ullast;
  401. if ($childrenWrapClass) {
  402. $html[] = '</div>';
  403. }
  404. }
  405. $html[] = '</li>';
  406. break;
  407. }
  408. default:
  409. {
  410. $htmlLi = '<li';
  411. foreach ($attributes as $attrName => $attrValue) {
  412. $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
  413. }
  414. $htmlLi .= '>';
  415. $html[] = $htmlLi;
  416. $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
  417. $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
  418. $html[] = '</a>';
  419. // render children
  420. $htmlChildren = '';
  421. $j = 0;
  422. foreach ($activeChildren as $child) {
  423. $htmlChildren .= $this->_renderCategoryMenuItemHtml(
  424. $child,
  425. ($level + 1),
  426. ($j == $activeChildrenCount - 1),
  427. ($j == 0),
  428. false,
  429. $outermostItemClass,
  430. $childrenWrapClass,
  431. $noEventAttributes
  432. );
  433. $j++;
  434. }
  435. if (!empty($htmlChildren)) {
  436. if ($childrenWrapClass) {
  437. $html[] = '<div class="' . $childrenWrapClass . '">';
  438. }
  439. $html[] = '<ul class="level' . $level . '">';
  440. $html[] = $htmlChildren;
  441. $html[] = '</ul>';
  442. if ($childrenWrapClass) {
  443. $html[] = '</div>';
  444. }
  445. }
  446. $html[] = '</li>';
  447. }
  448. }
  449. $html = implode("\n", $html);
  450. return $html;
  451. }
  452. }