ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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

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 31 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 178 of file class.ilArrayUtil.php.

References null.

Referenced by stableSortArray().

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

References $DIC, and $ilDB.

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

38  : array
39  {
40  global $DIC;
41 
42  $ilDB = $DIC->database();
43 
44 
45  if (!is_array($a_array) or !count($a_array)) {
46  return ["''"];
47  }
48 
49  foreach ($a_array as $k => $item) {
50  $a_array[$k] = $ilDB->quote($item);
51  }
52 
53  return $a_array;
54  }
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

◆ sort_func()

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

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

References ilStr\strCmp().

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

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

◆ 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 92 of file class.ilArrayUtil.php.

Referenced by ilDerivedTaskCollector\__construct(), ilBenchmarkTableGUI\__construct(), ilTaxonomyTableGUI\__construct(), ilSkillCatTableGUI\__construct(), ilUserDefinedFields\__read(), ilCourseObjectiveMaterials\_getAssignableMaterials(), ilExport\_getLastExportFileDate(), ilExport\_getLastExportFileInformation(), ilNewsItem\_getNewsItemsOfUser(), ilObjRole\_removeObjectId(), ilInfoScreenGUI\addPreconditions(), ilCalendarSchedule\calculate(), ilColumnGUI\determineBlocks(), ilLMTracker\determineProgressStatus(), ilObjTypeDefinitionGUI\editObject(), ilTable2GUI\exportData(), ilObjExercise\exportGradesExcel(), ilClassificationBlockGUI\filterContainer(), ilTaxonomyNode\fixOrderNumbers(), ilTaxonomyClassificationProvider\getActiveTaxonomiesForParentRefId(), ilExAssignmentTeam\getAdoptableTeamAssignments(), ilNewsItem\getAggregatedChildNewsData(), ilNewsItem\getAggregatedNewsData(), ilObjSurvey\getAllRelations(), ilItemGroupItems\getAssignableItems(), ilCalendarSelectionBlockGUI\getCalendars(), ilSkillTree\getChildsByTypeFilter(), ilPersonalSkillExplorerGUI\getChildsOfNode(), ilModulesTableGUI\getComponents(), ilBenchmarkTableGUI\getDataByFirstTable(), ilLearningHistoryEntryCollector\getEntries(), ilLikeData\getExpressionEntries(), ilLikeData\getExpressionEntriesForObject(), ilContainerFilterFieldData\getFilterSetForRefId(), ilObjectDefinition\getGroupedRepositoryObjectTypes(), ilExAssignmentTeam\getGroupMembersMap(), ilNewItemGroupTableGUI\getGroups(), ilDclEditViewTableGUI\getHTML(), ilDclCreateViewTableGUI\getHTML(), ilDclTableViewEditFieldsTableGUI\getHTML(), ilDclFieldListTableGUI\getHTML(), ilCalendarAgendaListGUI\getHTML(), ilTable2GUI\getHTML(), ilPCImageMapTableGUI\getItems(), ilUserRoleStartingPointTableGUI\getItems(), ilObjBlogGUI\getKeywords(), ilBookingInfoScreenAdapter\getList(), ILIAS\Awareness\WidgetManager\getListData(), ilItemGroupItemsTableGUI\getMaterials(), ilCourseMembershipGUI\getPrintMemberData(), ilPageObject\getRecentChanges(), ILIAS\COPage\Editor\Server\UI\ServerTable\getRecords(), ilObjMediaCast\getSortedItemsArray(), ilObjectDefinition\getSubObjects(), ilObjectDefinition\getSubObjectsRecursively(), ilTagging\getTagsForUser(), ilObjectActivation\getTimingsAdministrationItems(), ILIAS\Skill\Usage\UsageDBRepository\getUsageOfObject(), ilObjUserTrackingGUI\initLPDefaultsForm(), ilContainerSessionsContentGUI\initSessionPresentationLimitation(), ilLTIConsumerGradeSynchronizationGUI\initTableData(), ilPCQuestionGUI\insert(), ilObjectListGUI\insertPreconditions(), ilPCParagraph\linkTermsInDom(), ilSCORMTrackingUsersTableGUI\parse(), ilTimingsPersonalTableGUI\parse(), ilGroupParticipantsTableGUI\parse(), ilLearningSequenceParticipantsTableGUI\parse(), ilCourseParticipantsTableGUI\parse(), ILIAS\BookingManager\Reservations\ReservationDBRepository\preloadByContextIds(), ilTreeExplorerGUI\preloadChilds(), ilContentStyleSettings\read(), ilPortfolioPageGUI\renderMyCourses(), ilContainerContentGUI\renderPageEmbeddedBlocks(), ILIAS\Skill\Node\SkillTreeNodeManager\saveChildsOrder(), ilObjStyleSheet\saveMediaQueryOrder(), ILIAS\Wiki\Navigation\ImportantPageDBRepository\saveOrderingAndIndentation(), ilWikiPageGUI\searchWikiLinkAC(), ilExerciseManagementGUI\showParticipantObject(), ilLMPresentationGUI\showPrintView(), ilWebLinkItemsContainer\sortArray(), ilRepositoryExplorerGUI\sortChilds(), ilTableGUI\sortData(), ilContainerSorting\sortItems(), ilWorkspaceFolderSorting\sortNodes(), ilExplorer\sortNodes(), ilContainerSorting\sortOrderDefault(), ilCourseObjectiveQuestionAssignmentTableGUI\sortQuestions(), ILIAS\UI\Component\Legacy\Content\ItemSetManager\sortSessions(), ilContainerSorting\sortSubItems(), ilAdvancedMDSettingsGUI\updateSubstitutions(), and ilObjTypeDefinitionGUI\viewObject().

