api can create notification
This commit is contained in:
parent
bc68755c40
commit
6810cb487f
1 changed files with 36 additions and 0 deletions
|
|
@ -1146,6 +1146,42 @@ class Thirdparties extends DolibarrApi
|
|||
return $returnNotifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create CompanyNotification object for thirdparty
|
||||
* @param int $id ID of thirdparty
|
||||
* @param array $request_data Request data
|
||||
*
|
||||
* @return array|mixed Notification of thirdparty
|
||||
*
|
||||
* @url POST {id}/notifications
|
||||
*/
|
||||
public function createCompanyNotification($id, $request_data = null)
|
||||
{
|
||||
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
|
||||
throw new RestException(403, "User has no right to update thirdparties");
|
||||
}
|
||||
if ($this->company->fetch($id) <= 0) {
|
||||
throw new RestException(404, 'Error creating Thirdparty Notification, Thirdparty doesn\'t exists');
|
||||
}
|
||||
$notification = new Notify($this->db);
|
||||
|
||||
$notification->socid = $id;
|
||||
|
||||
foreach ($request_data as $field => $value) {
|
||||
$notification->$field = $value;
|
||||
}
|
||||
|
||||
if ($notification->create(DolibarrApiAccess::$user) < 0) {
|
||||
throw new RestException(500, 'Error creating Thirdparty Notification');
|
||||
}
|
||||
|
||||
if ($notification->update(DolibarrApiAccess::$user) < 0) {
|
||||
throw new RestException(500, 'Error updating values');
|
||||
}
|
||||
|
||||
return $this->_cleanObjectDatas($notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a CompanyNotification attached to a thirdparty
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue