PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/joomla/modules/mod_jevents_legend/tmpl/geraint/legend.php

https://gitlab.com/ricardosanchez/prueba
PHP | 252 lines | 183 code | 45 blank | 24 comment | 64 complexity | fc75319e02cf8ba6ce43f0ec065c5467 MD5 | raw file
  1. <?php
  2. /**
  3. * copyright (C) 2008-2016 GWE Systems Ltd - All rights reserved
  4. */
  5. // Check to ensure this file is included in Joomla!
  6. defined('_JEXEC') or die();
  7. use Joomla\String\StringHelper;
  8. /**
  9. * HTML View class for the component frontend
  10. *
  11. * @static
  12. */
  13. include_once(JPATH_SITE."/modules/mod_jevents_legend/tmpl/default/legend.php");
  14. class GeraintModLegendView extends DefaultModLegendView{
  15. var $_modid = null;
  16. var $_params = null;
  17. function getViewName(){
  18. return "geraint";
  19. }
  20. function displayCalendarLegend($style="list"){
  21. // do not display normal legend if dynamic legend is visible on this page
  22. $registry = JRegistry::getInstance("jevents");
  23. if ($registry->get("jevents.dynamiclegend",0)) {
  24. return;
  25. }
  26. // since this is meant to be a comprehensive legend look for catids from menu first:
  27. $cfg = JEVConfig::getInstance();
  28. $Itemid = $this->myItemid;
  29. $user = JFactory::getUser();
  30. $db = JFactory::getDBO();
  31. // Parameters - This module should only be displayed alongside a com_jevents calendar component!!!
  32. $cfg = JEVConfig::getInstance();
  33. $option = JRequest::getCmd('option');
  34. if ($this->disable && $option!=JEV_COM_COMPONENT) return;
  35. $catidList = "";
  36. include_once(JPATH_ADMINISTRATOR."/components/".JEV_COM_COMPONENT."/libraries/colorMap.php");
  37. $menu = JFactory::getApplication()->getMenu();
  38. $active = $menu->getActive();
  39. if ((!is_null($active) && $active->component==JEV_COM_COMPONENT) || !isset($Itemid)){
  40. $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
  41. }
  42. else {
  43. // If accessing this function from outside the component then I must load suitable parameters
  44. $params = $menu->getParams($Itemid);
  45. }
  46. $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
  47. $c=0;
  48. $catids = array();
  49. // New system
  50. $newcats = $params->get("catidnew", false);
  51. if ($newcats && is_array($newcats))
  52. {
  53. foreach ($newcats as $newcat)
  54. {
  55. if (!in_array($newcat, $catids))
  56. {
  57. $catids[] = $newcat;
  58. $catidList .= (JString::strlen($catidList) > 0 ? "," : "") . $newcat;
  59. }
  60. }
  61. }
  62. else
  63. {
  64. while ($nextCatId = $params->get("catid$c", null))
  65. {
  66. if (!in_array($nextCatId, $catids))
  67. {
  68. $catids[] = $nextCatId;
  69. $catidList .= (JString::strlen($catidList) > 0 ? "," : "") . $nextCatId;
  70. }
  71. $c++;
  72. }
  73. }
  74. $jevleghelper = new modJeventsLegendHelper();
  75. if ($catidList == "" && $params->get("catid0", "xxx") == "xxx") {
  76. modJeventsLegendHelper::getAllCats($this->_params,$catids,$catidList);
  77. }
  78. $separator = $params->get("catseparator","|");
  79. $catidsOut = str_replace(",",$separator,$catidList);
  80. // I should only show legend for items that **can** be shown in calendar so must filter based on GET/POST
  81. $catidsIn = JRequest::getVar('catids', "NONE" );
  82. if ($catidsIn!="NONE" && $catidsIn!="0") $catidsGP = explode($separator,$catidsIn);
  83. else $catidsGP = array();
  84. $catidsGPList = implode(",",$catidsGP);
  85. // This produces a full tree of categories
  86. $allrows = $this->getCategoryHierarchy($catidList, $catidsGPList);
  87. // This is the full set of top level catids
  88. $availableCatsIds="";
  89. foreach ($allrows as $row){
  90. $availableCatsIds.=(JString::strlen($availableCatsIds)>0?$separator:"").$row->id;
  91. }
  92. $allcats = new catLegend("0", JText::_('JEV_LEGEND_ALL_CATEGORIES'),"#d3d3d3",JText::_('JEV_LEGEND_ALL_CATEGORIES_DESC'));
  93. $allcats->activeBranch = true;
  94. array_push($allrows,$allcats);
  95. if (count($allrows)==0) return "";
  96. else {
  97. if ($Itemid<999999) $itm = "&Itemid=$Itemid";
  98. $task = JRequest::getVar( 'jevcmd', $cfg->get('com_startview'));
  99. list($year,$month,$day) = JEVHelper::getYMD();
  100. $tsk="";
  101. if ($task=="month.calendar" || $task=="year.listeventsevents" || $task=="week.listevents" || $task=="year.listevents" || $task=="day.listevents"|| $task=="cat.listevents"){
  102. $tsk="&task=$task&year=$year&month=$month&day=$day";
  103. }
  104. else {
  105. $tsk="&task=$this->myTask&year=$year&month=$month&day=$day";
  106. }
  107. switch ($style) {
  108. case 'list':
  109. $content = '<div class="event_legend_container">';
  110. $content .= '<table border="0" cellpadding="0" cellspacing="5" width="100%">';
  111. foreach ($allrows as $row) {
  112. if (isset($row->activeBranch)){
  113. $content .= $this->listKids($row, $itm, $tsk, $availableCatsIds);
  114. }
  115. }
  116. $content .= "</table>\n";
  117. $content .= "</div>";
  118. break;
  119. case 'block':
  120. default:
  121. $content = '<div class="event_legend_container">';
  122. foreach ($allrows as $row) {
  123. if (isset($row->activeBranch)){
  124. $content .= $this->blockKids($row, $itm, $tsk, $availableCatsIds);
  125. }
  126. }
  127. // stop floating legend items
  128. $content .= '<br style="clear:both" />'."</div>\n";
  129. }
  130. // only if called from module
  131. if (isset($this->_params)) {
  132. if ($this->_params->get('show_admin', 0) && isset($year) && isset($month) && isset($day) && isset($Itemid)) {
  133. // This is only displayed when JEvents is the component so I can get the component view
  134. $component = JComponentHelper::getComponent(JEV_COM_COMPONENT);
  135. $registry = JRegistry::getInstance("jevents");
  136. $controller =& $registry->get("jevents.controller",null);
  137. if (!$controller) return $content;
  138. $view = $controller->view;
  139. //include_once(JPATH_SITE."/components/$option/events.html.php");
  140. ob_start();
  141. if (method_exists($view,"_viewNavAdminPanel")){
  142. echo $view->_viewNavAdminPanel();
  143. }
  144. $content .= ob_get_contents();
  145. ob_end_clean();
  146. }
  147. }
  148. return $content;
  149. }
  150. }
  151. function listKids($row, $itm, $tsk,$availableCatsIds, $activeParent = false, $activeSubCat=0){
  152. $catclass="";
  153. if ($row->parent_id>0) $catclass = "childcat";
  154. if ($row->parent_id>0 && isset($row->activeBranch)) $catclass = "activechildcat";
  155. if ($row->parent_id>0 && $activeParent) $catclass = "activechildcat";
  156. if ($row->parent_id>0 && $activeSubCat>0 && $row->id!=$activeSubCat && !isset($row->activeNode)) $catclass = "childcat";
  157. $cat = $row->id>0 ? "&catids=$row->id" : "";
  158. $content = "<tr><td style='border:solid 1px #000000;height:5px;width:5px;background-color:".$row->color."'></td>\n"
  159. ."<td class='legend' >"
  160. ."<a style='text-decoration:none' href='".JRoute::_("index.php?option=".JEV_COM_COMPONENT."$cat$itm$tsk")."' title='".JEventsHTML::special($row->name)."'>"
  161. .JEventsHTML::special($row->name)."</a></td></tr>\n";
  162. if (isset($row->activeBranch) && isset($row->subcats)){
  163. $activeSubCat = 0;
  164. foreach ($row->subcats as $subcatid => $subcat){
  165. if (isset($subcat->activeBranch)){
  166. $activeSubCat = $subcatid;
  167. }
  168. }
  169. foreach ($row->subcats as $subcatid => $subcat){
  170. $content .= $this->listKids($subcat, $itm, $tsk,$availableCatsIds, isset($row->activeNode),$activeSubCat);
  171. }
  172. }
  173. return $content;
  174. }
  175. function blockKids($row, $itm, $tsk, $availableCatsIds, $activeParent = false, $activeSubCat=0){
  176. $catclass="";
  177. if ($row->parent_id>0) $catclass = "childcat";
  178. if ($row->parent_id>0 && isset($row->activeBranch)) $catclass = "activechildcat";
  179. if ($row->parent_id>0 && $activeParent) $catclass = "activechildcat";
  180. if ($row->parent_id>0 && $activeSubCat>0 && $row->id!=$activeSubCat && !isset($row->activeNode)) $catclass = "childcat";
  181. $cat = $row->id>0 ? "&catids=$row->id" : "";
  182. //$rowparams = new JRegistry(isset($row->params)?$row->params:null);
  183. //$image = $rowparams->get("image",false);
  184. //$image = $image? "<img src = '".JURI::root().$image."' class='catimage' alt='categoryimage' />" : "";
  185. $content = '<div class="event_legend_item '.$catclass.'" style="border-color:'.$row->color.'">';
  186. $content .= '<div class="event_legend_name" style="border-color:'.$row->color.'">'
  187. . '<a href="'.JRoute::_("index.php?option=".JEV_COM_COMPONENT."$cat$itm$tsk").'" title="'.JEventsHTML::special($row->name).'">'
  188. . JEventsHTML::special($row->name).'</a>';
  189. $content .= '</div>'."\n";
  190. if (JString::strlen($row->description)>0) {
  191. $content .='<div class="event_legend_desc" style="border-color:'.$row->color.'">'.$row->description.'</div>';
  192. }
  193. $content .= '</div>'."\n";
  194. if (isset($row->activeBranch) && isset($row->subcats)){
  195. $activeSubCat = 0;
  196. foreach ($row->subcats as $subcatid => $subcat){
  197. if (isset($subcat->activeBranch)){
  198. $activeSubCat = $subcatid;
  199. }
  200. }
  201. foreach ($row->subcats as $subcatid => $subcat){
  202. $content .= $this->blockKids($subcat, $itm, $tsk,$availableCatsIds, isset($row->activeNode), $activeSubCat);
  203. }
  204. }
  205. return $content;
  206. }
  207. }