ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilWorkspaceFolderSorting.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
12 {
13  const SORT_DERIVED = 0;
16  const SORT_CREATION_ASC = 3;
17  const SORT_CREATION_DESC = 4;
18 
22  protected $lng;
23 
27  public function __construct(ilLanguage $lng = null)
28  {
29  global $DIC;
30 
31  $this->lng = ($lng != null)
32  ? $lng
33  : $DIC->language();
34 
35  $this->lng->loadLanguageModule("wfld");
36  }
37 
46  public function getOptionsByType($wsp_type, $selected, $parent_effective)
47  {
48  $sort_options = ($wsp_type == "wfld")
49  ? [self::SORT_DERIVED => $this->lng->txt("wfld_derive")]
50  : [];
51  if (in_array($wsp_type, ["wfld", "wsrt"])) {
52  $sort_options[self::SORT_ALPHABETICAL_ASC] = $this->getLabel(self::SORT_ALPHABETICAL_ASC);
53  $sort_options[self::SORT_ALPHABETICAL_DESC] = $this->getLabel(self::SORT_ALPHABETICAL_DESC);
54  $sort_options[self::SORT_CREATION_ASC] = $this->getLabel(self::SORT_CREATION_ASC);
55  $sort_options[self::SORT_CREATION_DESC] = $this->getLabel(self::SORT_CREATION_DESC);
56  }
57 
58  if (isset($sort_options[self::SORT_DERIVED])) {
59  $sort_options[self::SORT_DERIVED] .= " (" . $this->getLabel($parent_effective) . ")";
60  }
61 
62  if (isset($sort_options[$selected])) {
63  $sort_options[$selected] = "<strong>" . $sort_options[$selected] . "</strong>";
64  }
65  return $sort_options;
66  }
67 
74  protected function getLabel(int $option)
75  {
76  switch ($option) {
77  case self::SORT_DERIVED: return $this->lng->txt("wfld_derive");
78  case self::SORT_ALPHABETICAL_ASC: return $this->lng->txt("wfld_alphabetically_asc");
79  case self::SORT_ALPHABETICAL_DESC: return $this->lng->txt("wfld_alphabetically_desc");
80  case self::SORT_CREATION_ASC: return $this->lng->txt("wfld_creation_asc");
81  case self::SORT_CREATION_DESC: return $this->lng->txt("wfld_creation_desc");
82  }
83  return "";
84  }
85 
93  public function sortNodes($nodes, $sorting)
94  {
95  switch ($sorting) {
96  case self::SORT_ALPHABETICAL_ASC:
97  $nodes = ilUtil::sortArray($nodes, "title", "asc");
98  break;
99  case self::SORT_ALPHABETICAL_DESC:
100  $nodes = ilUtil::sortArray($nodes, "title", "desc");
101  break;
102 
103  case self::SORT_CREATION_ASC:
104  $nodes = ilUtil::sortArray($nodes, "create_date", "asc");
105  break;
106 
107  case self::SORT_CREATION_DESC:
108  $nodes = ilUtil::sortArray($nodes, "create_date", "desc");
109  break;
110 
111  }
112  return $nodes;
113  }
114 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
getOptionsByType($wsp_type, $selected, $parent_effective)
Get options by type.
__construct(ilLanguage $lng=null)
Constructor.
sortNodes($nodes, $sorting)
Sort nodes.
$DIC
Definition: xapitoken.php:46
language handling