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

156 lines
4.8 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
2014-09-03 02:46:08 +00:00
*
*/
class Forwarded{
2014-09-03 02:46:08 +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////////////////////////////////////////////////////
2014-09-03 02:46:08 +00:00
/**
* 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";
2014-09-03 02:46:08 +00:00
2013-07-22 11:19:21 +00:00
}
2014-09-03 02:46:08 +00:00
/**
* 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();
}
2014-09-03 02:46:08 +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;
2014-09-03 02:46:08 +00:00
}
2013-07-22 11:19:21 +00:00
}
2014-09-03 02:46:08 +00:00
2013-07-22 11:19:21 +00:00
////////////////////////////////////////////Methods////////////////////////////////////////////////////
2014-09-03 02:46:08 +00:00
/**
* A constructor.
* Empty constructor
*/
2013-07-22 11:19:21 +00:00
public function __construct() {
}
2014-09-03 02:46:08 +00:00
/**
* 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']);
}
2014-09-03 02:46:08 +00:00
/**
* 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
}
2014-09-03 02:46:08 +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");
2014-09-03 02:46:08 +00:00
$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);
}
2014-09-03 02:46:08 +00:00
2013-07-22 11:19:21 +00:00
////////////////////////////////////////////Getters////////////////////////////////////////////////////
2014-09-03 02:46:08 +00:00
/**
* get group attribute of the object.
*/
2013-07-22 11:19:21 +00:00
public function getGroup(){
return $this->group;
}
2014-09-03 02:46:08 +00:00
/**
* get ticket attribute of the object.
*/
2013-07-22 11:19:21 +00:00
public function getTicket(){
return $this->ticket;
}
2014-09-03 02:46:08 +00:00
2013-07-22 11:19:21 +00:00
////////////////////////////////////////////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;
}
2014-09-03 02:46:08 +00:00
/**
* 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;
}
2014-09-03 02:46:08 +00:00
}