2013-07-16 02:58:54 +00:00
< ? php
2013-09-10 23:38:53 +00:00
/**
* Handles the linkage of users being in a support group .
* Moderators and Admins can be part of a support group , this class offers functionality to check if a link between a user and group is existing .
* @ author Daan Janssens , mentored by Matthew Lagoe
*
*/
2013-07-16 02:58:54 +00:00
class In_Support_Group {
2013-09-10 23:38:53 +00:00
private $user ; /**< The id of the user being in a support group */
private $group ; /**< The id of the support group*/
2013-07-16 02:58:54 +00:00
////////////////////////////////////////////Functions////////////////////////////////////////////////////
2013-09-10 23:38:53 +00:00
/**
* Check if user is in in_support_group .
* @ param $user_id the id of the user .
* @ param $group_id the id of the support group .
* @ return true is returned in case the user is in the support group , else false is returned .
*/
2013-07-16 14:43:58 +00:00
public static function userExistsInSGroup ( $user_id , $group_id ) {
2013-07-16 02:58:54 +00:00
$dbl = new DBLayer ( " lib " );
//check if name is already used
if ( $dbl -> execute ( " SELECT * FROM `in_support_group` WHERE `User` = :user_id and `Group` = :group_id " , array ( 'user_id' => $user_id , 'group_id' => $group_id ) ) -> rowCount () ){
return true ;
} else {
return false ;
}
}
////////////////////////////////////////////Methods////////////////////////////////////////////////////
2013-09-10 23:38:53 +00:00
/**
* A constructor .
* Empty constructor
*/
2013-07-16 02:58:54 +00:00
public function __construct () {
}
2013-09-10 23:38:53 +00:00
/**
* sets the object ' s attributes .
* @ param $values should be an array of the form array ( 'User' => user_id , 'Group' => support_groups_id ) .
*/
2013-07-16 02:58:54 +00:00
public function set ( $values ) {
$this -> setUser ( $values [ 'User' ]);
$this -> setGroup ( $values [ 'Group' ]);
}
2013-09-10 23:38:53 +00:00
/**
* creates a new 'in_support_group' entry .
* this method will use the object 's attributes for creating a new ' in_support_group ' entry in the database .
*/
2013-07-16 02:58:54 +00:00
public function create () {
$dbl = new DBLayer ( " lib " );
$query = " INSERT INTO `in_support_group` (`User`,`Group`) VALUES (:user, :group) " ;
$values = Array ( 'user' => $this -> user , 'group' => $this -> group );
$dbl -> execute ( $query , $values );
2013-07-16 14:43:58 +00:00
}
2013-09-10 23:38:53 +00:00
/**
* deletes an existing 'in_support_group' entry .
* this method will use the object 's attributes for deleting an existing ' in_support_group ' entry in the database .
*/
2013-07-16 14:43:58 +00:00
public function delete () {
$dbl = new DBLayer ( " lib " );
$query = " DELETE FROM `in_support_group` WHERE `User` = :user_id and `Group` = :group_id " ;
$values = array ( 'user_id' => $this -> getUser () , 'group_id' => $this -> getGroup ());
$dbl -> execute ( $query , $values );
}
2013-07-16 02:58:54 +00:00
2013-09-10 23:38:53 +00:00
/*
public function load ( $group_id ) {
2013-07-16 02:58:54 +00:00
$dbl = new DBLayer ( " lib " );
$statement = $dbl -> execute ( " SELECT * FROM `in_support_group` WHERE `Group` = :group_id " , Array ( 'group_id' => $group_id ));
$row = $statement -> fetch ();
$this -> set ( $row );
}
2013-09-10 23:38:53 +00:00
*/
2013-07-16 02:58:54 +00:00
////////////////////////////////////////////Getters////////////////////////////////////////////////////
2013-09-10 23:38:53 +00:00
/**
* get user attribute of the object .
*/
2013-07-16 02:58:54 +00:00
public function getUser (){
return $this -> user ;
}
2013-09-10 23:38:53 +00:00
/**
* get group attribute of the object .
*/
2013-07-16 02:58:54 +00:00
public function getGroup (){
return $this -> group ;
}
////////////////////////////////////////////Setters////////////////////////////////////////////////////
2013-09-10 23:38:53 +00:00
/**
* set user attribute of the object .
* @ param $u integer id of the user
*/
2013-07-16 02:58:54 +00:00
public function setUser ( $u ){
$this -> user = $u ;
}
2013-09-10 23:38:53 +00:00
/**
* set group attribute of the object .
* @ param $g integer id of the support group
*/
2013-07-16 02:58:54 +00:00
public function setGroup ( $g ){
$this -> group = $g ;
}
}