25 use Luracast\Restler\RestException;
27 require_once DOL_DOCUMENT_ROOT.
'/zapier/class/hook.class.php';
41 public static $FIELDS = array(
61 $this->hook =
new Hook($this->db);
75 public function get($id)
77 if (!DolibarrApiAccess::$user->rights->zapier->read) {
78 throw new RestException(401);
81 $result = $this->hook->fetch($id);
83 throw new RestException(404,
'Hook not found');
87 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
105 if (!DolibarrApiAccess::$user->rights->zapier->read) {
106 throw new RestException(401);
109 $arraychoices = array(
110 'invoices' =>
'Invoices',
111 'orders' =>
'Orders',
112 'thirdparties' =>
'Thirparties',
113 'contacts' =>
'Contacts',
125 return $arraychoices;
144 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
148 if (!DolibarrApiAccess::$user->rights->zapier->read) {
149 throw new RestException(401);
154 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
157 $restrictonsocid = 0;
161 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
162 $search_sale = DolibarrApiAccess::$user->id;
165 $sql =
"SELECT t.rowid";
166 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
168 $sql .=
", sc.fk_soc, sc.fk_user";
170 $sql .=
" FROM ".MAIN_DB_PREFIX.
"hook_mytable as t";
172 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
173 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
175 $sql .=
" WHERE 1 = 1";
181 $tmpobject =
new Hook($this->db);
182 if ($tmpobject->ismultientitymanaged) {
183 $sql .=
' AND t.entity IN ('.getEntity(
'hook').
')';
185 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
186 $sql .=
" AND t.fk_soc = sc.fk_soc";
188 if ($restrictonsocid && $socid) {
189 $sql .=
" AND t.fk_soc = ".((int) $socid);
191 if ($restrictonsocid && $search_sale > 0) {
193 $sql .=
" AND t.rowid = sc.fk_soc";
196 if ($restrictonsocid && $search_sale > 0) {
197 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
203 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
207 $sql .= $this->db->order($sortfield, $sortorder);
212 $offset = $limit * $page;
214 $sql .= $this->db->plimit($limit + 1, $offset);
217 $result = $this->db->query(
$sql);
220 $num = $this->db->num_rows($result);
222 $obj = $this->db->fetch_object($result);
223 $hook_static =
new Hook($this->db);
224 if ($hook_static->fetch($obj->rowid)) {
230 throw new RestException(503,
'Error when retrieve hook list');
232 if (!count($obj_ret)) {
233 throw new RestException(404,
'No hook found');
246 public function post($request_data =
null)
248 if (!DolibarrApiAccess::$user->rights->zapier->write) {
249 throw new RestException(401);
256 dol_syslog(
"API Zapier create hook receive : ".print_r($request_data,
true), LOG_DEBUG);
257 $result = $this->
validate($request_data, $fields);
259 foreach ($request_data as $field => $value) {
260 $this->hook->$field = $value;
262 $this->hook->fk_user = DolibarrApiAccess::$user->id;
264 if (!$this->hook->create(DolibarrApiAccess::$user)) {
265 throw new RestException(500,
"Error creating Hook", array_merge(array($this->hook->error), $this->hook->errors));
268 'id' => $this->hook->id,
318 public function delete($id)
320 if (!DolibarrApiAccess::$user->rights->zapier->delete) {
321 throw new RestException(401);
324 $result = $this->hook->fetch($id);
326 throw new RestException(404,
'Hook not found');
330 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
333 if (!$this->hook->delete(DolibarrApiAccess::$user)) {
334 throw new RestException(500,
'Error when deleting Hook : '.$this->hook->error);
340 'message' =>
'Hook deleted'
355 $object = parent::_cleanObjectDatas($object);
372 foreach ($fields as $field) {
373 if (!isset($data[$field])) {
374 throw new RestException(400, $field.
" field missing");
376 $hook[$field] = $data[$field];
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_cleanObjectDatas($object)
Clean sensible object datas.
validate($data, $fields)
Validate fields before create or update object.
__construct()
Constructor.
post($request_data=null)
Create hook object.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='')
List hooks.
getModulesChoices()
Get list of possibles choices for module.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.