API endpoint to update timespent record
This commit is contained in:
parent
0cf4fca331
commit
b7b322e661
@ -516,6 +516,7 @@ class Tasks extends DolibarrApi
|
|||||||
* @param string $note Note
|
* @param string $note Note
|
||||||
*
|
*
|
||||||
* @url POST {id}/addtimespent
|
* @url POST {id}/addtimespent
|
||||||
|
* NOTE: Should be "POST {id}/timespent", since POST already implies "add"
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -562,6 +563,64 @@ class Tasks extends DolibarrApi
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update time spent for a task of a project.
|
||||||
|
* You can test this API with the following input message
|
||||||
|
* { "date": "2016-12-31 23:15:00", "duration": 1800, "user_id": 1, "note": "My time test" }
|
||||||
|
*
|
||||||
|
* @param int $id Task ID
|
||||||
|
* @param int $timespent_id Time spent ID (llx_projet_task_time.rowid)
|
||||||
|
* @param datetime $date Date (YYYY-MM-DD HH:MI:SS in GMT)
|
||||||
|
* @param int $duration Duration in seconds (3600 = 1h)
|
||||||
|
* @param int $user_id User (Use 0 for connected user)
|
||||||
|
* @param string $note Note
|
||||||
|
*
|
||||||
|
* @url PUT {id}/timespent/{timespent_id}
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function putTimeSpent($id, $timespent_id, $date, $duration, $user_id = 0, $note = '')
|
||||||
|
{
|
||||||
|
if (!DolibarrApiAccess::$user->rights->projet->creer) {
|
||||||
|
throw new RestException(401);
|
||||||
|
}
|
||||||
|
if ($this->task->fetch($id) <= 0) {
|
||||||
|
throw new RestException(404, 'Task not found');
|
||||||
|
}
|
||||||
|
if ($this->task->fetchTimeSpent($timespent_id) <= 0) {
|
||||||
|
throw new RestException(404, 'Timespent not found');
|
||||||
|
}
|
||||||
|
elseif ($this->task->id != $id) {
|
||||||
|
throw new RestException(404, 'Timespent not found in selected task');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
|
||||||
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newdate = dol_stringtotime($date, 1);
|
||||||
|
$this->task->timespent_date = $newdate;
|
||||||
|
$this->task->timespent_datehour = $newdate;
|
||||||
|
$this->task->timespent_withhour = 1;
|
||||||
|
$this->task->timespent_duration = $duration;
|
||||||
|
$this->task->timespent_fk_user = $user_id ?? DolibarrApiAccess::$user->id;
|
||||||
|
$this->task->timespent_note = $note;
|
||||||
|
|
||||||
|
$result = $this->task->updateTimeSpent(DolibarrApiAccess::$user, 0);
|
||||||
|
if ($result == 0) {
|
||||||
|
throw new RestException(304, 'Error nothing done.');
|
||||||
|
}
|
||||||
|
if ($result < 0) {
|
||||||
|
throw new RestException(500, 'Error when updating time spent: '.$this->task->error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'success' => array(
|
||||||
|
'code' => 200,
|
||||||
|
'message' => 'Time spent updated'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user