protected function sortContentTypeList(array &$contentTypes, $orderby, $sort = 'asc')
{
switch ($orderby) {
case 'name':
if ($sort === 'asc' || $sort === null) {
usort($contentTypes, function (APIContentType $contentType1, APIContentType $contentType2) {
return strcasecmp($contentType1->identifier, $contentType2->identifier);
});
} elseif ($sort === 'desc') {
usort($contentTypes, function (APIContentType $contentType1, APIContentType $contentType2) {
return strcasecmp($contentType1->identifier, $contentType2->identifier) * -1;
});
} else {
throw new BadRequestException('wrong value for sort parameter');
}
break;
case 'lastmodified':
if ($sort === 'asc' || $sort === null) {
usort($contentTypes, function ($timeObj3, $timeObj4) {
$timeObj3 = strtotime($timeObj3->modificationDate->format('Y-m-d H:i:s'));
$timeObj4 = strtotime($timeObj4->modificationDate->format('Y-m-d H:i:s'));
return $timeObj3 > $timeObj4;
});
} elseif ($sort === 'desc') {
usort($contentTypes, function ($timeObj3, $timeObj4) {
$timeObj3 = strtotime($timeObj3->modificationDate->format('Y-m-d H:i:s'));
$timeObj4 = strtotime($timeObj4->modificationDate->format('Y-m-d H:i:s'));
return $timeObj3 < $timeObj4;
});
} else {
throw new BadRequestException('wrong value for sort parameter');
}
break;
default:
throw new BadRequestException('wrong value for orderby parameter');
break;
}
}