ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWorkspaceFolderSorting.php
Go to the documentation of this file.
1<?php
2
20{
21 public const SORT_DERIVED = 0;
22 public const SORT_ALPHABETICAL_ASC = 1;
23 public const SORT_ALPHABETICAL_DESC = 2;
24 public const SORT_CREATION_ASC = 3;
25 public const SORT_CREATION_DESC = 4;
26
27 protected ilLanguage $lng;
28
29 public function __construct(?ilLanguage $lng = null)
30 {
31 global $DIC;
32
33 $this->lng = ($lng != null)
34 ? $lng
35 : $DIC->language();
36
37 $this->lng->loadLanguageModule("wfld");
38 }
39
40 public function getOptionsByType(
41 string $wsp_type,
42 int $selected,
43 int $parent_effective
44 ): array {
45 $sort_options = ($wsp_type == "wfld")
46 ? [self::SORT_DERIVED => $this->lng->txt("wfld_derive")]
47 : [];
48 if (in_array($wsp_type, ["wfld", "wsrt"])) {
49 $sort_options[self::SORT_ALPHABETICAL_ASC] = $this->getLabel(self::SORT_ALPHABETICAL_ASC);
50 $sort_options[self::SORT_ALPHABETICAL_DESC] = $this->getLabel(self::SORT_ALPHABETICAL_DESC);
51 $sort_options[self::SORT_CREATION_ASC] = $this->getLabel(self::SORT_CREATION_ASC);
52 $sort_options[self::SORT_CREATION_DESC] = $this->getLabel(self::SORT_CREATION_DESC);
53 }
54
55 if (isset($sort_options[self::SORT_DERIVED])) {
56 $sort_options[self::SORT_DERIVED] .= " (" . $this->getLabel($parent_effective) . ")";
57 }
58
59 if (isset($sort_options[$selected])) {
60 $sort_options[$selected] = "<strong>" . $sort_options[$selected] . "</strong>";
61 }
62 return $sort_options;
63 }
64
65 protected function getLabel(int $option): string
66 {
67 switch ($option) {
68 case self::SORT_DERIVED: return $this->lng->txt("wfld_derive");
69 case self::SORT_ALPHABETICAL_ASC: return $this->lng->txt("wfld_alphabetically_asc");
70 case self::SORT_ALPHABETICAL_DESC: return $this->lng->txt("wfld_alphabetically_desc");
71 case self::SORT_CREATION_ASC: return $this->lng->txt("wfld_creation_asc");
72 case self::SORT_CREATION_DESC: return $this->lng->txt("wfld_creation_desc");
73 }
74 return "";
75 }
76
77 public function sortNodes(array $nodes, int $sorting): array
78 {
79 switch ($sorting) {
80 case self::SORT_ALPHABETICAL_ASC:
81 $nodes = ilArrayUtil::sortArray($nodes, "title", "asc");
82 break;
83 case self::SORT_ALPHABETICAL_DESC:
84 $nodes = ilArrayUtil::sortArray($nodes, "title", "desc");
85 break;
86 case self::SORT_CREATION_ASC:
87 $nodes = ilArrayUtil::sortArray($nodes, "create_date", "asc");
88 break;
89 case self::SORT_CREATION_DESC:
90 $nodes = ilArrayUtil::sortArray($nodes, "create_date", "desc");
91 break;
92 }
93 return $nodes;
94 }
95}
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getOptionsByType(string $wsp_type, int $selected, int $parent_effective)
sortNodes(array $nodes, int $sorting)
global $DIC
Definition: shib_login.php:26