mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-24 01:48:44 +00:00
Added ticket class | added ticket_user class| added ticket_category class. These aren't tested yet, so expect errors and changes! :D
--HG-- branch : quitta-gsoc-2013
This commit is contained in:
parent
b163ab7960
commit
ff96e6db5e
6 changed files with 273 additions and 13 deletions
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
namespace Ams_Tickets;
|
||||
|
||||
class Ticket{
|
||||
private $tId;
|
||||
private $timestamp;
|
||||
private $title;
|
||||
private $status;
|
||||
private $queue;
|
||||
private $ticket_category;
|
||||
private $author;
|
||||
private $db;
|
||||
|
||||
public function __construct($db_data) {
|
||||
$this->db = $db_data;
|
||||
}
|
||||
|
||||
|
||||
//Set ticket object
|
||||
public function setTicket($ts,$t,$s,$q,$t_c,$a){
|
||||
$this->timestamp = $ts;
|
||||
$this->title = $t;
|
||||
$this->status = $s;
|
||||
$this->queue = $q;
|
||||
$this->ticket_category = $t_c;
|
||||
$this->author = $a;
|
||||
}
|
||||
|
||||
//create ticket by writing private data to DB.
|
||||
public function create(){
|
||||
$dbl = new DBLayer($this->db);
|
||||
$query = "INSERT INTO ticket (Timestamp, Title, Status, Queue, Ticket_Category, Author) VALUES (:timestamp, :title, :status, :queue, :tcat, :author)";
|
||||
$values = Array('timestamp' => $this->timestamp, 'title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author);
|
||||
$dbl->execute($query, $values);
|
||||
}
|
||||
|
||||
//return constructed element based on TId
|
||||
public function load_With_TId( $id) {
|
||||
$dbl = new DBLayer($this->db);
|
||||
$statement = $dbl->execute("SELECT * FROM ticket WHERE TId=:id", array('id' => $id));
|
||||
$row = $statement->fetch();
|
||||
$this->tId = $row['TId'];
|
||||
$this->timestamp = $row['Timestamp'];
|
||||
$this->title = $row['Title'];
|
||||
$this->status = $row['Status'];
|
||||
$this->queue = $row['Queue'];
|
||||
$this->ticket_category = $row['Ticket_Category'];
|
||||
$this->author = $row['Author'];
|
||||
}
|
||||
|
||||
|
||||
//update private data to DB.
|
||||
public function update(){
|
||||
$dbl = new DBLayer($this->db);
|
||||
$query = "UPDATE ticket SET Timestamp = :timestamp, Title = :title, Status = :status, Queue = :queue, Ticket_Category = :tcat, Author = :author WHERE TId=:id";
|
||||
$values = Array('id' => $this->tId, 'timestamp' => $this->timestamp, 'title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author);
|
||||
$statement = $dbl->execute($query, $values);
|
||||
}
|
||||
|
||||
//Getters
|
||||
public function getPermission(){
|
||||
return $this->permission;
|
||||
}
|
||||
|
||||
|
||||
public function getExternId(){
|
||||
return $this->externId;
|
||||
}
|
||||
|
||||
|
||||
public function getTUserId(){
|
||||
return $this->tUserId;
|
||||
}
|
||||
|
||||
//setters
|
||||
public function setPermission($perm){
|
||||
$this->permission = $perm;
|
||||
}
|
||||
|
||||
|
||||
public function setExternId($id){
|
||||
$this->externId = $id;
|
||||
}
|
||||
|
||||
|
||||
public function setTUserId($id){
|
||||
$this->tUserId = $id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
namespace Ams_Tickets;
|
||||
|
||||
class Ticket_Category{
|
||||
|
||||
private $tCategoryId;
|
||||
private $name;
|
||||
|
||||
public function __construct($db_data) {
|
||||
$this->db = $db_data;
|
||||
}
|
||||
|
||||
|
||||
//Creates a ticket_Catergory in the DB
|
||||
public static function createTicketCategory( $name ,$db ) {
|
||||
$dbl = new DBLayer($db);
|
||||
$query = "INSERT INTO ticket_category (Name) VALUES (:name)";
|
||||
$values = Array('name' => $name);
|
||||
$dbl->execute($query, $values);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//return constructed element based on TCategoryId
|
||||
public static function constr_TCategoryId( $id, $db_data) {
|
||||
$instance = new self($db_data);
|
||||
$instance->setTCategoryId($id);
|
||||
return $instance;
|
||||
|
||||
}
|
||||
|
||||
//return constructed element based on TCategoryId
|
||||
public function load_With_TCategoryId( $id) {
|
||||
$dbl = new DBLayer($this->db);
|
||||
$statement = $dbl->execute("SELECT * FROM ticket_category WHERE TCategoryId=:id", array('id' => $id));
|
||||
$row = $statement->fetch();
|
||||
$instance->tCategoryId = $row['TCategoryId'];
|
||||
$instance->name = $row['Name'];
|
||||
return $instance;
|
||||
}
|
||||
|
||||
//update private data to DB.
|
||||
public function update(){
|
||||
$dbl = new DBLayer($this->db);
|
||||
$query = "UPDATE ticket_category SET Name = :name WHERE TCategoryId=:id";
|
||||
$values = Array('id' => $this->tCategoryId, 'name' => $this->name);
|
||||
$statement = $dbl->execute($query, $values);
|
||||
}
|
||||
|
||||
//Getters
|
||||
public function getName(){
|
||||
if ($this->name == ""){
|
||||
$this->load_With_TCategoryId($this->tCategoryId);
|
||||
}
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
public function getTCategoryId(){
|
||||
return $this->tCategoryId;
|
||||
}
|
||||
|
||||
|
||||
//setters
|
||||
public function setName($n){
|
||||
$this->name = $n;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
namespace Ams_Tickets;
|
||||
|
||||
class Ticket_User{
|
||||
|
||||
private $tUserId;
|
||||
private $permission;
|
||||
private $externId;
|
||||
private $db;
|
||||
|
||||
public function __construct($db_data) {
|
||||
$this->db = $db_data;
|
||||
}
|
||||
|
||||
|
||||
//Creates a ticket_user in the DB
|
||||
public static function createTicketUser( $extern_id, $permission,$db ) {
|
||||
$dbl = new DBLayer($db);
|
||||
$query = "INSERT INTO ticket_user (Permission, ExternId) VALUES (:perm, :ext_id)";
|
||||
$values = Array('perm' => $permission, 'ext_id' => $extern_id);
|
||||
$dbl->execute($query, $values);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//return constructed element based on TUserId
|
||||
public static function constr_TUserId( $id, $db_data) {
|
||||
$instance = new self($db_data);
|
||||
$instance->setTUserId($id);
|
||||
return $instance;
|
||||
|
||||
}
|
||||
|
||||
//return constructed element based on TUserId
|
||||
public function load_With_TUserId( $id) {
|
||||
$dbl = new DBLayer($this->db);
|
||||
$statement = $dbl->execute("SELECT * FROM ticket_user WHERE TUserId=:id", array('id' => $id));
|
||||
$row = $statement->fetch();
|
||||
$instance->tUserId = $row['TUserId'];
|
||||
$instance->permission = $row['Permission'];
|
||||
$instance->externId = $row['ExternId'];
|
||||
return $instance;
|
||||
}
|
||||
|
||||
|
||||
//return constructed element based on ExternId
|
||||
public static function constr_ExternId( $id, $db_data ) {
|
||||
$instance = new self($db_data);
|
||||
$dbl = new DBLayer($this->db);
|
||||
$statement = $dbl->execute("SELECT * FROM ticket_user WHERE ExternId=:id", array('id' => $id));
|
||||
$row = $statement->fetch();
|
||||
$instance->tUserId = $row['TUserId'];
|
||||
$instance->permission = $row['Permission'];
|
||||
$instance->externId = $row['ExternId'];
|
||||
return $instance;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//update private data to DB.
|
||||
public function update(){
|
||||
$dbl = new DBLayer($this->db);
|
||||
$query = "UPDATE ticket_user SET Permission = :perm, ExternId = :ext_id WHERE TUserId=:id";
|
||||
$values = Array('id' => $this->tUserId, 'perm' => $this->permission, 'ext_id' => $this->externId);
|
||||
$statement = $dbl->execute($query, $values);
|
||||
}
|
||||
|
||||
//Getters
|
||||
public function getPermission(){
|
||||
if ($this->permission == ""){
|
||||
$this->load_With_TUserId($this->tUserId);
|
||||
}
|
||||
return $this->permission;
|
||||
}
|
||||
|
||||
|
||||
public function getExternId(){
|
||||
if ($this->ExternId == ""){
|
||||
$this->load_With_TUserId($this->tUserId);
|
||||
}
|
||||
return $this->externId;
|
||||
}
|
||||
|
||||
|
||||
public function getTUserId(){
|
||||
return $this->tUserId;
|
||||
}
|
||||
|
||||
|
||||
//setters
|
||||
public function setPermission($perm){
|
||||
$this->permission = $perm;
|
||||
}
|
||||
|
||||
|
||||
public function setExternId($id){
|
||||
$this->externId = $id;
|
||||
}
|
||||
|
||||
}
|
|
@ -58,17 +58,17 @@
|
|||
ENGINE = InnoDB;
|
||||
|
||||
INSERT IGNORE INTO `" . $cfg['db']['lib']['name'] ."`.`ticket_category` (`Name`) VALUES ('Hacking'),('Ingame-Bug'),('Website-Bug'),('Installation');
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `" . $cfg['db']['lib']['name'] ."`.`ticket_user`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket_user` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (
|
||||
`UId` INT(10) NOT NULL AUTO_INCREMENT ,
|
||||
`TUserId` INT(10) NOT NULL AUTO_INCREMENT ,
|
||||
`Permission` INT(3) NOT NULL DEFAULT 1 ,
|
||||
`Extern_Id` INT(10) NOT NULL ,
|
||||
PRIMARY KEY (`UId`) )
|
||||
`ExternId` INT(10) NOT NULL ,
|
||||
PRIMARY KEY (`TUserId`) )
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
|
@ -95,7 +95,7 @@
|
|||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_ticket_ams_user`
|
||||
FOREIGN KEY (`Author` )
|
||||
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`UId` )
|
||||
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`TUserId` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
@ -119,7 +119,7 @@
|
|||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_assigned_ams_user`
|
||||
FOREIGN KEY (`User` )
|
||||
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`UId` )
|
||||
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`TUserId` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
@ -196,7 +196,7 @@
|
|||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_ticket_reply_ams_user`
|
||||
FOREIGN KEY (`Author` )
|
||||
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`UId` )
|
||||
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`TUserId` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_ticket_reply_ticket_content`
|
||||
|
@ -244,6 +244,7 @@
|
|||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
|
||||
";
|
||||
$dbl->executeWithoutParams($sql);
|
||||
print "The Lib & Web database were correctly installed! <br />";
|
||||
|
|
|
@ -24,10 +24,10 @@ ENGINE = InnoDB;
|
|||
DROP TABLE IF EXISTS `mydb`.`ticket_user` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`ticket_user` (
|
||||
`UId` INT(10) NOT NULL AUTO_INCREMENT ,
|
||||
`TUserId` INT(10) NOT NULL AUTO_INCREMENT ,
|
||||
`Permission` INT(3) NOT NULL DEFAULT 1 ,
|
||||
`Extern_Id` INT(10) NOT NULL,
|
||||
PRIMARY KEY (`UId`) )
|
||||
`ExternId` INT(10) NOT NULL ,
|
||||
PRIMARY KEY (`TUserId`) )
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
|
@ -54,7 +54,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`ticket` (
|
|||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_ticket_ams_user`
|
||||
FOREIGN KEY (`Author` )
|
||||
REFERENCES `mydb`.`ticket_user` (`UId` )
|
||||
REFERENCES `mydb`.`ticket_user` (`TUserId` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
@ -78,7 +78,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`assigned` (
|
|||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_assigned_ams_user`
|
||||
FOREIGN KEY (`User` )
|
||||
REFERENCES `mydb`.`ticket_user` (`UId` )
|
||||
REFERENCES `mydb`.`ticket_user` (`TUserId` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
@ -155,7 +155,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`ticket_reply` (
|
|||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_ticket_reply_ams_user`
|
||||
FOREIGN KEY (`Author` )
|
||||
REFERENCES `mydb`.`ticket_user` (`UId` )
|
||||
REFERENCES `mydb`.`ticket_user` (`TUserId` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_ticket_reply_ticket_content`
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue