3 * Handles the assigning of a ticket to a user. This is being used to make someone responsible for the handling and solving of a ticket.
4 * The idea is that someone can easily assign a ticket to himself and by doing that, he makes aware to the other moderators that he will deal with the ticket in the future.
5 * @author Daan Janssens, mentored by Matthew Lagoe
9 private $user; /**< The id of the user being assigned */
10 private $ticket; /**< The id of the ticket being assigned */
13 ////////////////////////////////////////////Functions////////////////////////////////////////////////////
16 * Assigns a ticket to a user or returns an error message.
17 * It will first check if the ticket isn't already assigned, if not, it will create a new 'assigned' entry.
18 * @param $user_id the id of the user we want to assign to the ticket
19 * @param $ticket_id the id of the ticket.
20 * @return A string, if assigning succeedded "SUCCESS_ASSIGNED" will be returned, else "ALREADY_ASSIGNED" will be returned.
22 public static function assignTicket( $user_id, $ticket_id) {
23 $dbl = new DBLayer("lib");
24 //check if ticket is already assigned, if so return "ALREADY ASSIGNED"
25 if(! Assigned
::isAssigned($ticket_id)){
26 $assignation = new Assigned();
27 $assignation->set(array('User' => $user_id, 'Ticket' => $ticket_id));
28 $assignation->create();
29 return "SUCCESS_ASSIGNED";
31 return "ALREADY_ASSIGNED";
38 * Unassign a ticket being coupled to a user or return an error message.
39 * It will first check if the ticket is assigned, if this is indeed the case it will delete the 'assigned' entry.
40 * @param $user_id the id of the user we want to unassign from the ticket
41 * @param $ticket_id the id of the ticket.
42 * @return A string, if unassigning succeedded "SUCCESS_UNASSIGNED" will be returned, else "NOT_ASSIGNED" will be returned.
44 public static function unAssignTicket( $user_id, $ticket_id) {
45 $dbl = new DBLayer("lib");
46 //check if ticket is really assigned to that user
47 if( Assigned
::isAssigned($ticket_id, $user_id)){
48 $assignation = new Assigned();
49 $assignation->set(array('User' => $user_id, 'Ticket' => $ticket_id));
50 $assignation->delete();
51 return "SUCCESS_UNASSIGNED";
53 return "NOT_ASSIGNED";
59 * Get the (external) id of the user assigned to a ticket
60 * @param $ticket_id the Id of the ticket that's being queried
61 * @return The (external)id of the user being assigned to the ticket
63 public static function getUserAssignedToTicket($ticket_id) {
64 $dbl = new DBLayer("lib");
65 $statement = $dbl->execute("SELECT ticket_user.ExternId FROM `assigned` JOIN `ticket_user` ON assigned.User = ticket_user.TUserId WHERE `Ticket` = :ticket_id", Array('ticket_id' => $ticket_id));
66 $user_id = $statement->fetch();
67 return $user_id['ExternId'];
74 * Check if a ticket is already assigned (in case the user_id param is used, it will check if it's assigned to that user)
75 * @param $ticket_id the Id of the ticket that's being queried
76 * @param $user_id the id of the user, default parameter = 0, by using a user_id, it will check if that user is assigned to the ticket.
77 * @return true in case it's assigned, false in case it isn't.
79 public static function isAssigned( $ticket_id, $user_id = 0) {
80 $dbl = new DBLayer("lib");
81 //check if ticket is already assigned
83 if($user_id == 0 && $dbl->select("`assigned`", array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id")->rowCount() ){
85 }else if( $dbl->select("`assigned`", array('ticket_id' => $ticket_id, 'user_id' => $user_id), "`Ticket` = :ticket_id and `User` = :user_id")->rowCount() ){
92 ////////////////////////////////////////////Methods////////////////////////////////////////////////////
98 public function __construct() {
103 * sets the object's attributes.
104 * @param $values should be an array of the form array('User' => user_id, 'Ticket' => ticket_id).
106 public function set($values) {
107 $this->setUser($values['User']);
108 $this->setTicket($values['Ticket']);
113 * creates a new 'assigned' entry.
114 * this method will use the object's attributes for creating a new 'assigned' entry in the database.
116 public function create() {
117 $dbl = new DBLayer("lib");
118 $dbl->insert("`assigned`", Array('User' => $this->getUser(), 'Ticket' => $this->getTicket()));
123 * deletes an existing 'assigned' entry.
124 * this method will use the object's attributes for deleting an existing 'assigned' entry in the database.
126 public function delete() {
127 $dbl = new DBLayer("lib");
128 $dbl->delete("`assigned`", array('user_id' => $this->getUser() ,'ticket_id' => $this->getTicket()), "`User` = :user_id and `Ticket` = :ticket_id");
132 * loads the object's attributes.
133 * loads the object's attributes by giving a ticket_id, it will put the matching user_id and the ticket_id into the attributes.
134 * @param $ticket_id the id of the ticket that should be loaded
136 public function load($ticket_id) {
137 $dbl = new DBLayer("lib");
138 $statement = $dbl->select("`assigned`", Array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id");
139 $row = $statement->fetch();
144 ////////////////////////////////////////////Getters////////////////////////////////////////////////////
147 * get user attribute of the object.
149 public function getUser(){
155 * get ticket attribute of the object.
157 public function getTicket(){
158 return $this->ticket
;
161 ////////////////////////////////////////////Setters////////////////////////////////////////////////////
164 * set user attribute of the object.
165 * @param $u integer id of the user
167 public function setUser($u){
172 * set ticket attribute of the object.
173 * @param $t integer id of the ticket
175 public function setTicket($t){