MDL-78204 availability: Remove 'showmore' from availability_info

- Remove 'showmore' logic from the base availability_info renderable.
Other components rendering the availability information should handle the showmore/showless behaviour themselves.

- Deprecate JS module and string.

- Move availability_info header generation logic to a new protected function to improve code readability.
This commit is contained in:
Mikel Martín
2023-06-26 09:32:36 +02:00
parent 3cd84747cb
commit 09d9f367b6
8 changed files with 35 additions and 64 deletions
@@ -40,12 +40,6 @@ class availability_info implements renderable, templatable {
/** @var core_availability_multiple_messages availabilitymessages the course format class */
protected $availabilitymessages;
/** @var int counts number of conditions */
protected $count = 0;
/** @var int Maximum number of lines of availability info */
protected const MAXVISIBLE = 4;
/**
* Constructor.
*
@@ -53,7 +47,6 @@ class availability_info implements renderable, templatable {
*/
public function __construct(core_availability_multiple_messages $renderable) {
$this->availabilitymessages = $renderable;
$this->count = 0;
}
/**
@@ -68,10 +61,6 @@ class availability_info implements renderable, templatable {
$template->id = uniqid();
if ($this->count >= self::MAXVISIBLE) {
$template->showmorelink = true;
}
return $template;
}
@@ -82,12 +71,9 @@ class availability_info implements renderable, templatable {
*/
protected function get_item_base_template(): stdClass {
return (object)[
'hidden' => $this->count > self::MAXVISIBLE,
'abbreviate' => $this->count === self::MAXVISIBLE,
'id' => false,
'items' => [],
'hasitems' => false,
'showmorelink' => false,
];
}
@@ -101,15 +87,9 @@ class availability_info implements renderable, templatable {
$template = $this->get_item_base_template();
$template->header = get_string(
'list_' . ($availability->root ? 'root_' : '') .
($availability->andoperator ? 'and' : 'or') .
($availability->treehidden ? '_hidden' : ''),
'availability'
);
$template->header = $this->get_item_header($availability);
foreach ($availability->items as $item) {
$this->count++;
if (is_string($item)) {
$simple_item = $this->get_item_base_template();
$simple_item->header = $item;
@@ -123,4 +103,20 @@ class availability_info implements renderable, templatable {
return $template;
}
/**
* Get the item header.
* Depending on availability configuration this will return a string from a combined string identifier.
* For example: list_root_and_hidden, list_and, list_root_or_hidden, list_root_or, etc.
*
* @param core_availability_multiple_messages $availability the availability messages
* @return string the item header
*/
protected function get_item_header(core_availability_multiple_messages $availability): string {
$stridentifier = 'list_' . ($availability->root ? 'root_' : '') .
($availability->andoperator ? 'and' : 'or') .
($availability->treehidden ? '_hidden' : '');
return get_string($stridentifier, 'availability');
}
}