Skip to content

Instantly share code, notes, and snippets.

@musdevs
Created January 16, 2017 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musdevs/33a556119f58aa886970fdcf44ba80e2 to your computer and use it in GitHub Desktop.
Save musdevs/33a556119f58aa886970fdcf44ba80e2 to your computer and use it in GitHub Desktop.
Bitrix class for tuning web-messenger notify
class ImNotifySettings
{
protected $userId = null;
const CATEGORY = 'im';
const OPTION = 'notify';
public function __construct($userId)
{
$userId = intval($userId);
if ($userId < 0) {
throw new Exception("Invalid user ID");
}
$this->userId = $userId;
}
public function enableNotify($name)
{
$settings = $this->getValue();
$currentValue = $settings[$name];
if ($currentValue === true) {
// нужное значение уже установлено
return;
} else {
$settings[$name] = true;
CUserOptions::SetOption(
ImNotifySettings::CATEGORY,
ImNotifySettings::OPTION,
$settings,
false,
$this->userId
);
}
}
public function disableNotify($name)
{
$settings = $this->getValue();
$currentValue = $settings[$name];
if ($currentValue === false) {
// нужное значение уже установлено
return;
} else {
$settings[$name] = false;
CUserOptions::SetOption(
ImNotifySettings::CATEGORY,
ImNotifySettings::OPTION,
$settings,
false,
$this->userId
);
}
}
public function getValue()
{
$value = CUserOptions::GetOption(
ImNotifySettings::CATEGORY,
ImNotifySettings::OPTION,
false,
$this->userId
);
return $value;
}
public function isNotifyEnabled($name)
{
$settings = $this->getValue();
return $settings[$name] === true;
}
}
@musdevs
Copy link
Author

musdevs commented Jan 16, 2017

Вывести список пользователей с установленной опцией получения уведомлений о новом сообщении в Живой ленте Битрикс24, адресованном всем сотрудникам:

$notifyName = 'email|blog|broadcast_post';
$result = Bitrix\Main\UserTable::getList(array(
	'select' => array('ID', 'LAST_NAME', 'NAME'),
	'filter' => array('=ACTIVE' => 'Y')
));

echo '<pre>';
echo "Notify $notifyName is enabled for users:\n";
while ($row = $result->fetch()) {
	$s = new ImNotifySettings($row['ID']);
	if (!$s->isNotifyEnabled($notifyName)) {
		echo $row['ID'], ' ', $row['LAST_NAME'], ' ', $row['NAME'], "\n";
	}
}
echo '</pre>';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment