9 private static $options;
10 private static $optionName =
'sender.limitation.daily';
11 private static $defaultLimit = 0;
16 $counts = MessageTable::getAllDailyCount();
20 $sid = $sender->getId();
21 foreach ($sender->getFromList() as $from)
23 $key = $sid.
':'.$from[
'id'];
24 $limits[$key] = array(
26 'fromId' => $from[
'id'],
27 'limit' => static::getDailyLimit($sid, $from[
'id']),
28 'current' => isset($counts[$key]) ? $counts[$key] : 0
38 $key = $senderId .
':' . $fromId;
39 return static::getOption($key, static::$defaultLimit);
44 $key = $senderId .
':' . $fromId;
45 static::setOption($key, (
int)$limit);
46 MessageTable::returnDeferredToQueue($senderId, $fromId);
52 $limit = static::getDailyLimit($senderId, $fromId);
55 $current = MessageTable::getDailyCount($senderId, $fromId);
57 return ($current < $limit);
64 $time = static::getOption(
'retryTime', [
77 'h' => (int)$params[
'h'],
78 'i' => (
int)$params[
'i'],
79 'auto' => (bool)$params[
'auto'],
80 'tz' => (
string)$params[
'tz'],
83 static::setOption(
'retryTime', $result);
92 private static function setOptions(array $options)
94 static::$options = $options;
95 Option::set(
'messageservice', static::$optionName, serialize($options));
104 private static function getOptions()
106 if (static::$options ===
null)
108 $optionsString = Option::get(
'messageservice', static::$optionName);
109 if (\CheckSerializedData($optionsString))
111 static::$options = unserialize($optionsString, [
'allowed_classes' =>
false]);
114 if (!is_array(static::$options))
116 static::$options = array();
119 return static::$options;
130 private static function setOption($optionName, $optionValue)
132 $options = static::getOptions();
133 if (!isset($options[$optionName]) || $options[$optionName] !== $optionValue)
135 $options[$optionName] = $optionValue;
136 static::setOptions($options);
148 private static function getOption($optionName, $defaultValue =
null)
150 $options = static::getOptions();
151 return isset($options[$optionName]) ? $options[$optionName] : $defaultValue;
160 static::$options = array();
161 Option::delete(
'messageservice', array(
'name' => static::$optionName));