Location: PHPKode > scripts > Bit Options > bit-options/unit_test.php
<?
require_once 'BitOptions.php';

define('USER_ACCESS_CHAT', 1);
define('USER_ACCESS_POLLS', 2);
define('USER_ACCESS_MODERATE_CHAT', 3);
define('USER_ACCESS_MANAGE_POLLS', 4);

//Giving some access to the user:
$user_options = new BitOptions(false);

$user_options[USER_ACCESS_CHAT] = true;
$user_options[USER_ACCESS_POLLS] = true;

echo "User1 has these options set: ";
print_r(BitOptions::GetOptions($user_options));

if ($user_options[USER_ACCESS_CHAT]) echo "<br />User1 can post a message in the chat.";
else echo "<br /> User1 can't post a message in the chat";

echo "<br /><br />Creating User2's options as copy of User1's but stored as string instead of int";
//I know that trere are other ways to do it. I'm just showing that these 2 functions work as expected.
$user2_options = BitOptions::CalculateOptions(BitOptions::GetOptions($user_options), true);

echo "<br />User2 has these options set: ";
print_r(BitOptions::GetOptions($user2_options));

echo "<br /><br />Disallowing User1 to chat";
$user_options[USER_ACCESS_CHAT] = false;

if ($user_options[USER_ACCESS_CHAT]) echo "<br />User1 can post a message in the chat.";
else echo "<br /> User1 can't post a message in the chat";

if ($user2_options[USER_ACCESS_CHAT]) echo "<br />User2 can post a message in the chat.";
else echo "<br /> User2 can't post a message in the chat";

echo "<br /><br />Allowing User2 to manage polls";
$user2_options[USER_ACCESS_POLLS] = true;

if ($user2_options[USER_ACCESS_POLLS]) echo "<br />User2 can manage polls";
else echo "<br /> User2 can't manage polls";

//Showing that __toString() works
echo "<br /><br />User1 options are stored as: $user_options";
echo "<br />User2 options are stored as: $user2_options";

//we can use tha class in a foreach loop
echo "<br /><br />Looping through the options of User2 which are enabled(true)";
foreach ($user2_options AS $v) echo "<br />$v";
?>
Return current item: Bit Options