255], [['before_link_text'], 'string', 'max' => 1000], [['content_html'], 'string', 'max' => 10000], [['file'], 'required', 'when' => function ($model) { return $model->isFileContent() && $model->isNewRecord; }, 'whenClient' => "function() { if(!$('#regulation-id').val()) { var select = $(\"#content_type_field\")[0] var selected = select.options[select.selectedIndex].value; return +selected === " . self::CONTENT_TYPE_FILE . ". } return false; }"], [['content_link'], 'required', 'when' => function ($model) { return $model->isLinkContent(); }, 'whenClient' => "function() { var select = $(\"#content_type_field\")[0] var selected = select.options[select.selectedIndex].value; return +selected === " . self::CONTENT_TYPE_LINK . ". }"], [['content_html'], 'required', 'when' => function ($model) { return $model->isHTMLContent(); }, 'whenClient' => "function() { var select = $(\"#content_type_field\")[0] var selected = select.options[select.selectedIndex].value; return +selected === " . self::CONTENT_TYPE_HTML . ". }"], [['file'], 'file', 'extensions' => 'png, jpg, doc, docx, pdf, bmp, jpeg', 'skipOnEmpty' => !$this->isFileContent() || !$this->isNewRecord, 'maxSize' => iniGet::getUploadMaxFilesize(false)], [['attachment_type'], 'exist', 'skipOnError' => true, 'targetClass' => AttachmentType::class, 'targetAttribute' => ['attachment_type' => 'id']], ]; } public function attributeLabels() { return [ 'id' => 'ID', 'related_entity' => 'Связанная сущность', 'confirm_required' => 'Требовать подтверждение ознакомления', 'before_link_text' => 'Текст перед ссылкой', 'name' => 'Имя ссылки', 'content_type' => 'Тип содержимого ссылки', 'content_link' => 'Адрес ссылки', 'content_html' => 'HTML-текст', 'content_file' => 'Файл', 'file' => 'Файл', 'attachment_type' => 'Требуемый тип скан-копии', ]; } public function getAttachmentType() { return $this->hasOne(AttachmentType::class, ['id' => 'attachment_type']); } public static function getContentTypes() { return [ self::CONTENT_TYPE_HTML => 'HTML текст', self::CONTENT_TYPE_FILE => 'Файл', self::CONTENT_TYPE_LINK => 'Ссылка' ]; } public function getContent_file_extension(): ?string { return ArrayHelper::getValue($this, 'extension'); } public function getContent_file(): ?string { return ArrayHelper::getValue($this, 'filename'); } public function isFileContent() { return (int)$this->content_type === self::CONTENT_TYPE_FILE; } public function isLinkContent() { return (int)$this->content_type === self::CONTENT_TYPE_LINK; } public function isHTMLContent() { return (int)$this->content_type === self::CONTENT_TYPE_HTML; } public function getConfirmRequiredText() { return $this->confirm_required ? 'Да' : 'Нет'; } public function getContentTypeText() { return self::getContentTypes()[$this->content_type]; } public function getMimeType() { switch ($this->content_file_extension) { case 'pdf': return 'application/pdf'; break; default: return 'image/jpeg'; break; } } public function getUserRegulations() { return $this->hasMany(UserRegulation::class, ['regulation_id' => 'id']); } protected function getOwnerId() { return 'admin'; } protected function getBasePathToStoreFiles() { return Regulation::FILE_PATH; } }