addEllipsis() public static method

http://www.alfasky.com/?p=20 This little function will help you truncate a string to a specified length when copying data to a place where you can only store or display a limited number of characters, then it will append “…” to it showing that some characters were removed from the original entry.
public static addEllipsis ( $string, $length, string $end = '...' ) : string
$string
$length
$end string
return string
Beispiel #1
0
/**
 * Get a combined array with time recordings and expenses to export.
 *
 * @param int $start Time from which to take entries into account.
 * @param int $end Time until which to take entries into account.
 * @param array $projects Array of project IDs to filter by.
 * @param int $filter_cleared (-1: show all, 0:only cleared 1: only not cleared) entries
 * @param bool $short_form should the short form be created
 * @return array with time recordings and expenses chronologically sorted
 */
function invoice_get_data($start, $end, $projects, $filter_cleared, $short_form)
{
    global $database;
    $limitCommentSize = true;
    $results = array();
    // --------------------------------------------------------------------------------
    // timesheet entries
    $timeSheetEntries = $database->get_timeSheet($start, $end, null, null, $projects, null, false, false, $filter_cleared);
    foreach ($timeSheetEntries as $entry) {
        // active recordings will be omitted
        if ($entry['end'] == 0) {
            continue;
        }
        $arr = ext_invoice_empty_entry();
        $arr['type'] = 'timeSheet';
        $arr['desc'] = $entry['activityName'];
        $arr['start'] = $entry['start'];
        $arr['end'] = $entry['end'];
        $arr['hour'] = $entry['duration'] / 3600;
        $arr['fDuration'] = $entry['formattedDuration'];
        // @deprecated use duration instead
        $arr['duration'] = $entry['duration'];
        $arr['timestamp'] = $entry['start'];
        $arr['amount'] = $entry['wage'];
        $arr['description'] = $entry['description'];
        $arr['rate'] = $entry['rate'];
        $arr['comment'] = $entry['comment'];
        $arr['username'] = $entry['userName'];
        $arr['useralias'] = $entry['userAlias'];
        $arr['location'] = $entry['location'];
        $arr['trackingNr'] = $entry['trackingNumber'];
        $arr['projectID'] = $entry['projectID'];
        $arr['projectName'] = $entry['projectName'];
        $arr['projectComment'] = $entry['projectComment'];
        invoice_add_to_array($results, $arr, $short_form);
    }
    // --------------------------------------------------------------------------------
    // if expenses extension is used, load expenses as well
    if (file_exists('../ki_expenses/private_db_layer_mysql.php')) {
        include_once '../ki_expenses/private_db_layer_mysql.php';
        $expenses = get_expenses($start, $end, null, null, $projects, false, false, -1, $filter_cleared);
        foreach ($expenses as $entry) {
            $arr = ext_invoice_empty_entry();
            $arr['type'] = 'expense';
            $arr['desc'] = $entry['designation'];
            $arr['start'] = $entry['timestamp'];
            $arr['end'] = $entry['timestamp'];
            $arr['hour'] = null;
            $arr['fDuration'] = $entry['multiplier'];
            // @deprecated use duration instead
            $arr['duration'] = $entry['multiplier'];
            $arr['timestamp'] = $entry['timestamp'];
            $arr['amount'] = sprintf("%01.2f", $entry['value'] * $entry['multiplier']);
            $arr['description'] = $entry['designation'];
            $arr['rate'] = $entry['value'];
            $arr['comment'] = $entry['comment'];
            $arr['username'] = $entry['userName'];
            $arr['useralias'] = $entry['userAlias'];
            $arr['location'] = null;
            $arr['trackingNr'] = null;
            $arr['projectID'] = $entry['projectID'];
            $arr['projectName'] = $entry['projectName'];
            $arr['projectComment'] = $entry['projectComment'];
            // @deprecated expenses only: will be removed in the future, can be fetched otherwise
            $arr['activityName'] = $entry['designation'];
            // @deprecated expenses only: will be removed in the future, can be fetched otherwise
            $arr['multiplier'] = $entry['multiplier'];
            // @deprecated expenses only: will be removed in the future, can be fetched otherwise
            $arr['value'] = $entry['value'];
            invoice_add_to_array($results, $arr, $short_form);
        }
    }
    $allEntries = array();
    foreach ($results as $entry) {
        if ($limitCommentSize) {
            $entry['comment'] = Kimai_Format::addEllipsis($entry['comment'], 150);
        }
        // FIXME use date_format_3 instead
        $entry['date'] = date("m/d/Y", $entry['timestamp']);
        $allEntries[] = $entry;
    }
    return $allEntries;
}
Beispiel #2
0
/**
 * Get a combined array with time recordings and expenses to export.
 *
 * @param int $start Time from which to take entries into account.
 * @param int $end Time until which to take entries into account.
 * @param array $users Array of user IDs to filter by.
 * @param array $customers Array of customer IDs to filter by.
 * @param array $projects Array of project IDs to filter by.
 * @param array $activities Array of activity IDs to filter by.
 * @param bool $limit sbould the amount of entries be limited
 * @param bool $reverse_order should the entries be put out in reverse order
 * @param string $default_location use this string if no location is set for the entry
 * @param int $filter_cleared (-1: show all, 0:only cleared 1: only not cleared) entries
 * @param int $filter_type (-1 show time and expenses, 0: only show time entries, 1: only show expenses)
 * @param int $limitCommentSize should comments be cut off, when they are too long
 * @return array with time recordings and expenses chronologically sorted
 */