98  : array {
99  if (!$a_keep_keys) {
100  return self::stableSortArray($array, $a_array_sortby_key, $a_array_sortorder, $a_numeric);
101  }
102 
103  global $array_sortby, $array_sortorder;
104  $array_sortby = $a_array_sortby_key;
105 
106  if ($a_array_sortorder == "desc") {
107  $array_sortorder = "desc";
108  } else {
109  $array_sortorder = "asc";
110  }
111  if ($a_numeric) {
112  if ($a_keep_keys) {
113  uasort($array, [ilArrayUtil::class, "sort_func_numeric"]);
114  } else {
115  usort($array, [ilArrayUtil::class, "sort_func_numeric"]);
116  }
117  } else {
118  if ($a_keep_keys) {
119  uasort($array, [ilArrayUtil::class, "sort_func"]);
120  } else {
121  usort($array, [ilArrayUtil::class, "sort_func"]);
122  }
123  }
124 
125  return $array;
126  }
+ 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 230 of file class.ilArrayUtil.php.

References mergesort().

Referenced by ilSessionMaterialsTableGUI\getDataFromDb(), ilSCORMTrackingItemsTableGUI\getItems(), ilSCORM2004TrackingItemsTableGUI\getItems(), ilBookingInfoScreenAdapter\getList(), ilTrQuery\getUserDataForObject(), ILIAS\BookingManager\Reservations\ReservationDBRepository\preloadByContextIds(), ILIAS\Contact\MailingLists\MailingListsMembersTable\sortedRecords(), ILIAS\Contact\MemberSearch\MailMemberSearchTable\sortedRecords(), ILIAS\Forum\Moderation\ForumModeratorsTable\sortedRecords(), ILIAS\Chatroom\Bans\BannedUsersTable\sortedRecords(), ILIAS\components\Authentication\Pages\AuthPageLanguagesOverviewTable\sortedRecords(), and ILIAS\Contact\MailingLists\MailingListsTable\sortedRecords().

235  : array {
236  global $array_sortby, $array_sortorder;
237 
238  $array_sortby = $a_array_sortby;
239 
240  if ($a_array_sortorder == "desc") {
241  $array_sortorder = "desc";
242  } else {
243  $array_sortorder = "asc";
244  }
245 
246  // Create a copy of the array values for sorting
247  $sort_array = array_values($array);
248 
249  if ($a_numeric) {
250  ilArrayUtil::mergesort($sort_array, [ilArrayUtil::class, "sort_func_numeric"]);
251  } else {
252  ilArrayUtil::mergesort($sort_array, [ilArrayUtil::class, "sort_func"]);
253  }
254 
255  return $sort_array;
256  }
static mergesort(array &$array, ?callable $cmp_function=null)
+ Here is the call graph for this function:
+ 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 80 of file class.ilArrayUtil.php.

References ilUtil\stripSlashes().

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

80  : array
81  {
82  foreach ($a_arr as $k => $v) {
83  $a_arr[$k] = ilUtil::stripSlashes($v, $a_strip_html, $a_allow);
84  }
85 
86  return $a_arr;
87  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
+ 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
Deprecated:

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

References ilUtil\stripSlashes().

Referenced by ilKprimChoiceWizardInputGUI\cleanupAnswerText(), assQuestionGUI\cleanupAnswerText(), ILIAS\SurveyQuestionPool\Editing\EditingGUIRequest\getAnswers(), ILIAS\SurveyQuestionPool\Editing\EditingGUIRequest\getColumns(), ilMatrixRowWizardInputGUI\getInput(), ilCategoryWizardInputGUI\getInput(), ilImagemapFileInputGUI\getPostBody(), ILIAS\SurveyQuestionPool\Editing\EditingGUIRequest\getRows(), ilMultiFilesSubmitRecursiveSlashesStripper\manipulateFileSubmitValues(), ilStartUpGUI\saniziteArrayElementsTrafo(), ilPasswordAssistanceGUI\saniziteArrayElementsTrafo(), ilOpenIdConnectSettingsGUI\saniziteArrayElementsTrafo(), and assLongMenuGUI\writeQuestionSpecificPostData().

60  : array
61  {
62  if (is_array($a_data)) {
63  foreach ($a_data as $k => $v) {
64  if (is_array($v)) {
65  $a_data[$k] = ilArrayUtil::stripSlashesRecursive($v, $a_strip_html, $a_allow);
66  } else {
67  $a_data[$k] = ilUtil::stripSlashes($v, $a_strip_html, $a_allow);
68  }
69  }
70  } else {
71  $a_data = ilUtil::stripSlashes($a_data, $a_strip_html, $a_allow);
72  }
73 
74  return $a_data;
75  }
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
+ 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: