Created
January 16, 2017 07:05
-
-
Save musdevs/33a556119f58aa886970fdcf44ba80e2 to your computer and use it in GitHub Desktop.
Bitrix class for tuning web-messenger notify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Вывести список пользователей с установленной опцией получения уведомлений о новом сообщении в Живой ленте Битрикс24, адресованном всем сотрудникам: