-
Notifications
You must be signed in to change notification settings - Fork 1
/
einsatzkomponente.php
217 lines (179 loc) · 6.88 KB
/
einsatzkomponente.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/**
* @package Joomla.Plugin
* @subpackage Search.Einsatzkomponente
*
* @copyright Copyright (C) 2016 - Julian Schäfer
* @license GNU/GPL Lizenz
*******************************************************************************************************
* Dieses Plugin erweitert die Standard-Joomlasuche mit Einsatzberichten aus der Einsatzkomponente V3.x
*******************************************************************************************************
*/
// To prevent accessing the document directly
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
//for joomla 2.5
jimport('joomla.plugin.plugin');
// Require the component's router file
require_once JPATH_ROOT. '/components/com_einsatzkomponente/router.php';
/*
* All functions need to get wrapped in a class
*/
class plgSearchEinsatzkomponente extends JPlugin
{
/**
* Constructor
*
* @access protected
* @param object $subject The object to observe
* @param array $config An array that holds the plugin configuration
* @since 1.6
*/
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
$this->loadLanguage();
}
// Define a function to return an array of search areas.
// Note the value of the array key is normally a language string
function onContentSearchAreas()
{
static $areas = array(
'einsatzkomponente' => 'PLG_SEARCH_EINSATZKOMPONENTE_NAME_SEARCH_AREA'
);
return $areas;
}
/**
* The sql must return the following fields that are used in a common display
* routine: href, title, section, created, text, browsernav
*
* @param string Target search string
* @param string mathcing option, exact|any|all
* @param string ordering option, newest|oldest|popular|alpha|category
* @param mixed An array if the search it to be restricted to areas, null if search all
*/
function onContentSearch( $text, $phrase='', $ordering='', $areas=null )
{
$db = JFactory::getDbo();
$user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
// If the array is not correct, return it:
if (is_array( $areas )) {
if (!array_intersect( $areas, array_keys( $this->onContentSearchAreas() ) )) {
return array();
}
}
// Now retrieve the plugin parameters :
$openInWindow = $this->params->get('openInWindow', 1 );
$showOrga = $this->params->get('showOrga', 0 );
$showAddress = $this->params->get('showAddress', 0 );
$showType = $this->params->get('showType', 0 );
$showCat = $this->params->get('showCat', 0 );
$searchAddress = $this->params->get('searchAddress', 0 );
$searchBoss = $this->params->get('searchBoss', 0 );
$searchBoss2 = $this->params->get('searchBoss2', 0 );
$searchCat = $this->params->get('searchCat', 0 );
$searchType = $this->params->get('searchType', 0 );
// Use the PHP function trim to delete spaces in front of or at the back of the searching terms
$text = trim( $text );
// Return Array when nothing was filled in.
if ($text == '') {
return array();
}
// The database part
$wheres = array();
switch ($phrase) {
// Search exact
case 'exact':
$text = $db->Quote( '%'.$db->escape( $text, true ).'%', false );
$wheres2 = array();
$wheres2[] = 'a.summary LIKE '.$text;
$wheres2[] = 'a.desc LIKE '.$text;
$wheres2[] = 'd.name LIKE '.$text;
if($searchAddress == 1):$wheres2[] = 'a.address LIKE '.$text; endif;
if($searchBoss == 1): $wheres2[] = 'a.boss LIKE '.$text; endif;
if($searchBoss2 == 1): $wheres2[] = 'a.boss2 LIKE '.$text; endif;
if($searchCat == 1): $wheres2[] = 'b.title LIKE '.$text; endif;
if($searchType == 1): $wheres2[] = 'c.title LIKE '.$text; endif;
$where = '(' . implode( ') OR (', $wheres2 ) . ')';
break;
// Search all or any
case 'all':
case 'any':
// Set default
default:
$words = explode( ' ', $text );
$wheres = array();
foreach ($words as $word)
{
$word = $db->Quote( '%'.$db->escape( $word, true ).'%', false );
$wheres2 = array();
$wheres2[] = 'LOWER(a.summary) LIKE '.$word;
$wheres2[] = 'LOWER(a.desc) LIKE '.$word;
$wheres2[] = 'LOWER(d.name) LIKE '.$word;
if($searchAddress == 1): $wheres2[] = 'LOWER(a.address) LIKE '.$word; endif;
if($searchBoss == 1): $wheres2[] = 'LOWER(a.boss) LIKE '.$word; endif;
if($searchBoss2 == 1): $wheres2[] = 'LOWER(a.boss2) LIKE '.$word; endif;
if($searchCat == 1): $wheres2[] = 'LOWER(b.title) LIKE '.$word; endif;
if($searchType == 1): $wheres2[] = 'LOWER(c.title) LIKE '.$word; endif;
$wheres[] = implode( ' OR ', $wheres2 );
}
$where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
break;
}
// Ordering of the results
switch ( $ordering ) {
//Alphabetic, ascending
case 'alpha':
$order = 'a.summary ASC';
break;
// Oldest first
case 'oldest':
$order = 'a.date1 ASC';
break;
// Popular first
case 'popular':
$order = 'a.counter DESC';
break;
// Newest first
case 'newest':
$order = 'a.date1 DESC';
break;
// Default setting: alphabetic, ascending
default:
$order = 'a.date1 ASC';
}
// Replace nameofplugin
$section = JText::_( 'PLG_SEARCH_EINSATZKOMPONENTE_NAME_PLUGIN' );
// The database query
$query = $db->getQuery(true);
$query->select('a.id, a.data1, a.address, a.date1, a.counter, a.summary, a.desc, a.tickerkat, a.auswahl_orga, a.boss, a.boss2, b.title AS type, c.title AS category, d.name AS orga');
$query->from('#__eiko_einsatzberichte AS a');
$query->leftJoin('#__eiko_tickerkat as b ON b.id = a.tickerkat');
$query->leftJoin('#__eiko_einsatzarten as c ON c.id = a.data1');
$query->leftJoin('#__eiko_organisationen as d ON d.id = a.auswahl_orga');
$query->where('('. $where .')' . 'AND a.state = 1' );
$query->order($order);
// Set query
$db->setQuery($query);
$rows = $db->loadObjectList();
// The 'output' of the displayed link
$params = JComponentHelper::getParams('com_einsatzkomponente');
foreach($rows as $key => $row) {
$rows[$key]->title = $row->summary;
$rows[$key]->title .= ($showOrga AND $showAddress) ? ' (' . $row->orga .' | ' . $row->address .')' : '';
$rows[$key]->title .= ($showOrga AND !$showAddress) ? ' (' . $row->orga .')' : '';
$rows[$key]->title .= ($showAddress AND !$showOrga) ? ' (' . $row->address .')' : '';
$rows[$key]->section = $section;
$rows[$key]->section .= ($showCat) ? ' | ' . $row->category : '';
$rows[$key]->section .= ($showType) ? ' | ' . $row->type : '';
$rows[$key]->href = JRoute::_('index.php?option=com_einsatzkomponente&view=einsatzbericht&id='.$row->id.'&Itemid='.$params->get('homelink',''));
$rows[$key]->created = $row->date1;
$rows[$key]->text = $row->desc;
$rows[$key]->browsernav = ($openInWindow) ? 1 : 0;
}
//Return the search results in an array
return $rows;
}
}
?>