ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilObjectPropertyTitleAndDescription.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
30 {
31  private const TITLE_LABEL = 'title';
32  private const DESCRIPTION_LABEL = 'description';
33  private const GROUP_LABEL = 'title_and_description';
34 
35  public function __construct(
36  private string $title = '',
37  private string $long_description = '',
38  private ?ilObjectTypeSpecificPropertyModifications $object_type_specific_property_modifications = null
39  ) {
40  }
41 
42  public function getTitle(): string
43  {
44  if ($this->object_type_specific_property_modifications !== null) {
45  return $this->object_type_specific_property_modifications->modifyTitle($this->title);
46  }
47 
48  return $this->title;
49  }
50 
51  public function withTitle(string $title): self
52  {
53  $clone = clone $this;
54  $clone->title = $title;
55  return $clone;
56  }
57 
58  public function getDescription(): string
59  {
60  return mb_substr($this->getLongDescription(), 0, ilObject::DESC_LENGTH);
61  }
62 
63  public function withDescription(string $description): self
64  {
65  $clone = clone $this;
66  $clone->long_description = $description;
67  return $clone;
68  }
69 
70  public function getLongDescription(): ?string
71  {
72  if ($this->object_type_specific_property_modifications !== null) {
73  return $this->object_type_specific_property_modifications->modifyDescription($this->long_description);
74  }
75  return $this->long_description;
76  }
77 
78  public function toForm(
79  \ilLanguage $language,
80  FieldFactory $field_factory,
82  ): FormInput {
83  $trafo = $refinery->custom()->transformation(
84  function ($vs): ilObjectProperty {
85  list($title, $long_description) = $vs;
87  $title,
88  $long_description
89  );
90  }
91  );
92 
93  $title_input = $field_factory->text($language->txt(self::TITLE_LABEL))
94  ->withoutStripTags()
95  ->withMaxLength(ilObject::TITLE_LENGTH)
96  ->withRequired(true)
97  ->withValue($this->title);
98  $description_input = $field_factory->textarea($language->txt(self::DESCRIPTION_LABEL))
99  ->withoutStripTags()
100  ->withMaxLimit(ilObject::LONG_DESC_LENGTH)
101  ->withValue($this->long_description);
102  return $field_factory->group([$title_input, $description_input], self::GROUP_LABEL)
103  ->withAdditionalTransformation($trafo);
104  }
105 }
__construct(private string $title='', private string $long_description='', private ?ilObjectTypeSpecificPropertyModifications $object_type_specific_property_modifications=null)
toForm(\ilLanguage $language, FieldFactory $field_factory, Refinery $refinery)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
const TITLE_LENGTH
const DESC_LENGTH
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const LONG_DESC_LENGTH
withRequired(bool $is_required, ?Constraint $requirement_constraint=null)
Get an input like this, but set the field to be required (or not).
This describes inputs that can be used in forms.
Definition: FormInput.php:32