145 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
149 if (!DolibarrApiAccess::$user->rights->zapier->read) {
150 throw new RestException(401);
155 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
158 $restrictonsocid = 0;
162 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
163 $search_sale = DolibarrApiAccess::$user->id;
166 $sql =
"SELECT t.rowid";
167 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
169 $sql .=
", sc.fk_soc, sc.fk_user";
171 $sql .=
" FROM ".MAIN_DB_PREFIX.
"hook_mytable as t";
173 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
174 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
176 $sql .=
" WHERE 1 = 1";
182 $tmpobject =
new Hook($this->db);
183 if ($tmpobject->ismultientitymanaged) {
184 $sql .=
' AND t.entity IN ('.getEntity(
'hook').
')';
186 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
187 $sql .=
" AND t.fk_soc = sc.fk_soc";
189 if ($restrictonsocid && $socid) {
190 $sql .=
" AND t.fk_soc = ".((int) $socid);
192 if ($restrictonsocid && $search_sale > 0) {
194 $sql .=
" AND t.rowid = sc.fk_soc";
197 if ($restrictonsocid && $search_sale > 0) {
198 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
204 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
208 $sql .= $this->db->order($sortfield, $sortorder);
213 $offset = $limit * $page;
215 $sql .= $this->db->plimit($limit + 1, $offset);
218 $result = $this->db->query($sql);
221 $num = $this->db->num_rows($result);
223 $obj = $this->db->fetch_object($result);
224 $hook_static =
new Hook($this->db);
225 if ($hook_static->fetch($obj->rowid)) {
231 throw new RestException(503,
'Error when retrieve hook list');
245 public function post($request_data =
null)
247 if (!DolibarrApiAccess::$user->rights->zapier->write) {
248 throw new RestException(401);
251 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 if ($field ===
'caller') {
262 $this->hook->context[
'caller'] = $request_data[
'caller'];
266 $this->hook->$field = $value;
269 $this->hook->fk_user = DolibarrApiAccess::$user->id;
271 if (!$this->hook->create(DolibarrApiAccess::$user)) {
272 throw new RestException(500,
"Error creating Hook", array_merge(array($this->hook->error), $this->hook->errors));
275 'id' => $this->hook->id,