Kimai_Database_Mysql::timeEntry_edit PHP Method

timeEntry_edit() public method

edit time sheet entry
Author: th
public timeEntry_edit ( integer $id, array $data ) : boolean
$id integer ID of record
$data array array with new record data
return boolean
    public function timeEntry_edit($id, array $data)
    {
        $data = $this->clean_data($data);
        $original_array = $this->timeSheet_get_data($id);
        $new_array = array();
        $budgetChange = 0;
        $approvedChange = 0;
        foreach ($original_array as $key => $value) {
            if (isset($data[$key]) == true) {
                // budget is added to total budget for activity. So if we change the budget, we need
                // to first subtract the previous entry before adding the new one
                //          	if($key == 'budget') {
                //          		$budgetChange = - $value;
                //          	} else if($key == 'approved') {
                //          		$approvedChange = - $value;
                //          	}
                $new_array[$key] = $data[$key];
            } else {
                $new_array[$key] = $original_array[$key];
            }
        }
        $values['description'] = MySQL::SQLValue($new_array['description']);
        $values['comment'] = MySQL::SQLValue($new_array['comment']);
        $values['location'] = MySQL::SQLValue($new_array['location']);
        if ($new_array['trackingNumber'] == '') {
            $values['trackingNumber'] = 'NULL';
        } else {
            $values['trackingNumber'] = MySQL::SQLValue($new_array['trackingNumber']);
        }
        $values['userID'] = MySQL::SQLValue($new_array['userID'], MySQL::SQLVALUE_NUMBER);
        $values['projectID'] = MySQL::SQLValue($new_array['projectID'], MySQL::SQLVALUE_NUMBER);
        $values['activityID'] = MySQL::SQLValue($new_array['activityID'], MySQL::SQLVALUE_NUMBER);
        $values['commentType'] = MySQL::SQLValue($new_array['commentType'], MySQL::SQLVALUE_NUMBER);
        $values['start'] = MySQL::SQLValue($new_array['start'], MySQL::SQLVALUE_NUMBER);
        $values['end'] = MySQL::SQLValue($new_array['end'], MySQL::SQLVALUE_NUMBER);
        $values['duration'] = MySQL::SQLValue($new_array['duration'], MySQL::SQLVALUE_NUMBER);
        $values['rate'] = MySQL::SQLValue($new_array['rate'], MySQL::SQLVALUE_NUMBER);
        $values['fixedRate'] = MySQL::SQLValue($new_array['fixedRate'], MySQL::SQLVALUE_NUMBER);
        $values['cleared'] = MySQL::SQLValue($new_array['cleared'] ? 1 : 0, MySQL::SQLVALUE_NUMBER);
        $values['budget'] = MySQL::SQLValue($new_array['budget'], MySQL::SQLVALUE_NUMBER);
        $values['approved'] = MySQL::SQLValue($new_array['approved'], MySQL::SQLVALUE_NUMBER);
        $values['statusID'] = MySQL::SQLValue($new_array['statusID'], MySQL::SQLVALUE_NUMBER);
        $values['billable'] = MySQL::SQLValue($new_array['billable'], MySQL::SQLVALUE_NUMBER);
        $filter['timeEntryID'] = MySQL::SQLValue($id, MySQL::SQLVALUE_NUMBER);
        $table = $this->kga['server_prefix'] . "timeSheet";
        if (!$this->conn->TransactionBegin()) {
            $this->logLastError('timeEntry_edit');
            return false;
        }
        $query = MySQL::BuildSQLUpdate($table, $values, $filter);
        $success = true;
        if (!$this->conn->Query($query)) {
            $success = false;
        }
        if ($success) {
            if (!$this->conn->TransactionEnd()) {
                $this->logLastError('timeEntry_edit');
                return false;
            }
        } else {
            // $budgetChange += $values['budget'];
            // $approvedChange += $values['approved'];
            // $this->update_evt_budget($values['projectID'], $values['activityID'], $budgetChange);
            // $this->update_evt_approved($values['projectID'], $values['activityID'], $budgetChange);
            $this->logLastError('timeEntry_edit');
            if (!$this->conn->TransactionRollback()) {
                $this->logLastError('timeEntry_edit');
                return false;
            }
        }
        return $success;
    }
Kimai_Database_Mysql