ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilForumLP.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 class ilForumLP extends ilObjectLP
26 {
27  public function appendModeConfiguration(int $mode, ilRadioOption $modeElement): void
28  {
29  global $DIC;
30 
32  $num_postings = new ilNumberInputGUI(
33  $DIC->language()->txt('trac_frm_contribution_num_postings'),
34  'number_of_postings'
35  );
36  $num_postings->allowDecimals(false);
37  $num_postings->setMinValue(1);
38  $num_postings->setMaxValue(99999);
39  $num_postings->setSize(4);
40  $num_postings->setRequired(true);
41  if (is_int(ilForumProperties::getInstance($this->obj_id)->getLpReqNumPostings())) {
42  $requiredNumberOfPostings = ilForumProperties::getInstance($this->obj_id)->getLpReqNumPostings();
43  $num_postings->setValue((string) $requiredNumberOfPostings);
44  } else {
45  $num_postings->setValue('');
46  }
47  $modeElement->addSubItem($num_postings);
48 
49  // Use the default text presentation of the base class
50  $modeElement->setTitle(parent::getModeText($mode));
51  }
52  }
53 
54  public function saveModeConfiguration(ilPropertyFormGUI $form, bool &$modeChanged): void
55  {
56  $frm_properties = ilForumProperties::getInstance($this->obj_id);
57 
58  $current_value = $frm_properties->getLpReqNumPostings();
59 
60  if (is_numeric($form->getInput('number_of_postings'))) {
61  $frm_properties->setLpReqNumPostings(
62  (int) $form->getInput('number_of_postings')
63  );
64  } else {
65  $frm_properties->setLpReqNumPostings(null);
66  }
67  $frm_properties->update();
68 
69  if ($current_value !== $frm_properties->getLpReqNumPostings()) {
70  $modeChanged = true;
71  }
72  }
73 
74  public static function getDefaultModes(bool $lp_active): array
75  {
76  if ($lp_active) {
77  return [
80  ];
81  }
82 
83  return [
85  ];
86  }
87 
88  public function getDefaultMode(): int
89  {
91  }
92 
93  public function getValidModes(): array
94  {
95  return [
98  ];
99  }
100 
101  public function getModeText(int $mode): string
102  {
103  global $DIC;
104 
105  $text = parent::getModeText($mode);
106 
108  $mode === $this->getCurrentMode() &&
109  is_int(($number_of_postings = ilForumProperties::getInstance($this->obj_id)->getLpReqNumPostings()))) {
110  try {
111  $text = sprintf(
112  match ($number_of_postings) {
113  1 => $DIC->language()->txt('trac_frm_contribution_num_postings_info_s'),
114  default => $DIC->language()->txt('trac_frm_contribution_num_postings_info_p')
115  },
116  $text,
117  $number_of_postings
118  );
119  } catch (Throwable) {
120  }
121  }
122 
123  return $text;
124  }
125 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveModeConfiguration(ilPropertyFormGUI $form, bool &$modeChanged)
getModeText(int $mode)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
static getInstance(int $a_obj_id=0)
const LP_MODE_CONTRIBUTION_TO_DISCUSSION
$text
Definition: xapiexit.php:21
global $DIC
Definition: shib_login.php:25
static getDefaultModes(bool $lp_active)
Class ilForumLP.
appendModeConfiguration(int $mode, ilRadioOption $modeElement)
setTitle(string $a_title)