updated install, added create_Ticket function as wrapper!

This commit is contained in:
Quitta 2013-07-08 14:49:03 +02:00
parent 31571a2151
commit 07cda95e11
9 changed files with 192 additions and 107 deletions

View file

@ -10,6 +10,33 @@ class Ticket{
private $author;
private $db;
////////////////////////////////////////////Functions////////////////////////////////////////////////////
/*FUNCTION: create_Ticket()
* creates a ticket + first initial reply and fills in the content of it!
*
*/
public static function create_Ticket( $title, $content, $category, $author, $db_data) {
$ticket = new Ticket($db_data);
$ticket->set($title,0,0,$category,$author);
$ticket->create();
$ticket_id = $ticket->getTId();
$ticket_content = new Ticket_Content($db_data);
$ticket_content->setContent($content);
$ticket_content->create();
$content_id = $ticket_content->getTContentId();
$ticket_reply = new Ticket_Reply($db_data);
$ticket_reply->set($ticket_id, $content_id, $author);
$ticket_reply->create();
}
////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) {
$this->db = $db_data;
}
@ -55,13 +82,65 @@ class Ticket{
$statement = $dbl->execute($query, $values);
}
//Getters
////////////////////////////////////////////Getters////////////////////////////////////////////////////
public function getTId(){
return $this->tId;
}
//setters
public function getTimestamp(){
return $this->timestamp;
}
public function getTitle(){
return $this->title;
}
public function getStatus(){
return $this->status;
}
public function getQueue(){
return $this->queue;
}
public function getTicket_Category(){
return $this->ticket_category;
}
public function getAuthor(){
return $this->author;
}
////////////////////////////////////////////Setters////////////////////////////////////////////////////
public function setTId($id){
$this->tId = $id;
}
public function setTimestamp($ts){
$this->timestamp = $ts;
}
public function setTitle($t){
$this->title = $t;
}
public function setStatus($s){
$this->status = $s;
}
public function setQueue($q){
$this->queue = $q;
}
public function setTicket_Category($tc){
$this->ticket_category = $tc;
}
public function setAuthor($a){
$this->author = $a;
}
}

View file

