PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/joomla/libraries/regularlabs/helpers/assignments/zoo.php

https://gitlab.com/ricardosanchez/prueba
PHP | 281 lines | 216 code | 54 blank | 11 comment | 48 complexity | ba95434fec02b91637ccd72b84bd854c MD5 | raw file
  1. <?php
  2. /**
  3. * @package Regular Labs Library
  4. * @version 16.11.9943
  5. *
  6. * @author Peter van Westen <info@regularlabs.com>
  7. * @link http://www.regularlabs.com
  8. * @copyright Copyright © 2016 Regular Labs All Rights Reserved
  9. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  10. */
  11. defined('_JEXEC') or die;
  12. require_once dirname(__DIR__) . '/assignment.php';
  13. class RLAssignmentsZoo extends RLAssignment
  14. {
  15. public function init()
  16. {
  17. if (!$this->request->view)
  18. {
  19. $this->request->view = $this->request->task;
  20. }
  21. switch ($this->request->view)
  22. {
  23. case 'item':
  24. $this->request->idname = 'item_id';
  25. break;
  26. case 'category':
  27. $this->request->idname = 'category_id';
  28. break;
  29. }
  30. $this->request->id = JFactory::getApplication()->input->getInt($this->request->idname, 0);
  31. }
  32. public function initAssignment($assignment, $article = 0)
  33. {
  34. parent::initAssignment($assignment, $article);
  35. if ($this->request->option != 'com_zoo' && !isset($this->request->idname))
  36. {
  37. return;
  38. }
  39. switch ($this->request->idname)
  40. {
  41. case 'item_id':
  42. $this->request->view = 'item';
  43. break;
  44. case 'category_id':
  45. $this->request->view = 'category';
  46. break;
  47. }
  48. }
  49. public function passPageTypes()
  50. {
  51. return $this->passByPageTypes('com_zoo', $this->selection, $this->assignment);
  52. }
  53. public function passCategories()
  54. {
  55. if ($this->request->option != 'com_zoo')
  56. {
  57. return $this->pass(false);
  58. }
  59. $pass = (
  60. ($this->params->inc_apps && $this->request->view == 'frontpage')
  61. || ($this->params->inc_categories && $this->request->view == 'category')
  62. || ($this->params->inc_items && $this->request->view == 'item')
  63. );
  64. if (!$pass)
  65. {
  66. return $this->pass(false);
  67. }
  68. $cats = $this->getCategories();
  69. if ($cats === false)
  70. {
  71. return $this->pass(false);
  72. }
  73. $cats = $this->makeArray($cats);
  74. $pass = $this->passSimple($cats, 'include');
  75. if ($pass && $this->params->inc_children == 2)
  76. {
  77. return $this->pass(false);
  78. }
  79. if (!$pass && $this->params->inc_children)
  80. {
  81. foreach ($cats as $cat)
  82. {
  83. $cats = array_merge($cats, $this->getCatParentIds($cat));
  84. }
  85. }
  86. return $this->passSimple($cats);
  87. }
  88. private function getCategories()
  89. {
  90. if ($this->article && isset($this->article->catid))
  91. {
  92. return array($this->article->catid);
  93. }
  94. $menuparams = $this->getMenuItemParams($this->request->Itemid);
  95. switch ($this->request->view)
  96. {
  97. case 'frontpage':
  98. if ($this->request->id)
  99. {
  100. return array($this->request->id);
  101. }
  102. if (!isset($menuparams->application))
  103. {
  104. return array();
  105. }
  106. return array('app' . $menuparams->application);
  107. case 'category':
  108. $cats = array();
  109. if ($this->request->id)
  110. {
  111. $cats[] = $this->request->id;
  112. }
  113. else if (isset($menuparams->category))
  114. {
  115. $cats[] = $menuparams->category;
  116. }
  117. if (empty($cats['0']))
  118. {
  119. return array();
  120. }
  121. $query = $this->db->getQuery(true)
  122. ->select('c.application_id')
  123. ->from('#__zoo_category AS c')
  124. ->where('c.id = ' . (int) $cats['0']);
  125. $this->db->setQuery($query);
  126. $cats[] = 'app' . $this->db->loadResult();
  127. return $cats;
  128. case 'item':
  129. $id = $this->request->id;
  130. if (!$id && isset($menuparams->item_id))
  131. {
  132. $id = $menuparams->item_id;
  133. }
  134. if (!$id)
  135. {
  136. return array();
  137. }
  138. $query = $this->db->getQuery(true)
  139. ->select('c.category_id')
  140. ->from('#__zoo_category_item AS c')
  141. ->where('c.item_id = ' . (int) $id)
  142. ->where('c.category_id != 0');
  143. $this->db->setQuery($query);
  144. $cats = $this->db->loadColumn();
  145. $query = $this->db->getQuery(true)
  146. ->select('i.application_id')
  147. ->from('#__zoo_item AS i')
  148. ->where('i.id = ' . (int) $id);
  149. $this->db->setQuery($query);
  150. $cats[] = 'app' . $this->db->loadResult();
  151. return $cats;
  152. default:
  153. return false;
  154. }
  155. }
  156. public function passItems()
  157. {
  158. if (!$this->request->id || $this->request->option != 'com_zoo')
  159. {
  160. return $this->pass(false);
  161. }
  162. if ($this->request->view != 'item')
  163. {
  164. return $this->pass(false);
  165. }
  166. $pass = false;
  167. // Pass Article Id
  168. if (!$this->passItemByType($pass, 'ContentIds'))
  169. {
  170. return $this->pass(false);
  171. }
  172. // Pass Authors
  173. if (!$this->passItemByType($pass, 'Authors'))
  174. {
  175. return $this->pass(false);
  176. }
  177. return $this->pass($pass);
  178. }
  179. public function getItem($fields = array())
  180. {
  181. $query = $this->db->getQuery(true)
  182. ->select($fields)
  183. ->from('#__zoo_item')
  184. ->where('id = ' . (int) $this->request->id);
  185. $this->db->setQuery($query);
  186. return $this->db->loadObject();
  187. }
  188. private function getCatParentIds($id = 0)
  189. {
  190. $parent_ids = array();
  191. if (!$id)
  192. {
  193. return $parent_ids;
  194. }
  195. while ($id)
  196. {
  197. if (substr($id, 0, 3) == 'app')
  198. {
  199. $parent_ids[] = $id;
  200. break;
  201. }
  202. $query = $this->db->getQuery(true)
  203. ->select('c.parent')
  204. ->from('#__zoo_category AS c')
  205. ->where('c.id = ' . (int) $id);
  206. $this->db->setQuery($query);
  207. $pid = $this->db->loadResult();
  208. if (!$pid)
  209. {
  210. $query = $this->db->getQuery(true)
  211. ->select('c.application_id')
  212. ->from('#__zoo_category AS c')
  213. ->where('c.id = ' . (int) $id);
  214. $this->db->setQuery($query);
  215. $app = $this->db->loadResult();
  216. if ($app)
  217. {
  218. $parent_ids[] = 'app' . $app;
  219. }
  220. break;
  221. }
  222. $parent_ids[] = $pid;
  223. $id = $pid;
  224. }
  225. return $parent_ids;
  226. }
  227. }