ILIAS  release_8 Revision v8.24
ilArrayUtil Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilArrayUtil:

Static Public Member Functions

static quoteArray (array $a_array)
 Quotes all members of an array for usage in DB query statement. More...
 
static stripSlashesRecursive ($a_data, bool $a_strip_html=true, string $a_allow="")
 
static stripSlashesArray (array $a_arr, bool $a_strip_html=true, string $a_allow="")
 
static sortArray (array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
 
static stableSortArray (array $array, string $a_array_sortby, string $a_array_sortorder="asc", bool $a_numeric=false)
 Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which have the same sort value. More...
 

Static Private Member Functions

static sort_func (array $left, array $right)
 
static sort_func_numeric (array $left, array $right)
 
static mergesort (array &$array, callable $cmp_function=null)
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning ilArrayUtil class various functions, usage as namespace

Author
Sascha Hofmann sasch.nosp@m.ahof.nosp@m.mann@.nosp@m.gmx..nosp@m.de
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Deprecated:
The 2021 Technical Board has decided to mark the ilUtil class as deprecated. The ilUtil is a historically grown helper class with many different UseCases and functions. The class is not under direct maintainership and the responsibilities are unclear. In this context, the class should no longer be used in the code and existing uses should be converted to their own service in the medium term. If you need ilUtil for the implementation of a new function in ILIAS > 7, please contact the Technical Board.

Definition at line 32 of file class.ilArrayUtil.php.

Member Function Documentation

◆ mergesort()

static ilArrayUtil::mergesort ( array &  $array,
callable  $cmp_function = null 
)
staticprivate
Parameters
array$array
callable$cmp_function
Returns
void

Definition at line 180 of file class.ilArrayUtil.php.

180 : void
181 {
182 if ($cmp_function === null) {
183 $cmp_function = 'strcmp';
184 }
185 // Arrays of size < 2 require no action.
186 if (count($array) < 2) {
187 return;
188 }
189
190 // Split the array in half
191 $halfway = count($array) / 2;
192 $array1 = array_slice($array, 0, $halfway);
193 $array2 = array_slice($array, $halfway);
194
195 // Recurse to sort the two halves
196 ilArrayUtil::mergesort($array1, $cmp_function);
197 ilArrayUtil::mergesort($array2, $cmp_function);
198
199 // If all of $array1 is <= all of $array2, just append them.
200 if (call_user_func($cmp_function, end($array1), $array2[0]) < 1) {
201 $array = array_merge($array1, $array2);
202 return;
203 }
204
205 // Merge the two sorted arrays into a single sorted array
206 $array = [];
207 $ptr1 = $ptr2 = 0;
208 while ($ptr1 < count($array1) && $ptr2 < count($array2)) {
209 if (call_user_func($cmp_function, $array1[$ptr1], $array2[$ptr2]) < 1) {
210 $array[] = $array1[$ptr1++];
211 } else {
212 $array[] = $array2[$ptr2++];
213 }
214 }
215
216 // Merge the remainder
217 while ($ptr1 < count($array1)) {
218 $array[] = $array1[$ptr1++];
219 }
220 while ($ptr2 < count($array2)) {
221 $array[] = $array2[$ptr2++];
222 }
223 }
static mergesort(array &$array, callable $cmp_function=null)

References mergesort().

Referenced by mergesort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quoteArray()

static ilArrayUtil::quoteArray ( array  $a_array)
static

Quotes all members of an array for usage in DB query statement.

Deprecated:

Definition at line 39 of file class.ilArrayUtil.php.

39 : array
40 {
41 global $DIC;
42
43 $ilDB = $DIC->database();
44
45
46 if (!is_array($a_array) or !count($a_array)) {
47 return ["''"];
48 }
49
50 foreach ($a_array as $k => $item) {
51 $a_array[$k] = $ilDB->quote($item);
52 }
53
54 return $a_array;
55 }
global $DIC
Definition: feed.php:28

References $DIC, and $ilDB.

Referenced by ilObjGroup\_isMember(), ilUtil\_sortIds(), ilTree\getChildsByTypeFilter(), and ilObjGroup\getGroupMemberData().

+ Here is the caller graph for this function:

◆ sort_func()

static ilArrayUtil::sort_func ( array  $left,
array  $right 
)
staticprivate
Deprecated:

Definition at line 133 of file class.ilArrayUtil.php.

133 : int
134 {
135 global $array_sortby, $array_sortorder;
136
137 if (!isset($array_sortby)) {
138 // occurred in: setup -> new client -> install languages -> sorting of languages
139 $array_sortby = 0;
140 }
141
142 $leftValue = (string) ($left[$array_sortby] ?? '');
143 $rightValue = (string) ($right[$array_sortby] ?? '');
144
145 // this comparison should give optimal results if
146 // locale is provided and mb string functions are supported
147 if ($array_sortorder === "asc") {
148 return ilStr::strCmp($leftValue, $rightValue);
149 } elseif ($array_sortorder === "desc") {
150 return ilStr::strCmp($rightValue, $leftValue);
151 }
152
153 return 0;
154 }
static strCmp(string $a, string $b)
Definition: class.ilStr.php:90

References ilStr\strCmp().

+ Here is the call graph for this function:

◆ sort_func_numeric()

static ilArrayUtil::sort_func_numeric ( array  $left,
array  $right 
)
staticprivate
Deprecated:

Definition at line 159 of file class.ilArrayUtil.php.

159 : int
160 {
161 global $array_sortby, $array_sortorder;
162
163 $leftValue = (string) ($left[$array_sortby] ?? '');
164 $rightValue = (string) ($right[$array_sortby] ?? '');
165
166 if ($array_sortorder === "asc") {
167 return $leftValue <=> $rightValue;
168 } elseif ($array_sortorder === "desc") {
169 return $rightValue <=> $leftValue;
170 }
171
172 return 0;
173 }

◆ sortArray()

static ilArrayUtil::sortArray ( array  $array,
string  $a_array_sortby_key,
string  $a_array_sortorder = "asc",
bool  $a_numeric = false,
bool  $a_keep_keys = false 
)
static
Deprecated:

Definition at line 94 of file class.ilArrayUtil.php.

100 : array {
101 if (!$a_keep_keys) {
102 return self::stableSortArray($array, $a_array_sortby_key, $a_array_sortorder, $a_numeric);
103 }
104
105 global $array_sortby, $array_sortorder;
106 $array_sortby = $a_array_sortby_key;
107
108 if ($a_array_sortorder == "desc") {
109 $array_sortorder = "desc";
110 } else {
111 $array_sortorder = "asc";
112 }
113 if ($a_numeric) {
114 if ($a_keep_keys) {
115 uasort($array, [ilArrayUtil::class, "sort_func_numeric"]);
116 } else {
117 usort($array, [ilArrayUtil::class, "sort_func_numeric"]);
118 }
119 } else {
120 if ($a_keep_keys) {
121 uasort($array, [ilArrayUtil::class, "sort_func"]);
122 } else {
123 usort($array, [ilArrayUtil::class, "sort_func"]);
124 }
125 }
126
127 return $array;
128 }
static stableSortArray(array $array, string $a_array_sortby, string $a_array_sortorder="asc", bool $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...

References stableSortArray().

Referenced by ilSkillCatTableGUI\__construct(), ilBenchmarkTableGUI\__construct(), ilTaxonomyTableGUI\__construct(), ilUserDefinedFields\__read(), ilCourseObjectiveMaterials\_getAssignableMaterials(), ilExport\_getLastExportFileDate(), ilExport\_getLastExportFileInformation(), ilInfoScreenGUI\addPreconditions(), ilCalendarSchedule\calculate(), ilColumnGUI\determineBlocks(), ilLMTracker\determineProgressStatus(), ilObjTypeDefinitionGUI\editObject(), ilTable2GUI\exportData(), ilObjExercise\exportGradesExcel(), ilGlobalTemplate\fillFooter(), ilPollBlockGUI\fillRow(), ilClassificationBlockGUI\filterContainer(), ilTaxonomyNode\fixOrderNumbers(), ilItemGroupItems\getAssignableItems(), ilCalendarSelectionBlockGUI\getCalendars(), ilSkillTree\getChildsByTypeFilter(), ilPersonalSkillExplorerGUI\getChildsOfNode(), ilModulesTableGUI\getComponents(), ilBenchmarkTableGUI\getDataByFirstTable(), ilSessionMaterialsTableGUI\getDataFromDb(), ilFSStorageExercise\getFiles(), ilFSWebStorageExercise\getFiles(), ilContainerFilterFieldData\getFilterSetForRefId(), ilObjectDefinition\getGroupedRepositoryObjectTypes(), ilExAssignmentTeam\getGroupMembersMap(), ilNewItemGroupTableGUI\getGroups(), ilDclCreateViewTableGUI\getHTML(), ilDclEditViewTableGUI\getHTML(), ilDclFieldListTableGUI\getHTML(), ilDclTableListTableGUI\getHTML(), ilDclTableViewEditFieldsTableGUI\getHTML(), ilDclTableViewTableGUI\getHTML(), ilCalendarAgendaListGUI\getHTML(), ilTable2GUI\getHTML(), ilTestManScoringParticipantsTableGUI\getInternalyOrderedDataValues(), ilPCIIMTriggerTableGUI\getItems(), ilPCImageMapTableGUI\getItems(), ilUserRoleStartingPointTableGUI\getItems(), ilBookingInfoScreenAdapter\getList(), ILIAS\Awareness\WidgetManager\getListData(), ilObjAssessmentFolderGUI\getLogDataOutputForm(), ilItemGroupItemsTableGUI\getMaterials(), ilCourseMembershipGUI\getPrintMemberData(), ilObjMediaCast\getSortedItemsArray(), ilObjectDefinition\getSubObjects(), ilObjectActivation\getTimingsAdministrationItems(), ilObjUserTrackingGUI\initLPDefaultsForm(), ilLTIConsumerGradeSynchronizationGUI\initTableData(), ilPCQuestionGUI\insert(), ilObjectListGUI\insertPreconditions(), ilBadgeProfileGUI\listBadges(), ilCourseParticipantsTableGUI\parse(), ilGroupParticipantsTableGUI\parse(), ilLearningSequenceParticipantsTableGUI\parse(), ilSCORMTrackingUsersTableGUI\parse(), ilTimingsPersonalTableGUI\parse(), ilObjectAddNewItemGUI\parsePersonalWorkspace(), ilObjectAddNewItemGUI\parseRepository(), ilTreeExplorerGUI\preloadChilds(), ilContentStyleSettings\read(), ilContainerContentGUI\renderPageEmbeddedBlocks(), ILIAS\Skill\Tree\SkillTreeNodeManager\saveChildsOrder(), ilWikiPageGUI\searchWikiLinkAC(), ilContainerSessionsContentGUI\showMaterials(), ilExerciseManagementGUI\showParticipantObject(), ilLMPresentationGUI\showPrintView(), ilWebLinkItemsContainer\sort(), ilRepositoryExplorerGUI\sortChilds(), ilTableGUI\sortData(), ilContainerSorting\sortItems(), ilExplorer\sortNodes(), ilWorkspaceFolderSorting\sortNodes(), ilContainerSorting\sortOrderDefault(), ilCourseObjectiveQuestionAssignmentTableGUI\sortQuestions(), ilContainerSorting\sortSubItems(), ilAdvancedMDSettingsGUI\updateSubstitutions(), and ilObjTypeDefinitionGUI\viewObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stableSortArray()

static ilArrayUtil::stableSortArray ( array  $array,
string  $a_array_sortby,
string  $a_array_sortorder = "asc",
bool  $a_numeric = false 
)
static

Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which have the same sort value.

To sort an array by multiple sort keys, invoke this function for each sort key.

Deprecated:

Definition at line 232 of file class.ilArrayUtil.php.

237 : array {
238 global $array_sortby, $array_sortorder;
239
240 $array_sortby = $a_array_sortby;
241
242 if ($a_array_sortorder == "desc") {
243 $array_sortorder = "desc";
244 } else {
245 $array_sortorder = "asc";
246 }
247
248 // Create a copy of the array values for sorting
249 $sort_array = array_values($array);
250
251 if ($a_numeric) {
252 ilArrayUtil::mergesort($sort_array, [ilArrayUtil::class, "sort_func_numeric"]);
253 } else {
254 ilArrayUtil::mergesort($sort_array, [ilArrayUtil::class, "sort_func"]);
255 }
256
257 return $sort_array;
258 }

Referenced by ilSCORM2004TrackingItemsTableGUI\getItems(), ilSCORMTrackingItemsTableGUI\getItems(), ilBookingInfoScreenAdapter\getList(), and sortArray().

+ Here is the caller graph for this function:

◆ stripSlashesArray()

static ilArrayUtil::stripSlashesArray ( array  $a_arr,
bool  $a_strip_html = true,
string  $a_allow = "" 
)
static
Deprecated:

Definition at line 82 of file class.ilArrayUtil.php.

82 : array
83 {
84 foreach ($a_arr as $k => $v) {
85 $a_arr[$k] = ilUtil::stripSlashes($v, $a_strip_html, $a_allow);
86 }
87
88 return $a_arr;
89 }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")

References ilUtil\stripSlashes().

Referenced by ilSkillProfileGUI\saveLevelOrder(), ilBasicSkillGUI\updateLevelOrder(), ilExerciseManagementGUI\uploadMultiFeedbackObject(), ilMobMultiSrtUploadGUI\uploadMultipleSubtitleFile(), and ilObjMediaObjectGUI\uploadMultipleSubtitleFileObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stripSlashesRecursive()

static ilArrayUtil::stripSlashesRecursive (   $a_data,
bool  $a_strip_html = true,
string  $a_allow = "" 
)
static
Parameters
$datastring|array
Returns
string|array
Deprecated:

Definition at line 62 of file class.ilArrayUtil.php.

63 {
64 if (is_array($a_data)) {
65 foreach ($a_data as $k => $v) {
66 if (is_array($v)) {
67 $a_data[$k] = ilArrayUtil::stripSlashesRecursive($v, $a_strip_html, $a_allow);
68 } else {
69 $a_data[$k] = ilUtil::stripSlashes($v, $a_strip_html, $a_allow);
70 }
71 }
72 } else {
73 $a_data = ilUtil::stripSlashes($a_data, $a_strip_html, $a_allow);
74 }
75
76 return $a_data;
77 }
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")

References ilUtil\stripSlashes(), and stripSlashesRecursive().

Referenced by ilAnswerWizardInputGUI\checkInput(), ilErrorTextWizardInputGUI\checkInput(), ilEssayKeywordWizardInputGUI\checkInput(), ilImageWizardInputGUI\checkInput(), ilKprimChoiceWizardInputGUI\checkInput(), ilKVPWizardInputGUI\checkInput(), ilMatchingPairWizardInputGUI\checkInput(), ilMatchingWizardInputGUI\checkInput(), ilMultipleChoiceWizardInputGUI\checkInput(), ilSingleChoiceWizardInputGUI\checkInput(), ilImagemapCorrectionsInputGUI\checkInput(), assQuestionGUI\cleanupAnswerText(), ilKprimChoiceWizardInputGUI\cleanupAnswerText(), ILIAS\SurveyQuestionPool\Editing\EditingGUIRequest\getAnswers(), ILIAS\SurveyQuestionPool\Editing\EditingGUIRequest\getColumns(), ilGloAdvColSortInputGUI\getInput(), ilCategoryWizardInputGUI\getInput(), ilMatrixRowWizardInputGUI\getInput(), ilImagemapFileInputGUI\getPostBody(), ILIAS\SurveyQuestionPool\Editing\EditingGUIRequest\getRows(), assLongMenu\getSolutionSubmit(), ilMultiFilesSubmitRecursiveSlashesStripper\manipulateFileSubmitValues(), stripSlashesRecursive(), and assLongMenuGUI\writeQuestionSpecificPostData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: