/**
 * Returns ticket custom fields in the form of array:
 * array(
 *     '<custom field group title>' => array(<custom field object>, ... ),
 *     ...
 * )
 *
 * @param kyTicket $ticket Ticket.
 * @param bool $file_custom_field_present Placeholder to indicate if there is file custom field.
 * @return array
 */
function get_ticket_custom_fields(kyTicket $ticket, &$file_custom_field_present)
{
    $custom_field_groups = $ticket->getCustomFieldGroups();
    if (count($custom_field_groups) === 0) {
        return array();
    }
    $custom_fields = array();
    foreach ($custom_field_groups as $custom_field_group) {
        /* @var $custom_field_group kyTicketCustomFieldGroup */
        $group_custom_fields = array();
        foreach ($custom_field_group->getFields() as $custom_field) {
            /* @var $custom_field kyCustomField */
            if (!$custom_field->getDefinition()->getIsUserEditable()) {
                continue;
            }
            if ($custom_field->getType() === kyCustomFieldDefinition::TYPE_FILE) {
                $file_custom_field_present = true;
            }
            $group_custom_fields[$custom_field->getDefinition()->getDisplayOrder()] = $custom_field;
        }
        if (count($group_custom_fields) > 0) {
            ksort($group_custom_fields, SORT_NUMERIC);
            $custom_fields[$custom_field_group->getTitle()] = array_values($group_custom_fields);
        }
    }
    return $custom_fields;
}