@ -5,9 +5,7 @@ class Ticket_Category{
private $tCategoryId;
private $name;
public function __construct($db_data) {
$this->db = $db_data;
}
////////////////////////////////////////////Functions////////////////////////////////////////////////////
//Creates a ticket_Catergory in the DB
@ -43,6 +41,12 @@ class Ticket_Category{
}
////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) {
$this->db = $db_data;
}
//return constructed element based on TCategoryId
public function load_With_TCategoryId( $id) {
$dbl = new DBLayer($this->db);
@ -61,7 +65,8 @@ class Ticket_Category{
$statement = $dbl->execute($query, $values);
}
//Getters
////////////////////////////////////////////Getters////////////////////////////////////////////////////
public function getName(){
if ($this->name == ""){
$this->load_With_TCategoryId($this->tCategoryId);
@ -75,10 +80,15 @@ class Ticket_Category{
}
//setters
////////////////////////////////////////////Setters////////////////////////////////////////////////////
public function setName($n){
$this->name = $n;
}
public function setTCategoryId($id){
$this->tCategoryId = $id;
}
}

View file

@ -5,11 +5,23 @@ class Ticket_Content{
private $tContentId;
private $content;
////////////////////////////////////////////Functions////////////////////////////////////////////////////
//return constructed element based on TCategoryId
public static function constr_TContentId( $id, $db_data) {
$instance = new self($db_data);
$instance->setTContentId($id);
return $instance;
}
////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) {
$this->db = $db_data;
}
//Creates a ticket_content entry in the DB
public function create() {
$dbl = new DBLayer($this->db);
@ -18,13 +30,6 @@ class Ticket_Content{
$this->tContentId = $dbl->executeReturnId($query, $values); ;
}
//return constructed element based on TCategoryId
public static function constr_TContentId( $id, $db_data) {
$instance = new self($db_data);
$instance->setTContentId($id);
return $instance;
}
//return constructed element based on TContentId
public function load_With_TContentId( $id) {
$dbl = new DBLayer($this->db);
@ -42,7 +47,8 @@ class Ticket_Content{
$statement = $dbl->execute($query, $values);
}
//Getters
////////////////////////////////////////////Getters////////////////////////////////////////////////////
public function getContent(){
if ($this->content == ""){
$this->load_With_TContentId($this->tContentId);
@ -56,7 +62,8 @@ class Ticket_Content{
}
//setters
////////////////////////////////////////////Setters////////////////////////////////////////////////////
public function setContent($c){
$this->content = $c;
}

View file

@ -8,7 +8,16 @@ class Ticket_Reply{
private $timestamp;
private $db;
//////////////////////////////////Methods/////////////////////////////////
////////////////////////////////////////////Functions////////////////////////////////////////////////////
//return constructed element based on TCategoryId
public static function constr_TReplyId( $id, $db_data) {
$instance = new self($db_data);
$instance->setTReplyId($id);
return $instance;
}
////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) {
$this->db = $db_data;
@ -30,13 +39,6 @@ class Ticket_Reply{
$dbl->execute($query, $values);
}
//return constructed element based on TCategoryId
public static function constr_TReplyId( $id, $db_data) {
$instance = new self($db_data);
$instance->setTReplyId($id);
return $instance;
}
//return constructed element based on TId
public function load_With_TReplyId( $id) {
$dbl = new DBLayer($this->db);
@ -57,8 +59,8 @@ class Ticket_Reply{
$statement = $dbl->execute($query, $values);
}
////////////////////////////////////////////Getters////////////////////////////////////////////////////
//////////////////////////////////Getters/////////////////////////////////
public function getTicket(){
return $this->ticket;
}
@ -82,7 +84,8 @@ class Ticket_Reply{
}
///////////////////////////////////setters////////////////////////////////
////////////////////////////////////////////Setters////////////////////////////////////////////////////
public function setTicket($t){
$this->ticket = $t;
}

View file

@ -6,10 +6,7 @@ class Ticket_User{
private $externId;
private $db;
public function __construct($db_data) {
$this->db = $db_data;
}
////////////////////////////////////////////Functions////////////////////////////////////////////////////
//Creates a ticket_user in the DB
public static function createTicketUser( $extern_id, $permission,$db ) {
@ -29,18 +26,6 @@ class Ticket_User{
}
//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);
@ -55,6 +40,22 @@ class Ticket_User{
}
////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) {
$this->db = $db_data;
}
//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;
}
//update private data to DB.
public function update(){
$dbl = new DBLayer($this->db);
@ -63,7 +64,8 @@ class Ticket_User{
$statement = $dbl->execute($query, $values);
}
//Getters
////////////////////////////////////////////Getters////////////////////////////////////////////////////
public function getPermission(){
if ($this->permission == ""){
$this->load_With_TUserId($this->tUserId);
@ -85,7 +87,8 @@ class Ticket_User{
}
//setters
////////////////////////////////////////////Setters////////////////////////////////////////////////////
public function setPermission($perm){
$this->permission = $perm;
}

View file

@ -284,13 +284,13 @@ class Users{
* @takes $array with name,pass and mail
* @return ok if it's get correctly added to the shard, else return lib offline and put in libDB, if libDB is also offline return liboffline.
*/
public function createUser($values){
public function createUser($values, $user_id){
try {
//make connection with and put into shard db
global $cfg;
$dbs = new DBLayer($cfg['db']['shard']);
$dbs->execute("INSERT INTO user (Login, Password, Email) VALUES (:name, :pass, :mail)",$values);
ticket_user::createTicketUser( WebUsers::getId($values["name"]), 1, $cfg['db']['lib'] );
ticket_user::createTicketUser( $user_id , 1, $cfg['db']['lib'] );
return "ok";
}
catch (PDOException $e) {
@ -299,7 +299,7 @@ class Users{
$dbl = new DBLayer($cfg['db']['lib']);
$dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "createUser",
"query" => json_encode(array($values["name"],$values["pass"],$values["mail"]))));
ticket_user::createTicketUser( WebUsers::getId($values["name"]), 1, $cfg['db']['lib'] );
ticket_user::createTicketUser( $user_id , 1, $cfg['db']['lib'] );
return "shardoffline";
}catch (PDOException $e) {
print_r($e);

View file

@ -46,17 +46,16 @@ function write_user($newUser){
'mail' => $newUser["mail"]
);
//Create the user on the shard + in case shard is offline put copy of query in query db
//returns: ok, shardoffline or liboffline
$result = WebUsers::createUser($params);
try{
global $cfg;
//make connection with web db and put it in there
$dbw = new DBLayer($cfg['db']['web']);
$dbw->execute("INSERT INTO ams_user (Login, Password, Email) VALUES (:name, :pass, :mail)",$params);
//ticket_user::createTicketUser( WebUsers::getId($newUser["name"]), 1, $cfg['db']['lib'] );
$user_id = $dbw->executeReturnId("INSERT INTO ams_user (Login, Password, Email) VALUES (:name, :pass, :mail)",$params);
//Create the user on the shard + in case shard is offline put copy of query in query db
//returns: ok, shardoffline or liboffline
$result = WebUsers::createUser($params, $user_id);
}catch (PDOException $e) {
//go to error page or something, because can't access website db

View file

@ -1,7 +1,6 @@
<?php
function create_ticket(){
try{
//if logged in
if(WebUsers::isLoggedIn() && isset($_SESSION['ticket_user'])){
@ -14,27 +13,18 @@ function create_ticket(){
$category = filter_var($_POST['Category'], FILTER_SANITIZE_NUMBER_INT);
$title = filter_var($_POST['Title'], FILTER_SANITIZE_STRING);
$content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING);
try{
if($_POST['target_id'] == $_SESSION['id']){
$author = $_SESSION['ticket_user']->getTUserId();
}else{
$author= Ticket_User::constr_ExternId($_POST['target_id'], $cfg['db']['lib'])->getTUserId();
}
$ticket = new Ticket($cfg['db']['lib']);
$ticket->set($title,0,0,$category,$author);
$ticket->create();
$ticket_id = $ticket->getTId();
$ticket_content = new Ticket_Content($cfg['db']['lib']);
$ticket_content->setContent($content);
$ticket_content->create();
$content_id = $ticket_content->getTContentId();
$ticket_reply = new Ticket_Reply($cfg['db']['lib']);
$ticket_reply->set($ticket_id, $content_id, $author);
$ticket_reply->create();
Ticket::create_Ticket($title, $content, $category, $author, $cfg['db']['lib'] );
}catch (PDOException $e) {
//ERROR: LIB DB is not online!
header("Location: index.php");
exit;
}
}else{
//ERROR: permission denied!
@ -54,11 +44,5 @@ function create_ticket(){
exit;
}
}catch (PDOException $e) {
//go to error page or something, because can't access website db
print_r($e);
exit;
}
}

View file

@ -256,7 +256,7 @@
'pass' => $hashpass,
'mail' => "admin@admin.com",
);
Users::createUser($params);
Users::createUser($params, 1);
try{
$params['permission'] = 2;
$dbw = new DBLayer($cfg['db']['web']);