2013-07-06 04:09:47 +00:00
|
|
|
<?php
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* user entry point in the ticket system.
|
|
|
|
* The ticket_user makes a link between the entire ticket system's lib db and the www user, which is stored in another db (this is the external ID).
|
|
|
|
* The externalID could be the ID of a drupal user or wordpress user,.. The ticket_user also stores the permission of that user, this way the permission system
|
|
|
|
* is inside the lib itself and can be used in any www version that you like. permission 1 = user, 2 = mod, 3 = admin.
|
|
|
|
* @author Daan Janssens, mentored by Matthew Lagoe
|
|
|
|
*/
|
2013-07-06 04:09:47 +00:00
|
|
|
class Ticket_User{
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
private $tUserId; /**< The id of the user inside the ticket system*/
|
|
|
|
private $permission; /**< The permission of the user */
|
|
|
|
private $externId; /**< The id of the user account in the www (could be drupal,...) that is linked to the ticket_user */
|
|
|
|
|
2013-07-08 12:49:03 +00:00
|
|
|
////////////////////////////////////////////Functions////////////////////////////////////////////////////
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* create a new ticket user.
|
|
|
|
* @param $extern_id the id of the user account in the www version (drupal,...)
|
|
|
|
* @param $permission the permission that will be given to the user. 1=user, 2=mod, 3=admin
|
|
|
|
*/
|
2013-07-10 10:36:14 +00:00
|
|
|
public static function createTicketUser( $extern_id, $permission) {
|
|
|
|
$dbl = new DBLayer("lib");
|
2014-09-03 04:38:38 +00:00
|
|
|
$dbl->insert("ticket_user",array('TUserId' => $extern_id, 'Permission' => $permission, 'ExternId' => $extern_id));
|
2013-07-06 04:09:47 +00:00
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* check if a ticket_user object is a mod or not.
|
|
|
|
* @param $user the ticket_user object itself
|
|
|
|
* @return true or false
|
|
|
|
*/
|
2013-07-18 10:43:33 +00:00
|
|
|
public static function isMod($user){
|
|
|
|
if(isset($user) && $user->getPermission() > 1){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* check if a ticket_user object is an admin or not.
|
|
|
|
* @param $user the ticket_user object itself
|
|
|
|
* @return true or false
|
|
|
|
*/
|
2013-07-18 10:43:33 +00:00
|
|
|
public static function isAdmin($user){
|
|
|
|
if(isset($user) && $user->getPermission() == 3){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* return constructed ticket_user object based on TUserId.
|
|
|
|
* @param $id the TUserId of the entry.
|
|
|
|
* @return constructed ticket_user object
|
|
|
|
*/
|
2013-07-10 10:36:14 +00:00
|
|
|
public static function constr_TUserId( $id) {
|
|
|
|
$instance = new self();
|
2013-07-06 04:09:47 +00:00
|
|
|
$instance->setTUserId($id);
|
|
|
|
return $instance;
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-07-06 04:09:47 +00:00
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* return a list of all mods/admins.
|
|
|
|
* @return an array consisting of ticket_user objects that are mods & admins.
|
|
|
|
*/
|
2013-07-23 21:38:06 +00:00
|
|
|
public static function getModsAndAdmins() {
|
|
|
|
$dbl = new DBLayer("lib");
|
2014-05-27 22:18:44 +00:00
|
|
|
$statement = $dbl->select("ticket_user", array(null), "`Permission` > 1" );
|
2013-07-23 21:38:06 +00:00
|
|
|
$rows = $statement->fetchAll();
|
|
|
|
$result = Array();
|
|
|
|
foreach($rows as $user){
|
|
|
|
$instanceUser = new self();
|
|
|
|
$instanceUser->set($user);
|
|
|
|
$result[] = $instanceUser;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
return $result;
|
2013-07-23 21:38:06 +00:00
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* return constructed ticket_user object based on ExternId.
|
|
|
|
* @param $id the ExternId of the entry.
|
|
|
|
* @return constructed ticket_user object
|
|
|
|
*/
|
2013-07-10 10:36:14 +00:00
|
|
|
public static function constr_ExternId( $id) {
|
|
|
|
$instance = new self();
|
|
|
|
$dbl = new DBLayer("lib");
|
2014-05-27 22:18:44 +00:00
|
|
|
$statement = $dbl->select("ticket_user" ,array('id'=>$id) ,"ExternId=:id");
|
2013-07-06 04:09:47 +00:00
|
|
|
$row = $statement->fetch();
|
|
|
|
$instance->tUserId = $row['TUserId'];
|
|
|
|
$instance->permission = $row['Permission'];
|
|
|
|
$instance->externId = $row['ExternId'];
|
|
|
|
return $instance;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* change the permission of a ticket_user.
|
|
|
|
* @param $user_id the TUserId of the entry.
|
|
|
|
* @param $perm the new permission value.
|
|
|
|
*/
|
2013-07-19 01:05:12 +00:00
|
|
|
public static function change_permission($user_id, $perm){
|
|
|
|
$user = new Ticket_User();
|
|
|
|
$user->load_With_TUserId($user_id);
|
|
|
|
$user->setPermission($perm);
|
|
|
|
$user->update();
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* return the email address of a ticket_user.
|
|
|
|
* @param $id the TUserId of the entry.
|
|
|
|
* @return string containing the email address of that user.
|
|
|
|
*/
|
2013-08-13 15:16:43 +00:00
|
|
|
public static function get_email_by_user_id($id){
|
|
|
|
$user = new Ticket_User();
|
|
|
|
$user->load_With_TUserId($id);
|
|
|
|
$webUser = new WebUsers($user->getExternId());
|
2014-09-03 04:38:38 +00:00
|
|
|
return $webUser->getEmail();
|
2013-08-13 15:16:43 +00:00
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* return the username of a ticket_user.
|
|
|
|
* @param $id the TUserId of the entry.
|
|
|
|
* @return string containing username of that user.
|
|
|
|
*/
|
2013-08-13 15:16:43 +00:00
|
|
|
public static function get_username_from_id($id){
|
|
|
|
$user = new Ticket_User();
|
|
|
|
$user->load_With_TUserId($id);
|
|
|
|
$webUser = new WebUsers($user->getExternId());
|
2014-09-03 04:38:38 +00:00
|
|
|
return $webUser->getUsername();
|
2013-08-13 15:16:43 +00:00
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* return the TUserId of a ticket_user by giving a username.
|
|
|
|
* @param $username the username of a user.
|
|
|
|
* @return the TUserId related to that username.
|
|
|
|
*/
|
2013-08-13 15:16:43 +00:00
|
|
|
public static function get_id_from_username($username){
|
|
|
|
$externId = WebUsers::getId($username);
|
|
|
|
$user = Ticket_User::constr_ExternId($externId);
|
2014-09-03 04:38:38 +00:00
|
|
|
return $user->getTUserId();
|
2013-08-13 15:16:43 +00:00
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* return the ticket_user id from an email address.
|
|
|
|
* @param $email the emailaddress of a user.
|
|
|
|
* @return the ticket_user id related to that email address, in case none, return "FALSE".
|
|
|
|
*/
|
2013-08-13 15:16:43 +00:00
|
|
|
public static function get_id_from_email($email){
|
|
|
|
$webUserId = WebUsers::getIdFromEmail($email);
|
2013-08-17 01:06:22 +00:00
|
|
|
if($webUserId != "FALSE"){
|
|
|
|
$user = Ticket_User::constr_ExternId($webUserId);
|
|
|
|
return $user->getTUserId();
|
|
|
|
}else{
|
|
|
|
return "FALSE";
|
|
|
|
}
|
2013-08-13 15:16:43 +00:00
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-07-08 12:49:03 +00:00
|
|
|
////////////////////////////////////////////Methods////////////////////////////////////////////////////
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* A constructor.
|
|
|
|
* Empty constructor
|
|
|
|
*/
|
2013-07-10 10:36:14 +00:00
|
|
|
public function __construct() {
|
2013-07-08 12:49:03 +00:00
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* sets the object's attributes.
|
|
|
|
* @param $values should be an array of the form array('TUserId' => id, 'Permission' => perm, 'ExternId' => ext_id).
|
|
|
|
*/
|
2013-07-23 21:38:06 +00:00
|
|
|
public function set($values) {
|
|
|
|
$this->setTUserId($values['TUserId']);
|
|
|
|
$this->setPermission($values['Permission']);
|
|
|
|
$this->setExternId($values['ExternId']);
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* loads the object's attributes.
|
|
|
|
* loads the object's attributes by giving a TUserId.
|
|
|
|
* @param $id the id of the ticket_user that should be loaded
|
|
|
|
*/
|
2013-07-08 12:49:03 +00:00
|
|
|
public function load_With_TUserId( $id) {
|
2013-07-10 10:36:14 +00:00
|
|
|
$dbl = new DBLayer("lib");
|
2014-05-27 22:18:44 +00:00
|
|
|
$statement = $dbl->select("ticket_user" ,array('id'=>$id), "TUserId=:id" );
|
2013-07-08 12:49:03 +00:00
|
|
|
$row = $statement->fetch();
|
2013-07-13 21:18:49 +00:00
|
|
|
$this->tUserId = $row['TUserId'];
|
|
|
|
$this->permission = $row['Permission'];
|
|
|
|
$this->externId = $row['ExternId'];
|
2014-09-03 04:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* update the object's attributes to the db.
|
|
|
|
*/
|
2013-07-06 04:09:47 +00:00
|
|
|
public function update(){
|
2013-07-10 10:36:14 +00:00
|
|
|
$dbl = new DBLayer("lib");
|
2014-05-27 22:18:44 +00:00
|
|
|
$dbl->update("ticket_user" ,array('Permission' => $this->permission, 'ExternId' => $this->externId) ,"TUserId=$this->tUserId");
|
2013-07-06 04:09:47 +00:00
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-07-08 12:49:03 +00:00
|
|
|
////////////////////////////////////////////Getters////////////////////////////////////////////////////
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* get permission attribute of the object.
|
|
|
|
*/
|
2013-07-06 04:09:47 +00:00
|
|
|
public function getPermission(){
|
|
|
|
return $this->permission;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* get externId attribute of the object.
|
|
|
|
*/
|
2013-07-06 04:09:47 +00:00
|
|
|
public function getExternId(){
|
|
|
|
return $this->externId;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* get tUserId attribute of the object.
|
|
|
|
*/
|
2013-07-06 04:09:47 +00:00
|
|
|
public function getTUserId(){
|
|
|
|
return $this->tUserId;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-07-08 12:49:03 +00:00
|
|
|
////////////////////////////////////////////Setters////////////////////////////////////////////////////
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* set permission attribute of the object.
|
|
|
|
* @param $perm integer that indicates the permission level. (1= user, 2= mod, 3= admin)
|
|
|
|
*/
|
2013-07-06 04:09:47 +00:00
|
|
|
public function setPermission($perm){
|
|
|
|
$this->permission = $perm;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* set externId attribute of the object.
|
|
|
|
* @param $id the external id.
|
2014-09-03 04:38:38 +00:00
|
|
|
*/
|
2013-07-06 04:09:47 +00:00
|
|
|
public function setExternId($id){
|
|
|
|
$this->externId = $id;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
2013-09-12 17:28:56 +00:00
|
|
|
/**
|
|
|
|
* set tUserId attribute of the object.
|
|
|
|
* @param $id the ticket_user id
|
|
|
|
*/
|
2013-07-10 20:40:01 +00:00
|
|
|
public function setTUserId($id){
|
|
|
|
$this->tUserId= $id;
|
|
|
|
}
|
2014-09-03 04:38:38 +00:00
|
|
|
|
|
|
|
|
2014-05-27 22:18:44 +00:00
|
|
|
}
|