-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfearch.module
More file actions
94 lines (81 loc) · 2.44 KB
/
Copy pathfearch.module
File metadata and controls
94 lines (81 loc) · 2.44 KB
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
<?php
function fearch_views_pre_render(&$view)
{
if ($view->name == "knowledge_center" && user_is_logged_in())
{
$viewInput = strtolower($view->exposed_raw_input['combine_1']);
if ($viewInput == "")
{
return;
}
$viewQuery = split(' ', $viewInput);
$whereClause = "";
$parameters = array();
// 1=1 is a terrible and lazy hack
$baseQuery = "SELECT * FROM fearch_article a WHERE 1=1 ";
for ($i=0; $i < count($viewQuery); ++$i)
{
if ($viewQuery[$i] != "")
{
$whereClause .= "AND (SELECT count(*) FROM fearch_word_article_view WHERE aid = a.id AND word like :p" . (string)$i . ") > 0 ";
$parameters[":p" . $i] = "%" . db_like($viewQuery[$i]) . "%";
}
}
$whereClause .= ";";
$result = db_query($baseQuery . $whereClause, $parameters)->fetchAll();
$group = array();
// Put everthing into an object for grouping purposes
for ($i=0; $i < count($result); ++$i)
{
// Set the group as dir
$dir = split('/', $result[$i]->uri);
$dir = str_replace('_', ' ', $dir[0]);
if ($group[$dir])
{
if ($group[$dir]["count"] <= 10)
{
$group[$dir]["count"] += 1;
$group[$dir]["content"] .= '<div class="views-row kc-item">
<span class="views-field views-field-title">
<strong class="field-content">
<a href="' . $result[$i]->uri . '" target="_blank">' . $result[$i]->name . '</a>
</strong>
</span>
<div class="views-field views-field-body">
<span class="field-content">
' . $result[$i]->preview . '
</span>
</div>
</div>';
}
else
{
// More than 10 results returned
$group[$dir]["more"] = true;
}
}
else
{
$group[$dir]["content"] = '<div class="views-row kc-item">
<span class="views-field views-field-title">
<strong class="field-content">
<a href="' . $result[$i]->uri . '" target="_blank">' . $result[$i]->name . '</a>
</strong>
</span>
<div class="views-field views-field-body">
<span class="field-content">
' . $result[$i]->preview . '
</span>
</div>
</div>';
$group[$dir]["count"] = 1;
}
}
$attachment = "";
foreach ($group as $key => $value)
{
$attachment .= "<p> <h1>" . $key . "</p> </h1> <br> " . $value["content"] . ($value["more"] ? "<br> <p> Set limited to 10 results. Include more specific search terms for more accurate results.</p>" : "");
}
$view->attachment_after = $attachment;
}
}