PageRenderTime 24ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/sender/lib/integration/voximplant/messagecall.php

https://gitlab.com/alexprowars/bitrix
PHP | 243 lines | 161 code | 22 blank | 60 comment | 4 complexity | 52a57f89710f5c723505967f33a0452a MD5 | raw file
  1. <?php
  2. /**
  3. * Bitrix Framework
  4. * @package bitrix
  5. * @subpackage sender
  6. * @copyright 2001-2012 Bitrix
  7. */
  8. namespace Bitrix\Sender\Integration\VoxImplant;
  9. use Bitrix\Main\Localization\Loc;
  10. use Bitrix\Main\Result;
  11. use Bitrix\Sender\Message;
  12. use Bitrix\Sender\Entity;
  13. use Bitrix\Sender\Transport\TimeLimiter;
  14. use Bitrix\Voximplant\Tts;
  15. use Bitrix\Main\Config\Option;
  16. Loc::loadMessages(__FILE__);
  17. /**
  18. * Class MessageCall
  19. * @package Bitrix\Sender\Integration\VoxImplant
  20. */
  21. class MessageCall implements Message\iBase, Message\iMailable
  22. {
  23. const CODE = self::CODE_CALL;
  24. /** @var Message\Configuration $configuration Configuration. */
  25. protected $configuration;
  26. /**
  27. * MessageSms constructor.
  28. */
  29. public function __construct()
  30. {
  31. $this->configuration = new Message\Configuration();
  32. }
  33. /**
  34. * Get name.
  35. * @return string
  36. */
  37. public function getName()
  38. {
  39. return Loc::getMessage('SENDER_INTEGRATION_CALL_MESSAGE_NAME');
  40. }
  41. /**
  42. * Get code.
  43. *
  44. * @return string
  45. */
  46. public function getCode()
  47. {
  48. return static::CODE;
  49. }
  50. /**
  51. * Get supported transports.
  52. *
  53. * @return array
  54. */
  55. public function getSupportedTransports()
  56. {
  57. return array(TransportCall::CODE);
  58. }
  59. /**
  60. * Set configuration options
  61. * @return void
  62. */
  63. protected function setConfigurationOptions()
  64. {
  65. if ($this->configuration->hasOptions())
  66. {
  67. return;
  68. }
  69. $this->configuration->setArrayOptions(array(
  70. array(
  71. 'type' => 'list',
  72. 'code' => 'OUTPUT_NUMBER',
  73. 'name' => Loc::getMessage('SENDER_INTEGRATION_CALL_MESSAGE_CONFIG_OUTPUT_NUMBER'),
  74. 'items' => \CVoxImplantConfig::GetPortalNumbers(false),
  75. 'view' => function ()
  76. {
  77. /** @var \CAllMain {$GLOBALS['APPLICATION']} */
  78. ob_start();
  79. $GLOBALS['APPLICATION']->includeComponent(
  80. "bitrix:sender.call.number", "",
  81. array(
  82. "INPUT_NAME" => "%INPUT_NAME%",
  83. "VALUE" => "%INPUT_VALUE%",
  84. "MESSAGE_TYPE" => $this->getCode()
  85. )
  86. );
  87. return ob_get_clean();
  88. },
  89. 'required' => true,
  90. 'show_in_list' => true,
  91. 'readonly_view' => function($value)
  92. {
  93. return Service::getFormattedOutputNumber($value);
  94. },
  95. ),
  96. array(
  97. 'type' => 'text',
  98. 'code' => 'MESSAGE_TEXT',
  99. 'name' => Loc::getMessage('SENDER_INTEGRATION_CALL_MESSAGE_CONFIG_MESSAGE_TEXT'),
  100. 'required' => true,
  101. ),
  102. array(
  103. 'type' => 'list',
  104. 'code' => 'VOICE_LANGUAGE',
  105. 'name' => Loc::getMessage('SENDER_INTEGRATION_CALL_MESSAGE_CONFIG_VOICE_LANGUAGE'),
  106. 'items' => Tts\Language::getList(),
  107. 'required' => true,
  108. 'group' => Message\ConfigurationOption::GROUP_ADDITIONAL,
  109. ),
  110. array(
  111. 'type' => 'list',
  112. 'code' => 'VOICE_SPEED',
  113. 'name' => Loc::getMessage('SENDER_INTEGRATION_CALL_MESSAGE_CONFIG_VOICE_SPEED'),
  114. 'items' => Tts\Speed::getList(),
  115. 'required' => true,
  116. 'group' => Message\ConfigurationOption::GROUP_ADDITIONAL,
  117. ),
  118. array(
  119. 'type' => 'list',
  120. 'code' => 'VOICE_VOLUME',
  121. 'name' => Loc::getMessage('SENDER_INTEGRATION_CALL_MESSAGE_CONFIG_VOICE_VOLUME'),
  122. 'items' => Tts\Volume::getList(),
  123. 'required' => true,
  124. 'group' => Message\ConfigurationOption::GROUP_ADDITIONAL,
  125. ),
  126. ));
  127. TimeLimiter::prepareMessageConfiguration($this->configuration);
  128. }
  129. /**
  130. * Load configuration.
  131. *
  132. * @param integer|null $id ID.
  133. *
  134. * @return Message\Configuration
  135. */
  136. public function loadConfiguration($id = null)
  137. {
  138. $this->setConfigurationOptions();
  139. Entity\Message::create()
  140. ->setCode($this->getCode())
  141. ->loadConfiguration($id, $this->configuration);
  142. $defaultValues = array(
  143. 'VOICE_VOLUME' => Tts\Volume::getDefault(),
  144. 'VOICE_SPEED' => Tts\Speed::getDefault(),
  145. 'VOICE_LANGUAGE' => Tts\Language::getDefaultVoice(LANGUAGE_ID),
  146. );
  147. foreach ($defaultValues as $key => $value)
  148. {
  149. $option = $this->configuration->getOption($key);
  150. if (!$option || $option->hasValue())
  151. {
  152. continue;
  153. }
  154. $option->setValue($value);
  155. }
  156. $textOption = $this->configuration->getOption('MESSAGE_TEXT');
  157. if ($textOption)
  158. {
  159. $speedOption = $this->configuration->getOption('VOICE_SPEED');
  160. $textOption->setView(
  161. function () use ($speedOption)
  162. {
  163. /** @var \CAllMain {$GLOBALS['APPLICATION']} */
  164. ob_start();
  165. $GLOBALS['APPLICATION']->includeComponent(
  166. "bitrix:sender.call.text.editor",
  167. ".default",
  168. array(
  169. "INPUT_NAME" => "%INPUT_NAME%",
  170. "VALUE" => "%INPUT_VALUE%",
  171. "SPEED_INPUT_NAME" => $speedOption
  172. ?
  173. "%INPUT_NAME_" . $speedOption->getCode() . "%"
  174. :
  175. ''
  176. )
  177. );
  178. return ob_get_clean();
  179. }
  180. );
  181. }
  182. TimeLimiter::prepareMessageConfigurationView($this->configuration);
  183. return $this->configuration;
  184. }
  185. /**
  186. * Save configuration.
  187. *
  188. * @param Message\Configuration $configuration Configuration.
  189. *
  190. * @return Result
  191. */
  192. public function saveConfiguration(Message\Configuration $configuration)
  193. {
  194. return Entity\Message::create()
  195. ->setCode($this->getCode())
  196. ->saveConfiguration($this->configuration);
  197. }
  198. /**
  199. * Remove configuration.
  200. *
  201. * @param integer $id ID.
  202. * @return bool
  203. */
  204. public function removeConfiguration($id)
  205. {
  206. $result = Entity\Message::removeById($id);
  207. return $result->isSuccess();
  208. }
  209. /**
  210. * Copy configuration.
  211. *
  212. * @param integer|string|null $id ID.
  213. * @return Result|null
  214. */
  215. public function copyConfiguration($id)
  216. {
  217. return Entity\Message::create()
  218. ->setCode($this->getCode())
  219. ->copyConfiguration($id);
  220. }
  221. }