Skip to content

Commit dc64f24

Browse files
committed
Create tasks.class
Is now possible to fetch Tasks: by CreationDate by Ticket Specific Task
1 parent e42776c commit dc64f24

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed

ost_wbs/classes/class.tasks.php

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?php
2+
class Tasks
3+
{
4+
public function all($parameters)
5+
{
6+
// Escape Parameters
7+
$parameters['parameters'] = Helper::escapeParameters($parameters["parameters"]);
8+
9+
// Check Request method
10+
$validRequests = array("GET");
11+
Helper::validRequest($validRequests);
12+
13+
// Connect Database
14+
$Dbobj = new DBConnection();
15+
$mysqli = $Dbobj->getDBConnect();
16+
17+
switch ($parameters["sort"]) {
18+
// Sorte by Date
19+
case "creationDate":
20+
21+
// Get Start&End Date
22+
$startDate = $parameters['parameters']['start_date'];
23+
$endDate = $parameters['parameters']['end_date'];
24+
$ticketId = $parameters['parameters']['ticket_id'];
25+
26+
// Query
27+
$getTask = $mysqli->query("select
28+
".TABLE_PREFIX."task.id,
29+
".TABLE_PREFIX."task__cdata.task_id,
30+
".TABLE_PREFIX."task.id,
31+
".TABLE_PREFIX."thread.object_id,
32+
".TABLE_PREFIX."thread.id,
33+
".TABLE_PREFIX."thread_entry.thread_id,
34+
".TABLE_PREFIX."task.created,
35+
".TABLE_PREFIX."task.object_id,
36+
".TABLE_PREFIX."task.object_type,
37+
".TABLE_PREFIX."thread.object_type,
38+
".TABLE_PREFIX."task__cdata.title as title,
39+
".TABLE_PREFIX."thread_entry.body as body
40+
FROM ".TABLE_PREFIX."task
41+
LEFT JOIN ".TABLE_PREFIX."task__cdata ON ".TABLE_PREFIX."task.id = ".TABLE_PREFIX."task__cdata.task_id
42+
LEFT JOIN ".TABLE_PREFIX."thread ON ".TABLE_PREFIX."task.id = ".TABLE_PREFIX."thread.object_id
43+
LEFT JOIN ".TABLE_PREFIX."thread_entry ON ".TABLE_PREFIX."thread.id = ".TABLE_PREFIX."thread_entry.thread_id
44+
WHERE ".TABLE_PREFIX."task.created >= '".$startDate."'
45+
AND ".TABLE_PREFIX."task.created <= '".$endDate."'
46+
AND ".TABLE_PREFIX."task.object_id = ".$ticketId."
47+
AND ".TABLE_PREFIX."task.object_type = 'T'
48+
AND ".TABLE_PREFIX."thread.object_type = 'A'");
49+
50+
break;
51+
case "byTicket":
52+
53+
// Get TicketID
54+
$ticketId = $parameters['parameters']['ticket_id'];
55+
56+
// Query
57+
$getTask = $mysqli->query("select
58+
".TABLE_PREFIX."task.id,
59+
".TABLE_PREFIX."task__cdata.task_id,
60+
".TABLE_PREFIX."task.id,
61+
".TABLE_PREFIX."thread.object_id,
62+
".TABLE_PREFIX."thread.id,
63+
".TABLE_PREFIX."thread_entry.thread_id,
64+
".TABLE_PREFIX."task.created,
65+
".TABLE_PREFIX."task.object_id,
66+
".TABLE_PREFIX."task.object_type,
67+
".TABLE_PREFIX."thread.object_type,
68+
".TABLE_PREFIX."task__cdata.title as title,
69+
".TABLE_PREFIX."thread_entry.body as body
70+
FROM ".TABLE_PREFIX."task
71+
LEFT JOIN ".TABLE_PREFIX."task__cdata ON ".TABLE_PREFIX."task.id = ".TABLE_PREFIX."task__cdata.task_id
72+
LEFT JOIN ".TABLE_PREFIX."thread ON ".TABLE_PREFIX."task.id = ".TABLE_PREFIX."thread.object_id
73+
LEFT JOIN ".TABLE_PREFIX."thread_entry ON ".TABLE_PREFIX."thread.id = ".TABLE_PREFIX."thread_entry.thread_id
74+
WHERE ".TABLE_PREFIX."task.object_id = ".$ticketId."
75+
AND ".TABLE_PREFIX."task.object_type = 'T'
76+
AND ".TABLE_PREFIX."thread.object_type = 'A'");
77+
78+
break;
79+
default:
80+
throw new Exception("Unknown Parameter.");
81+
break;
82+
}
83+
84+
// Array that stores all results
85+
$result = array();
86+
$numRows = $getTask->num_rows;
87+
88+
// Fetch data
89+
while($printTask = $getTask->fetch_object())
90+
{
91+
array_push($result,
92+
array(
93+
'task_id'=>$printTask->id,
94+
'title'=>utf8_encode($printTask->title),
95+
'description'=>utf8_encode($printTask->body),
96+
'created'=>$printTask->created
97+
));
98+
99+
}
100+
101+
// Check if there are some results in the array
102+
if(!$result){
103+
throw new Exception("No items found.");
104+
}
105+
106+
// build return array
107+
$returnArray = array('total' => $numRows, 'tasks' => $result);
108+
109+
// Return values
110+
return $returnArray;
111+
}
112+
113+
public function specific($parameters)
114+
{
115+
// Escape Parameters
116+
$parameters['parameters'] = Helper::escapeParameters($parameters["parameters"]);
117+
118+
// Check Request method
119+
$validRequests = array("GET");
120+
Helper::validRequest($validRequests);
121+
122+
// Connect Database
123+
$Dbobj = new DBConnection();
124+
$mysqli = $Dbobj->getDBConnect();
125+
$taskID = $parameters["parameters"]["id"];
126+
127+
// set query
128+
$getTask = $mysqli->query("select
129+
130+
".TABLE_PREFIX."task__cdata.task_id,
131+
".TABLE_PREFIX."thread.object_id,
132+
".TABLE_PREFIX."thread.id,
133+
".TABLE_PREFIX."task.id,
134+
".TABLE_PREFIX."thread_entry.thread_id,
135+
".TABLE_PREFIX."task.created,
136+
".TABLE_PREFIX."task.object_id,
137+
".TABLE_PREFIX."task.object_type,
138+
".TABLE_PREFIX."thread.object_type,
139+
".TABLE_PREFIX."task__cdata.title as title,
140+
".TABLE_PREFIX."thread_entry.body as body
141+
FROM ".TABLE_PREFIX."task
142+
INNER JOIN ".TABLE_PREFIX."task__cdata ON ".TABLE_PREFIX."task.id = ".TABLE_PREFIX."task__cdata.task_id
143+
INNER JOIN ".TABLE_PREFIX."thread ON ".TABLE_PREFIX."task.id = ".TABLE_PREFIX."thread.object_id
144+
INNER JOIN ".TABLE_PREFIX."thread_entry ON ".TABLE_PREFIX."thread.id = ".TABLE_PREFIX."thread_entry.thread_id
145+
AND ".TABLE_PREFIX."task.id = ".$taskID."
146+
AND ".TABLE_PREFIX."task.object_type = 'T'
147+
AND ".TABLE_PREFIX."thread.object_type = 'A'");
148+
149+
// Array that stores all results
150+
$result = array();
151+
$numRows = $getTask->num_rows;
152+
153+
// Fetch data
154+
while($printTask = $getTask->fetch_object())
155+
{
156+
array_push($result,
157+
array(
158+
'task_id'=>$printTask->id,
159+
'title'=>utf8_encode($printTask->title),
160+
'description'=>utf8_encode($printTask->body),
161+
'created'=>$printTask->created
162+
));
163+
}
164+
165+
// Check if there are some results in the array
166+
if(!$result){
167+
throw new Exception("No items found.");
168+
}
169+
170+
// build return array
171+
$returnArray = array('total' => $numRows, 'tasks' => $result);
172+
173+
// Return values
174+
return $returnArray;
175+
}
176+
177+
}
178+
?>

0 commit comments

Comments
 (0)