PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_roksprocket/lib/RokSprocket/Provider/Seblod/Filter.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 466 lines | 250 code | 60 blank | 156 comment | 13 complexity | d5d473c77f2de35d07a7812b8d2d3f2c MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @author RocketTheme http://www.rockettheme.com
  5. * @copyright Copyright (C) 2007 - 2013 RocketTheme, LLC
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  7. */
  8. class RokSprocket_Provider_Seblod_Filter extends RokSprocket_Provider_AbstractJoomlaPlatformFilter
  9. {
  10. /**
  11. *
  12. * @return void
  13. */
  14. protected function setBaseQuery()
  15. {
  16. $this->query->select('a.id, a.title, a.alias, a.introtext, a.`fulltext`, a.catid' . ', a.state, a.access, a.created, a.created_by, a.created_by_alias, a.modified, a.featured, a.language, a.hits' . ', a.publish_up, a.publish_down, a.images, a.urls, a.language, a.metakey, a.metadesc, a.metadata')->from('#__content as a');
  17. $this->query->select('s.id as core_id, s.cck, s.pk, s.pkb, s.storage_location, s.storage_table, s.author_id, s.parent_id, s.date_time');
  18. $this->query->join('LEFT', '#__cck_core AS s ON s.pk = a.id');
  19. // $this->query->where('s.storage_location = "joomla_article"');
  20. $this->query->select('st.name, st.title AS type_title');
  21. $this->query->join('LEFT', '#__cck_core_types AS st ON st.`name` = s.cck');
  22. $this->query->join('LEFT', '#__cck_core_type_field AS stf ON stf.typeid = st.id');
  23. $this->query->select('sf.name, sf.type, sf.storage_table, sf.storage_field');
  24. $this->query->join('LEFT', '#__cck_core_fields AS sf ON sf.id = stf.fieldid');
  25. $this->query->select('CONCAT(ssf.match_value) as searchable');
  26. $this->query->join('LEFT', '#__cck_core_search_field AS ssf ON ssf.fieldid = stf.fieldid');
  27. $this->query->select('c.title AS category_title, c.alias AS category_alias');
  28. $this->query->join('LEFT', '#__categories AS c ON c.id = a.catid');
  29. $this->query->select('ua.name AS author_name');
  30. $this->query->join('LEFT', '#__users AS ua ON ua.id = a.created_by');
  31. $this->query->select('um.name AS last_modified_by');
  32. $this->query->join('LEFT', '#__users AS um ON um.id = a.modified_by');
  33. $this->query->select('ROUND(v.rating_sum / v.rating_count, 0) AS rating, v.rating_count as rating_count');
  34. $this->query->join('LEFT', '#__content_rating AS v ON a.id = v.content_id');
  35. $this->query->select('vl.title AS access_title');
  36. $this->query->join('LEFT', '#__viewlevels AS vl ON a.access = vl.id');
  37. $this->query->select('l.title AS language_title');
  38. $this->query->join('LEFT', '#__languages AS l ON a.language = l.lang_code');
  39. $this->query->group('a.id');
  40. }
  41. /**
  42. * @param $data
  43. * @return void
  44. */
  45. protected function seblod_application_type($data)
  46. {
  47. $this->numberMatch('st.id', $data);
  48. }
  49. /**
  50. *
  51. * @return void
  52. */
  53. protected function setAccessWhere()
  54. {
  55. $user = JFactory::getUser();
  56. $this->access_where[] = 'a.access IN(' . implode(',', $user->getAuthorisedViewLevels()) . ')';
  57. if (!$this->showUnpublished) {
  58. if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content'))) {
  59. $this->access_where[] = '(a.state = 1 or a.state = 2)';
  60. // Hide any articles that are not in the published date range
  61. $now = JFactory::getDate()->toSql();
  62. $nullDate = $this->db->getNullDate();
  63. $this->access_where[] = '(a.publish_up = ' . $this->db->Quote($nullDate) . ' OR a.publish_up <= ' . $this->db->Quote($now) . ')';
  64. $this->access_where[] = '(a.publish_down = ' . $this->db->Quote($nullDate) . ' OR a.publish_down >= ' . $this->db->Quote($now) . ')';
  65. }
  66. }
  67. $this->access_where[] = '(a.state != -2)';
  68. }
  69. /**
  70. *
  71. */
  72. protected function setDisplayedWhere(){
  73. if (!empty($this->displayedIds) ) {
  74. $this->displayed_where[] = 'a.id NOT IN (' . implode(',', $this->displayedIds) . ')';
  75. }
  76. }
  77. /**
  78. * @param $data
  79. * @return void
  80. */
  81. protected function coretype($data)
  82. {
  83. $this->stringMatch('st.name', $data);
  84. }
  85. /**
  86. * @param $data
  87. * @return void
  88. */
  89. protected function customfield($data)
  90. {
  91. $this->custommatch($data);
  92. }
  93. /**
  94. * @param $data
  95. * @return void
  96. */
  97. protected function id($data)
  98. {
  99. $this->article_where[] = 'a.id IN (' . implode(',', $data) . ')';
  100. }
  101. /**
  102. * @param $data
  103. * @return void
  104. */
  105. protected function article($data)
  106. {
  107. $this->article_where[] = 'a.id IN (' . implode(',', $data) . ')';
  108. }
  109. /**
  110. * @param $data
  111. * @return void
  112. */
  113. protected function author($data)
  114. {
  115. $this->filter_where[] = 'a.created_by IN (' . implode(',', $data) . ')';
  116. }
  117. /**
  118. * @param $data
  119. *
  120. * @return void
  121. */
  122. protected function authoralias($data)
  123. {
  124. $this->textMatch('a.created_by_alias', $data);
  125. }
  126. /**
  127. * @param $data
  128. * @return void
  129. */
  130. protected function modifiedby($data)
  131. {
  132. $this->filter_where[] = ' a.modified_by IN (' . implode(',', $data) . ')';
  133. }
  134. /**
  135. * @param $data
  136. *
  137. * @return void
  138. */
  139. protected function publish_up($data)
  140. {
  141. $this->dateMatch('a.publish_up', $data);
  142. }
  143. /**
  144. * @param $data
  145. *
  146. * @return void
  147. */
  148. protected function publish_down($data)
  149. {
  150. $this->dateMatch('a.publish_down', $data);
  151. }
  152. /**
  153. * @param $data
  154. * @return void
  155. */
  156. protected function category($data)
  157. {
  158. $category_ids = array();
  159. jimport('joomla.application.categories');
  160. foreach ($data as $category_id) {
  161. $category_ids[] = $category_id;
  162. $categories = JCategories::getInstance('Content');
  163. /** @var $category JCategoryNode */
  164. $category = $categories->get($category_id);
  165. /** @var $category JCategoryNode */
  166. if (!empty($categories)) {
  167. $category = $categories->get($category_id);
  168. if ($category && $category->hasChildren()) {
  169. foreach ($category->getChildren(true) as $child_category) {
  170. $category_ids[] = $child_category->id;
  171. }
  172. }
  173. }
  174. }
  175. if (!empty($category_ids)) {
  176. $this->filter_where[] = 'a.catid IN (' . implode(',', $category_ids) . ')';
  177. }
  178. }
  179. /**
  180. * @param $data
  181. * @return void
  182. */
  183. protected function access($data)
  184. {
  185. $this->filter_where[] = 'a.access IN (' . implode(',', $data) . ')';
  186. }
  187. /**
  188. * @param $data
  189. * @return void
  190. */
  191. protected function featured($data)
  192. {
  193. $this->booleanMatch('a.featured', $data);
  194. }
  195. /**
  196. * @param $data
  197. * @return void
  198. */
  199. protected function published($data)
  200. {
  201. $this->booleanMatch('a.state', $data);
  202. }
  203. /**
  204. * @param $data
  205. * @return void
  206. */
  207. protected function title($data)
  208. {
  209. $this->textMatch('a.title', $data);
  210. }
  211. /**
  212. * @param $data
  213. * @return void
  214. */
  215. protected function alias($data)
  216. {
  217. $this->textMatch('a.alias', $data);
  218. }
  219. /**
  220. * @param $data
  221. * @return void
  222. */
  223. protected function rating($data)
  224. {
  225. $this->numberMatch('ROUND(v.rating_sum / v.rating_count, 0)', $data);
  226. }
  227. /**
  228. * @param $data
  229. * @return void
  230. */
  231. protected function hits($data)
  232. {
  233. $this->numberMatch('a.hits', $data);
  234. }
  235. /**
  236. * @param $data
  237. * @return void
  238. */
  239. protected function language($data)
  240. {
  241. $wheres = array();
  242. foreach ($data as $match) {
  243. $wheres[] = 'a.language = ' . $this->db->quote($this->db->escape($match, true));
  244. }
  245. $this->filter_where[] = '(' . implode(' OR ', $wheres) . ')';
  246. }
  247. /**
  248. * @param $data
  249. * @return void
  250. */
  251. protected function createdDate($data)
  252. {
  253. $this->dateMatch('a.created', $data);
  254. }
  255. /**
  256. * @param $data
  257. * @return void
  258. */
  259. protected function modifiedDate($data)
  260. {
  261. $this->dateMatch('a.modified', $data);
  262. }
  263. /**
  264. * @param $data
  265. * @return void
  266. */
  267. protected function articletext($data)
  268. {
  269. $wheres = array();
  270. foreach ($data as $match) {
  271. $match = trim($match);
  272. if (!empty($match)) {
  273. $wheres[] = 'a.introtext like ' . $this->db->quote('%' . $this->db->escape($match, true) . '%');
  274. }
  275. }
  276. if (!empty($wheres)) {
  277. $this->filter_where[] = '(' . implode(' OR ', $wheres) . ')';
  278. }
  279. }
  280. /**
  281. * @param $data
  282. * @return void
  283. */
  284. protected function customMatch($data)
  285. {
  286. $wheres = array();
  287. foreach ($data as $options) {
  288. foreach ($options as $key => $option) {
  289. $key_parts = explode("||", $key);
  290. $storage_name = $key_parts[0];
  291. $storage_field = $key_parts[1];
  292. $wheres[] = 'sf.name' . ' = "' . $storage_name . '"';
  293. foreach ($option as $type => $match) {
  294. switch ($type) {
  295. case 'matches':
  296. break;
  297. case 'contains':
  298. $wheres[] = 's.' . $storage_field . ' like ' . $this->db->quote('%' . $this->db->escape($match, true) . '%');
  299. break;
  300. case 'beginswith':
  301. $wheres[] = 's.' . $storage_field . ' like ' . $this->db->quote($this->db->escape($match, true) . '%');
  302. break;
  303. case 'endswith':
  304. $wheres[] = 's.' . $storage_field . ' like ' . $this->db->quote('%' . $this->db->escape($match, true));
  305. break;
  306. case 'is':
  307. $wheres[] = 's.' . $storage_field . ' = ' . $this->db->quote($this->db->escape($match, true));
  308. break;
  309. default:
  310. $wheres[] = 's.' . $storage_field . ' = "' . $match . '"';
  311. }
  312. }
  313. }
  314. }
  315. $this->filter_where[] = '(' . implode(' OR ', $wheres) . ')';
  316. }
  317. /**
  318. * @param $data
  319. * @return void
  320. */
  321. protected function searchablefield($data)
  322. {
  323. $wheres = array();
  324. foreach ($data as $match) {
  325. $match = trim($match);
  326. if (!empty($match)) {
  327. $wheres[] = 'CONCAT(ssf.matchvalue) like ' . $this->db->quote('%' . $this->db->escape($match, true) . '%');
  328. }
  329. }
  330. if (!empty($wheres)) {
  331. $this->filter_where[] = '(' . implode(' OR ', $wheres) . ')';
  332. }
  333. }
  334. /**
  335. * @param $data
  336. * @return void
  337. */
  338. protected function sort_title($data)
  339. {
  340. $this->normalSortBy('a.title', $data);
  341. }
  342. /**
  343. * @param $data
  344. * @return void
  345. */
  346. protected function sort_alias($data)
  347. {
  348. $this->normalSortBy('a.alias', $data);
  349. }
  350. /**
  351. * @param $data
  352. * @return void
  353. */
  354. protected function sort_category($data)
  355. {
  356. $this->normalSortBy('category_title', $data);
  357. }
  358. /**
  359. * @param $data
  360. * @return void
  361. */
  362. protected function sort_createddate($data)
  363. {
  364. $this->normalSortBy('a.created', $data);
  365. }
  366. /**
  367. * @param $data
  368. * @return void
  369. */
  370. protected function sort_modifieddate($data)
  371. {
  372. $this->normalSortBy('a.modified', $data);
  373. }
  374. /**
  375. * @param $data
  376. * @return void
  377. */
  378. protected function sort_modifiedby($data)
  379. {
  380. $this->normalSortBy('last_modified_by', $data);
  381. }
  382. /**
  383. * @param $data
  384. * @return void
  385. */
  386. protected function sort_author($data)
  387. {
  388. $this->normalSortBy('author_name', $data);
  389. }
  390. /**
  391. * @param $data
  392. * @return void
  393. */
  394. protected function sort_rating($data)
  395. {
  396. $this->normalSortBy('rating', $data);
  397. }
  398. /**
  399. * @param $data
  400. * @return void
  401. */
  402. protected function sort_hits($data)
  403. {
  404. $this->normalSortBy('a.hits', $data);
  405. }
  406. }