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

/favorites/admin/models/scopes.php

https://github.com/dioscouri/favorites
PHP | 105 lines | 82 code | 14 blank | 9 comment | 10 complexity | c74b6ab1d777a6f8ff9ec44da1cdda0f MD5 | raw file
  1. <?php
  2. /**
  3. * @version 1.5
  4. * @package Tags
  5. * @author Dioscouri Design
  6. * @link http://www.dioscouri.com
  7. * @copyright Copyright (C) 2007 Dioscouri Design. All rights reserved.
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  9. */
  10. /** ensure this file is being included by a parent file */
  11. defined('_JEXEC') or die('Restricted access');
  12. Favorites::load( 'FavoritesModelBase', 'models.base' );
  13. class FavoritesModelScopes extends FavoritesModelBase
  14. {
  15. protected function _buildQueryWhere(&$query)
  16. {
  17. $filter = $this->getState('filter');
  18. $filter_id_from = $this->getState('filter_id_from');
  19. $filter_id_to = $this->getState('filter_id_to');
  20. $filter_name = $this->getState('filter_name');
  21. $filter_identifier = $this->getState('filter_identifier');
  22. $filter_url = $this->getState('filter_url');
  23. $filter_table = $this->getState('filter_table');
  24. $filter_table_field = $this->getState('filter_table_field');
  25. $filter_table_name_field = $this->getState('filter_table_name_field');
  26. if ($filter)
  27. {
  28. $key = $this->_db->Quote('%'.$this->_db->getEscaped( trim( strtolower( $filter ) ) ).'%');
  29. $where = array();
  30. $where[] = 'LOWER(tbl.scope_id) LIKE '.$key;
  31. $where[] = 'LOWER(tbl.scope_name) LIKE '.$key;
  32. $where[] = 'LOWER(tbl.scope_identifier) LIKE '.$key;
  33. $where[] = 'LOWER(tbl.scope_url) LIKE '.$key;
  34. $query->where('('.implode(' OR ', $where).')');
  35. }
  36. if (strlen($filter_id_from))
  37. {
  38. if (strlen($filter_id_to))
  39. {
  40. $query->where('tbl.scope_id >= '.(int) $filter_id_from);
  41. }
  42. else
  43. {
  44. $query->where('tbl.scope_id = '.(int) $filter_id_from);
  45. }
  46. }
  47. if (strlen($filter_id_to))
  48. {
  49. $query->where('tbl.scope_id <= '.(int) $filter_id_to);
  50. }
  51. if (strlen($filter_name))
  52. {
  53. $key = $this->_db->Quote('%'.$this->_db->getEscaped( trim( strtolower( $filter_name ) ) ).'%');
  54. $query->where('LOWER(tbl.scope_name) LIKE '.$key);
  55. }
  56. if (strlen($filter_identifier))
  57. {
  58. $key = $this->_db->Quote('%'.$this->_db->getEscaped( trim( strtolower( $filter_identifier ) ) ).'%');
  59. $query->where('LOWER(tbl.scope_identifier) LIKE '.$key);
  60. }
  61. if (strlen($filter_url))
  62. {
  63. $key = $this->_db->Quote('%'.$this->_db->getEscaped( trim( strtolower( $filter_url ) ) ).'%');
  64. $query->where('LOWER(tbl.scope_url) LIKE '.$key);
  65. }
  66. if (strlen($filter_table))
  67. {
  68. $key = $this->_db->Quote('%'.$this->_db->getEscaped( trim( strtolower( $filter_table ) ) ).'%');
  69. $query->where('LOWER(tbl.scope_table) LIKE '.$key);
  70. }
  71. if (strlen($filter_table_field))
  72. {
  73. $key = $this->_db->Quote('%'.$this->_db->getEscaped( trim( strtolower( $filter_table_field ) ) ).'%');
  74. $query->where('LOWER(tbl.scope_table_field) LIKE '.$key);
  75. }
  76. if (strlen($filter_table_name_field))
  77. {
  78. $key = $this->_db->Quote('%'.$this->_db->getEscaped( trim( strtolower( $filter_table_name_field ) ) ).'%');
  79. $query->where('LOWER(tbl.scope_table_name_field) LIKE '.$key);
  80. }
  81. }
  82. public function getList($refresh = false)
  83. {
  84. $list = parent::getList($refresh);
  85. foreach(@$list as $item)
  86. {
  87. $item->link = 'index.php?option=com_favorites&view=scopes&task=edit&id='.$item->scope_id;
  88. }
  89. return $list;
  90. }
  91. }