-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountcodepatterns.php
59 lines (52 loc) · 2.2 KB
/
countcodepatterns.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
<?php
function buildSqlString($component,$input,$filter){
$components = explode(" ", $component);
$parameters = explode(" ", $input);
if($component==''){
$selectClause = 'SELECT COUNT(DISTINCT(cp.id)) codecount FROM codepattern cp, cptag ct, tag t ';
$whereClause = 'WHERE cp.id = ct.codepatternid AND t.id = ct.tagid AND t.name IN (\''.implode("','",$parameters).'\') ';
if($filter!='ALL')
{$whereClause = $whereClause . 'AND cp.type LIKE \''. $filter .'\' ';}
$sql_query = $selectClause . $whereClause;
}
else if($input==''){
$selectClause = 'SELECT COUNT(DISTINCT(cp.id)) codecount FROM codepattern cp, component c, cpcomponent cpc ';
$whereClause = 'WHERE c.shortcode IN (\''.implode("','",$components).'\') AND cpc.codepatternid = cp.id AND c.id = cpc.componentid ';
if($filter!='ALL')
{$whereClause = $whereClause . 'AND cp.type LIKE \''. $filter .'\' ';}
$sql_query = $selectClause . $whereClause;
}
else{
$selectClause = 'SELECT COUNT(DISTINCT(cp.id)) codecount FROM codepattern cp, cptag ct, tag t, component c, cpcomponent cpc ';
$whereClause = 'WHERE cp.id = ct.codepatternid AND t.id = ct.tagid AND t.name IN (\''.implode("','",$parameters).'\') AND c.shortcode IN (\''.implode("','",$components).'\') AND cpc.codepatternid = cp.id AND c.id = cpc.componentid ';
if($filter!='ALL')
{$whereClause = $whereClause . 'AND cp.type LIKE \''. $filter .'\' ';}
$sql_query = $selectClause . $whereClause;
}
return $sql_query;
}
$input = isset($_GET['searchtext'])?$_GET['searchtext']:'';
$component = isset($_GET['component'])?$_GET['component']:'';
$components = explode(" ", $component);
$parameters = explode(" ", $input);
$filter = isset($_GET['filter'])?$_GET['filter']:'';
$con = mysql_connect("localhost","codesearchuser","codesearchpass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("codesearch", $con);
$sqlString = buildSqlString($component,$input,$filter);
$sql_result = mysql_query($sqlString);
if($sql_result){
$return_arr = array();
while($row = mysql_fetch_array($sql_result,MYSQL_ASSOC))
{
$row_array = array();
$row_array['count'] = $row['codecount'];
array_push($return_arr,$row_array);
}
$json = json_encode($return_arr);
echo $json;
}
?>