39 'ACTIVE' => self::ACTIVE,
40 'TYPE' => self::TYPE_CUSTOM,
52 private $isAgreementTextHtml;
62 $list = Internals\AgreementTable::getList(array(
63 'select' => array(
'ID',
'NAME'),
64 'filter' => array(
'=ACTIVE' =>
'Y'),
65 'order' => array(
'ID' =>
'DESC')
67 foreach ($list as $item)
69 $result[$item[
'ID']] = $item[
'NAME'];
83 self::TYPE_CUSTOM =>
Loc::getMessage(
'MAIN_USER_CONSENT_AGREEMENT_TYPE_N'),
84 self::TYPE_STANDARD =>
Loc::getMessage(
'MAIN_USER_CONSENT_AGREEMENT_TYPE_S'),
97 $this->intl =
new Intl();
115 $this->errors->setError(
new Error(
'Parameter `Agreement ID` required.'));
119 $data = Internals\AgreementTable::getRowById(
$id);
122 $this->errors->setError(
new Error(
"Agreement with id `$id` not found."));
128 $this->intl->load($this->data[
'LANGUAGE_ID']);
152 return $this->errors->toArray();
162 return !$this->errors->isEmpty();
207 $this->
setData($data + $this->data);
217 $this->errors->clear();
220 $fields =
$data[
'FIELDS'];
221 unset(
$data[
'FIELDS']);
230 (new \CBXSanitizer)->sanitizeHtml(
$data[
'AGREEMENT_TEXT']);
235 $result = Internals\AgreementTable::update($this->
id,
$data);
240 $result = Internals\AgreementTable::add(
$data);
241 $this->
id = $result->getId();
244 if(!$result->isSuccess())
249 Internals\FieldTable::setConsentFields($this->
id, $fields);
263 unset(
$data[
'FIELDS']);
266 Internals\AgreementTable::checkFields($result, $this->
id,
$data);
267 if (!$result->isSuccess())
269 $this->errors->add($result->getErrors());
272 return $result->isSuccess();
282 return $this->
id > 0;
292 return ($this->data[
'ACTIVE'] == self::ACTIVE);
297 return $this->isAgreementTextHtml;
307 return ($this->data[
'TYPE'] != self::TYPE_STANDARD);
325 mb_strpos($text,
"\n")?: 50,
326 mb_strpos($text,
"<br>")?: 50,
327 mb_strpos($text,
".")?: 50,
331 return mb_substr($text, 0, $pos);
342 $text = $this->getContent($cutTitle);
353 $text = $this->getContent();
356 $sanitizer = new \CBXSanitizer;
357 $sanitizer->setLevel(\CBXSanitizer::SECURE_LEVEL_MIDDLE);
358 $sanitizer->allowAttributes([
360 'tag' =>
function ($tag)
364 'content' =>
function ($tag)
371 return $sanitizer->sanitizeHtml($text);
374 private function getContent($cutTitle =
false)
378 return $this->data[
'AGREEMENT_TEXT'];
381 $text = $this->intl->getText();
383 $replaceData = array();
393 if (mb_strlen($title) !== 50 && $title === mb_substr($text, 0, mb_strlen($title)))
395 $text = trim(mb_substr($text, mb_strlen($title)));
409 return str_replace(
'%',
'', $this->getLabel());
419 return ($this->data[
'USE_URL'] ===
'Y' && $this->data[
'URL'])
420 ? (
new Uri($this->data[
'URL']))->getLocator()
429 public function getLabel()
431 $text = $this->
isCustomType() ? $this->data[
'LABEL_TEXT'] : $this->intl->getLabelText();
434 if ($this->data[
'USE_URL'] !==
'Y' || !$this->data[
'URL'])
436 return str_replace(
'%',
'', $text);
439 $text = trim(trim($text),
"%");
440 $text = explode(
'%', $text);
441 $text = array_filter($text);
444 switch (count($text))
448 $text = array_merge([
''], $text, [
'']);
460 array_slice($text, 0, 2),
461 [implode(
'', array_slice($text, 2))]
466 return implode(
'%', $text);
476 if (!$this->dataProvider)
478 $providerCode = $this->data[
'DATA_PROVIDER'] ??
null;
482 if ($this->dataProvider)
484 return $this->dataProvider->getData();
498 $fields = $this->intl->getFields();
500 foreach ($fields as $field)
502 $fieldCode = $field[
'CODE'];
503 $field[
'VALUE'] = $fieldValues[$fieldCode] ??
'';
504 $result[$fieldCode] = $field;
518 $fields = $this->intl->getFields();
520 foreach ($fields as $field)
522 $fieldCode = $field[
'CODE'];
523 $result[$fieldCode] = $fieldValues[$fieldCode] ??
'';
532 $fields = $this->intl->getFields();
535 foreach ($fields as $field)
537 if (!isset($field[
'DEFAULT_VALUE']) || !$field[
'DEFAULT_VALUE'])
542 if (isset($result[$field[
'CODE']]) && $result[$field[
'CODE']])
547 $result[$field[
'CODE']] = $field[
'DEFAULT_VALUE'];
551 foreach ($fields as $field)
553 if ($field[
'TYPE'] !=
'enum' || empty($field[
'TEXT']))
558 $fieldCode = $field[
'CODE'];
561 foreach ($field[
'ITEMS'] as $item)
564 if (isset($item[
'IS_TEXT']) && $item[
'IS_TEXT'])
569 if ($result[$fieldCode] == $item[
'CODE'])
571 $valueAsText = $item[
'NAME'];
static loadLanguageFile($file, $language=null, $normalize=true)
static getMessage($code, $replace=null, $language=null)
__construct($id, array $replace=array())
setReplace(array $replace)
static getTitleFromText($text)
static getByCode($providerCode)
static getConsentFields($agreementId)
static formatArrayToText(array $list)
static replace($template, array $data, $isCut=false)