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,