";
foreach($anArray as $row){
if( !is_array($anArray) )
continue;
$ret .= "
";
foreach( $row as $entry )
$ret .= "| ".$entry." | ";
$ret .= "
";
}
$ret .= "";
return $ret;
}
/// einem User ein Attribut zuordnen
///
/// @param $aDbConnection PDO-Datenbankverbindung, die benutzt werden soll
/// @param $anUserId ID des Users, der das Attribut erhalten soll
/// @param $anAttributeId ID des zu vergebenden Attributes
///
/// - Es erfolgt keine Kontrolle, ob:
/// - die AttributId überhaupt existiert,
/// - ob die UserId überhaupt existiert,
/// - ob der User das Attribut bereits hat,
function giveUserAnUserAttribute($aDbConnection, $anUserId, $anAttributeId){
withdrawUsersAttribute($aDbConnection, $anUserId, $anAttributeId);
try{
dbQuery(
$aDbConnection,
"INSERT INTO `wkParticipo_user<=>userAttributes` (userId, attributeId) VALUES (:userId, :attributeId);",
array(
':userId' => array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT),
':attributeId'=> array('value'=>$anAttributeId, 'data_type'=>PDO::PARAM_INT)
)
);
}
catch(PDOException $db_error){
print "Error!: " . $db_error->getMessage() . "
queryString: ".$queryString."
"; var_dump($bindArray);
}
return;
}
/// einem User ein Attribut entziehen
function withdrawUsersAttribute($aDbConnection, $anUserId, $anAttributeId, $limit = NULL){
try{
// Variablen für das Binden an die Query vorbereiten
// inklusive Validierung der Werte
$bindArray = array();
if( is_positive_integer( $anUserId ) ){
$bindArray[':userId'] = array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT);
}
else{
throw new InvalidArgumentException("withdrawUsersAttribute: userId must be positive integer!");
}
if( is_positive_integer($anAttributeId) ){
$bindArray[':attributeId'] = array('value'=>$anAttributeId, 'data_type'=>PDO::PARAM_INT);
}
else{
throw new InvalidArgumentException("withdrawUsersAttribute: attributeid must be positive integer");
}
if( is_positive_integer( $limit ) ){
$bindArray[':limit'] = array('value' => $limit, 'data_type' => PDO::PARAM_INT);
}
// Zusammenstellen der Query
$queryString =
"DELETE FROM `wkParticipo_user<=>userAttributes` ".
"WHERE `userId`=:userId ".
"AND `attributeId`=:attributeId".
(is_positive_integer( $limit )?" LIMIT :limit":"").
";";
echo("queryString: ".$queryString."
"); var_dump($bindArray);
dbQuery(
$aDbConnection,
$queryString,
$bindArray
);
}
catch(PDOException $db_error){
print "Error!: " . $db_error->getMessage() . "
queryString: ".$queryString."
"; var_dump($bindArray);
}
return;
}// Ende withdrawUsersAttribute
#exit();
var_dump($_GET);
$actions = ["giveUserAnUserAttribute", "withdrawUsersAttribute"];
$dbConn = getCwsvJudoDbConn();
$dbConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
if(isset($_GET['action'])){
switch($_GET['action']){
case "giveUserAnUserAttribute":
try{
giveUserAnUserAttribute($dbConn, intval($_GET['userId']), intval($_GET['attributeId']));
}
catch(Exception $e){
print("UPS: ".$e->getMessage());
}
break;
case "withdrawUsersAttribute":
try{
withdrawUsersAttribute($dbConn, intval($_GET['userId']), intval($_GET['attributeId']));
}
catch(Exception $e){
print("UPS: ".$e->getMessage());
}
break;
default:
echo("Ungültige Aktion (".$_GET['action'].") erwünscht!");
break;
}
}
$users =
dbQuery(
$dbConn,
"SELECT * FROM cwsvjudo.wkParticipo_Users;"
);
$userAttributes =
dbQuery(
$dbConn,
"SELECT * FROM cwsvjudo.wkParticipo_userAttributes;"
);
?>
Attribute
userAttributes` WHERE wkParticipo_Users.id = `wkParticipo_user<=>userAttributes`.userId AND `wkParticipo_user<=>userAttributes`.attributeId=:attributeId;",
array(":attributeId"=>array('value'=>$userAttribute['id'], 'data_type'=>PDO::PARAM_INT))
);
echo( "".$userAttribute['name']."
".array2htmlTableString($attributedUsers) );
}
?>
User