function export_get_data($start, $end, $users = null, $customers = null, $projects = null, $activities = null, $limit = false, $reverse_order = false, $default_location = '', $filter_cleared = -1, $filter_type = -1, $limitCommentSize = true, $filter_refundable = -1)
{
    global $expense_ext_available, $database;
    $timeSheetEntries = array();
    $expenses = array();
    if ($filter_type != 1) {
        $timeSheetEntries = $database->get_timeSheet($start, $end, $users, $customers, $projects, $activities, $limit, $reverse_order, $filter_cleared);
    }
    if ($filter_type != 0 && $expense_ext_available) {
        $expenses = get_expenses($start, $end, $users, $customers, $projects, $limit, $reverse_order, $filter_refundable, $filter_cleared);
    }
    $result_arr = array();
    $timeSheetEntries_index = 0;
    $expenses_index = 0;
    $keys = array('type', 'id', 'time_in', 'time_out', 'duration', 'formattedDuration', 'decimalDuration', 'rate', 'wage', 'wage_decimal', 'budget', 'approved', 'statusID', 'status', 'billable', 'customerID', 'customerName', 'projectID', 'projectName', 'description', 'projectComment', 'activityID', 'activityName', 'comment', 'commentType', 'location', 'trackingNumber', 'username', 'cleared');
    while ($timeSheetEntries_index < count($timeSheetEntries) && $expenses_index < count($expenses)) {
        $arr = array();
        foreach ($keys as $key) {
            $arr[$key] = null;
        }
        $arr['location'] = $default_location;
        if (!$reverse_order && $timeSheetEntries[$timeSheetEntries_index]['start'] > $expenses[$expenses_index]['timestamp'] || $reverse_order && $timeSheetEntries[$timeSheetEntries_index]['start'] < $expenses[$expenses_index]['timestamp']) {
            if ($timeSheetEntries[$timeSheetEntries_index]['end'] != 0) {
                // active recordings will be omitted
                $arr['type'] = 'timeSheet';
                $arr['id'] = $timeSheetEntries[$timeSheetEntries_index]['timeEntryID'];
                $arr['time_in'] = $timeSheetEntries[$timeSheetEntries_index]['start'];
                $arr['time_out'] = $timeSheetEntries[$timeSheetEntries_index]['end'];
                $arr['duration'] = $timeSheetEntries[$timeSheetEntries_index]['duration'];
                $arr['formattedDuration'] = $timeSheetEntries[$timeSheetEntries_index]['formattedDuration'];
                $arr['decimalDuration'] = sprintf("%01.2f", $timeSheetEntries[$timeSheetEntries_index]['duration'] / 3600);
                $arr['rate'] = $timeSheetEntries[$timeSheetEntries_index]['rate'];
                $arr['wage'] = $timeSheetEntries[$timeSheetEntries_index]['wage'];
                $arr['wage_decimal'] = $timeSheetEntries[$timeSheetEntries_index]['wage_decimal'];
                $arr['budget'] = $timeSheetEntries[$timeSheetEntries_index]['budget'];
                $arr['approved'] = $timeSheetEntries[$timeSheetEntries_index]['approved'];
                $arr['statusID'] = $timeSheetEntries[$timeSheetEntries_index]['statusID'];
                $arr['status'] = $timeSheetEntries[$timeSheetEntries_index]['status'];
                $arr['billable'] = $timeSheetEntries[$timeSheetEntries_index]['billable'];
                $arr['customerID'] = $timeSheetEntries[$timeSheetEntries_index]['customerID'];
                $arr['customerName'] = $timeSheetEntries[$timeSheetEntries_index]['customerName'];
                $arr['projectID'] = $timeSheetEntries[$timeSheetEntries_index]['projectID'];
                $arr['projectName'] = $timeSheetEntries[$timeSheetEntries_index]['projectName'];
                $arr['description'] = $timeSheetEntries[$timeSheetEntries_index]['description'];
                $arr['projectComment'] = $timeSheetEntries[$timeSheetEntries_index]['projectComment'];
                $arr['activityID'] = $timeSheetEntries[$timeSheetEntries_index]['activityID'];
                $arr['activityName'] = $timeSheetEntries[$timeSheetEntries_index]['activityName'];
                if ($limitCommentSize) {
                    $arr['comment'] = Kimai_Format::addEllipsis($timeSheetEntries[$timeSheetEntries_index]['comment'], 150);
                } else {
                    $arr['comment'] = $timeSheetEntries[$timeSheetEntries_index]['comment'];
                }
                $arr['commentType'] = $timeSheetEntries[$timeSheetEntries_index]['commentType'];
                $arr['location'] = $timeSheetEntries[$timeSheetEntries_index]['location'];
                $arr['trackingNumber'] = $timeSheetEntries[$timeSheetEntries_index]['trackingNumber'];
                $arr['username'] = $timeSheetEntries[$timeSheetEntries_index]['userName'];
                $arr['cleared'] = $timeSheetEntries[$timeSheetEntries_index]['cleared'];
                $result_arr[] = $arr;
            }
            $timeSheetEntries_index++;
        } else {
            $arr['type'] = 'expense';
            $arr['id'] = $expenses[$expenses_index]['expenseID'];
            $arr['time_in'] = $expenses[$expenses_index]['timestamp'];
            $arr['time_out'] = $expenses[$expenses_index]['timestamp'];
            $arr['wage'] = sprintf("%01.2f", $expenses[$expenses_index]['value'] * $expenses[$expenses_index]['multiplier']);
            $arr['customerID'] = $expenses[$expenses_index]['customerID'];
            $arr['customerName'] = $expenses[$expenses_index]['customerName'];
            $arr['projectID'] = $expenses[$expenses_index]['projectID'];
            $arr['projectName'] = $expenses[$expenses_index]['projectName'];
            $arr['description'] = $expenses[$expenses_index]['designation'];
            $arr['projectComment'] = $expenses[$expenses_index]['projectComment'];
            if ($limitCommentSize) {
                $arr['comment'] = Kimai_Format::addEllipsis($expenses[$expenses_index]['comment'], 150);
            } else {
                $arr['comment'] = $expenses[$expenses_index]['comment'];
            }
            $arr['activityName'] = $expenses[$expenses_index]['designation'];
            $arr['comment'] = $expenses[$expenses_index]['comment'];
            $arr['commentType'] = $expenses[$expenses_index]['commentType'];
            $arr['username'] = $expenses[$expenses_index]['userName'];
            $arr['cleared'] = $expenses[$expenses_index]['cleared'];
            $result_arr[] = $arr;
            $expenses_index++;
        }
    }
    while ($timeSheetEntries_index < count($timeSheetEntries)) {
        if ($timeSheetEntries[$timeSheetEntries_index]['end'] != 0) {
            // active recordings will be omitted
            $arr = array();
            foreach ($keys as $key) {
                $arr[$key] = null;
            }
            $arr['location'] = $default_location;
            $arr['type'] = 'timeSheet';
            $arr['id'] = $timeSheetEntries[$timeSheetEntries_index]['timeEntryID'];
            $arr['time_in'] = $timeSheetEntries[$timeSheetEntries_index]['start'];
            $arr['time_out'] = $timeSheetEntries[$timeSheetEntries_index]['end'];
            $arr['duration'] = $timeSheetEntries[$timeSheetEntries_index]['duration'];
            $arr['formattedDuration'] = $timeSheetEntries[$timeSheetEntries_index]['formattedDuration'];
            $arr['decimalDuration'] = sprintf("%01.2f", $timeSheetEntries[$timeSheetEntries_index]['duration'] / 3600);
            $arr['rate'] = $timeSheetEntries[$timeSheetEntries_index]['rate'];
            $arr['wage'] = $timeSheetEntries[$timeSheetEntries_index]['wage'];
            $arr['wage_decimal'] = $timeSheetEntries[$timeSheetEntries_index]['wage_decimal'];
            $arr['budget'] = $timeSheetEntries[$timeSheetEntries_index]['budget'];
            $arr['approved'] = $timeSheetEntries[$timeSheetEntries_index]['approved'];
            $arr['statusID'] = $timeSheetEntries[$timeSheetEntries_index]['statusID'];
            $arr['status'] = $timeSheetEntries[$timeSheetEntries_index]['status'];
            $arr['billable'] = $timeSheetEntries[$timeSheetEntries_index]['billable'];
            $arr['customerID'] = $timeSheetEntries[$timeSheetEntries_index]['customerID'];
            $arr['customerName'] = $timeSheetEntries[$timeSheetEntries_index]['customerName'];
            $arr['projectID'] = $timeSheetEntries[$timeSheetEntries_index]['projectID'];
            $arr['projectName'] = $timeSheetEntries[$timeSheetEntries_index]['projectName'];
            $arr['projectComment'] = $timeSheetEntries[$timeSheetEntries_index]['projectComment'];
            $arr['activityID'] = $timeSheetEntries[$timeSheetEntries_index]['activityID'];
            $arr['activityName'] = $timeSheetEntries[$timeSheetEntries_index]['activityName'];
            $arr['description'] = $timeSheetEntries[$timeSheetEntries_index]['description'];
            if ($limitCommentSize) {
                $arr['comment'] = Kimai_Format::addEllipsis($timeSheetEntries[$timeSheetEntries_index]['comment'], 150);
            } else {
                $arr['comment'] = $timeSheetEntries[$timeSheetEntries_index]['comment'];
            }
            $arr['commentType'] = $timeSheetEntries[$timeSheetEntries_index]['commentType'];
            $arr['location'] = $timeSheetEntries[$timeSheetEntries_index]['location'];
            $arr['trackingNumber'] = $timeSheetEntries[$timeSheetEntries_index]['trackingNumber'];
            $arr['username'] = $timeSheetEntries[$timeSheetEntries_index]['userName'];
            $arr['cleared'] = $timeSheetEntries[$timeSheetEntries_index]['cleared'];
            $result_arr[] = $arr;
        }
        $timeSheetEntries_index++;
    }
    while ($expenses_index < count($expenses)) {
        $arr = array();
        foreach ($keys as $key) {
            $arr[$key] = null;
        }
        $arr['location'] = $default_location;
        $arr['type'] = 'expense';
        $arr['id'] = $expenses[$expenses_index]['expenseID'];
        $arr['time_in'] = $expenses[$expenses_index]['timestamp'];
        $arr['time_out'] = $expenses[$expenses_index]['timestamp'];
        $arr['wage'] = sprintf("%01.2f", $expenses[$expenses_index]['value'] * $expenses[$expenses_index]['multiplier']);
        $arr['customerID'] = $expenses[$expenses_index]['customerID'];
        $arr['customerName'] = $expenses[$expenses_index]['customerName'];
        $arr['projectID'] = $expenses[$expenses_index]['projectID'];
        $arr['projectName'] = $expenses[$expenses_index]['projectName'];
        $arr['description'] = $expenses[$expenses_index]['designation'];
        $arr['projectComment'] = $expenses[$expenses_index]['projectComment'];
        if ($limitCommentSize) {
            $arr['comment'] = Kimai_Format::addEllipsis($expenses[$expenses_index]['comment'], 150);
        } else {
            $arr['comment'] = $expenses[$expenses_index]['comment'];
        }
        $arr['commentType'] = $expenses[$expenses_index]['commentType'];
        $arr['username'] = $expenses[$expenses_index]['userName'];
        $arr['cleared'] = $expenses[$expenses_index]['cleared'];
        $expenses_index++;
        $result_arr[] = $arr;
    }
    return $result_arr;
}