khanat-opennel-code/code/web/private_php/ams/autoload/forwarded.php

156 lines
4.9 KiB
PHP
Raw Normal View History

2013-07-22 11:19:21 +00:00
<?php
/**
* Handles the forwarding of a ticket to a support_group. This is being used to transfer tickets to different groups (eg Developers, Website-Team, SupportGroup etc..)
* The idea is that someone can easily forward a ticket to a group and by doing that, the moderators that are in that group will receive the ticket in their todo queue.
* @author Daan Janssens, mentored by Matthew Lagoe
*
*/
class Forwarded{
2013-07-22 11:19:21 +00:00
private $group; /**< The id of the group to which the ticket is being forwarded */
private $ticket; /**< The id of the ticket being forwarded */
2013-07-22 11:19:21 +00:00
////////////////////////////////////////////Functions////////////////////////////////////////////////////
/**
* Forward a ticket to a group, also removes the previous group where it was forwarded to.
* It will first check if the ticket is already forwarded, if that's the case, it will delete that entry.
* Afterwards it creates the new forward entry
* @param $group_id the id of the support group we want to forward the ticket to.
* @param $ticket_id the id of the ticket.
* @return A string, if assigning succeedded "SUCCESS_FORWARDED" will be returned.
*/
2013-07-22 11:19:21 +00:00
public static function forwardTicket( $group_id, $ticket_id) {
$dbl = new DBLayer("lib");
if (forwarded::isForwarded($ticket_id)){
$forw = new Forwarded();
$forw->load($ticket_id);
$forw->delete();
}
$forward = new Forwarded();
$forward->set(array('Group' => $group_id, 'Ticket' => $ticket_id));
$forward->create();
return "SUCCESS_FORWARDED";
}
/**
* get the id of the group a ticket is forwarded to.
* @param $ticket_id the id of the ticket.
* @return the id of the group
*/
public static function getSGroupOfTicket($ticket_id) {
$forw = new self();
$forw->load($ticket_id);
return $forw->getGroup();
}
2013-07-22 11:19:21 +00:00
/**
* check if the ticket is forwarded
* @param $ticket_id the id of the ticket.
* @return returns true if the ticket is forwarded, else return false;
*/
2013-07-22 11:19:21 +00:00
public static function isForwarded( $ticket_id) {
$dbl = new DBLayer("lib");
if( $dbl->select("`forwarded`", array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id")->rowCount() ){
2013-07-22 11:19:21 +00:00
return true;
}else{
return false;
}
}
////////////////////////////////////////////Methods////////////////////////////////////////////////////
/**
* A constructor.
* Empty constructor
*/
2013-07-22 11:19:21 +00:00
public function __construct() {
}
/**
* sets the object's attributes.
* @param $values should be an array of the form array('Group' => group_id, 'Ticket' => ticket_id).
*/
2013-07-22 11:19:21 +00:00
public function set($values) {
$this->setGroup($values['Group']);
$this->setTicket($values['Ticket']);
}
/**
* creates a new 'forwarded' entry.
* this method will use the object's attributes for creating a new 'forwarded' entry in the database.
*/
2013-07-22 11:19:21 +00:00
public function create() {
$dbl = new DBLayer("lib");
$dbl->insert("`forwarded`", Array('Group' => $this->getGroup(), 'Ticket' => $this->getTicket()));
2013-07-22 11:19:21 +00:00
}
/**
* deletes an existing 'forwarded' entry.
* this method will use the object's attributes for deleting an existing 'forwarded' entry in the database.
*/
2013-07-22 11:19:21 +00:00
public function delete() {
$dbl = new DBLayer("lib");
$dbl->delete("`forwarded`", array('group_id' => $this->getGroup() ,'ticket_id' => $this->getTicket(), "`Group` = :group_id and `Ticket` = :ticket_id");
2013-07-22 11:19:21 +00:00
}
/**
* loads the object's attributes.
* loads the object's attributes by giving a ticket_id, it will put the matching group_id and the ticket_id into the attributes.
* @param $ticket_id the id of the ticket that should be loaded
*/
2013-07-22 11:19:21 +00:00
public function load( $ticket_id) {
$dbl = new DBLayer("lib");
$statement = $dbl->select("`forwarded`", Array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id");
2013-07-22 11:19:21 +00:00
$row = $statement->fetch();
$this->set($row);
}
////////////////////////////////////////////Getters////////////////////////////////////////////////////
/**
* get group attribute of the object.
*/
2013-07-22 11:19:21 +00:00
public function getGroup(){
return $this->group;
}
/**
* get ticket attribute of the object.
*/
2013-07-22 11:19:21 +00:00
public function getTicket(){
return $this->ticket;
}
////////////////////////////////////////////Setters////////////////////////////////////////////////////
/**
* set group attribute of the object.
* @param $g integer id of the group
*/
2013-07-22 11:19:21 +00:00
public function setGroup($g){
$this->group = $g;
}
/**
* set ticket attribute of the object.
* @param $t integer id of the ticket
*/
2013-07-22 11:19:21 +00:00
public function setTicket($t){
$this->ticket = $t;
}
}