26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'hook';
41 public $table_element =
'zapier_hook';
46 public $picto =
'hook@zapier';
49 const STATUS_DRAFT = 0;
50 const STATUS_VALIDATED = 1;
51 const STATUS_DISABLED = -1;
77 public $fields = array(
80 'label' =>
'TechnicalID',
101 'label' =>
'UserOwner',
106 'foreignkey' =>
'llx_user.rowid',
109 'type' =>
'varchar(255)',
115 'css' =>
'minwidth200',
119 'type' =>
'varchar(128)',
125 'css' =>
'minwidth200',
126 'help' =>
'Hook module'
129 'type' =>
'varchar(128)',
135 'css' =>
'minwidth200',
136 'help' =>
'Hook action trigger'
139 'type' =>
'varchar(255)',
145 'css' =>
'minwidth200',
147 'showoncombobox' => 1,
149 'date_creation' => array(
150 'type' =>
'datetime',
151 'label' =>
'DateCreation',
157 'import_key' => array(
158 'type' =>
'varchar(14)',
159 'label' =>
'ImportId',
175 'arrayofkeyval' => array(
216 public $fk_user_creat;
221 public $fk_user_modif;
240 $this->ismultientitymanaged = 0;
241 $this->isextrafieldmanaged = 1;
244 $this->fields[
'rowid'][
'visible'] = 0;
246 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
247 $this->fields[
'entity'][
'enabled'] = 0;
251 foreach ($this->fields as $key => $val) {
252 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
253 unset($this->fields[$key]);
258 foreach ($this->fields as $key => $val) {
259 if (is_array($this->fields[
'status'][
'arrayofkeyval'])) {
260 foreach ($this->fields[
'status'][
'arrayofkeyval'] as $key2 => $val2) {
261 $this->fields[
'status'][
'arrayofkeyval'][$key2] = $langs->trans($val2);
288 global $langs, $extrafields;
305 $object->ref =
"copy_of_".$object->ref;
309 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
310 $extrafields->fetch_name_optionals_label($this->table_element);
311 foreach (
$object->array_options as $key => $option) {
312 $shortkey = preg_replace(
'/options_/',
'', $key);
313 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
317 unset(
$object->array_options[$key]);
323 $object->context[
'createfromclone'] =
'createfromclone';
324 $result =
$object->createCommon($user);
330 unset(
$object->context[
'createfromclone']);
337 $this->db->rollback();
349 public function fetch($id, $ref =
null)
368 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
379 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
380 $sql .=
' WHERE t.entity = '.((int)
$conf->entity);
384 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
386 $this->errors[] = $errormessage;
387 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
391 if (!empty($sortfield)) {
392 $sql .= $this->db->order($sortfield, $sortorder);
394 if (!empty($limit)) {
395 $sql .= $this->db->plimit($limit, $offset);
398 $resql = $this->db->query($sql);
400 $num = $this->db->num_rows($resql);
402 while ($obj = $this->db->fetch_object($resql)) {
403 $record =
new self($this->db);
405 $record->id = $obj->rowid;
409 $records[$record->id] = $record;
411 $this->db->free($resql);
415 $this->errors[] =
'Error '.$this->db->lasterror();
416 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
441 public function delete(
User $user, $notrigger = 0)
457 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
459 global $db,
$conf, $langs, $hookmanager, $action;
460 global $dolibarr_main_authentication, $dolibarr_main_demo;
463 if (!empty(
$conf->dol_no_mouse_hover)) {
470 $label =
'<u>'.$langs->trans(
"Hook").
'</u>';
472 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
474 $url = DOL_URL_ROOT.
'/zapier/hook_card.php?id='.$this->id;
476 if ($option !=
'nolink') {
478 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
479 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
480 $add_save_lastsearch_values = 1;
482 if ($add_save_lastsearch_values) {
483 $url .=
'&save_lastsearch_values=1';
488 if (empty($notooltip)) {
490 $label = $langs->trans(
"ShowMyObject");
491 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
493 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
494 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
496 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
499 $linkstart =
'<a href="'.$url.
'"';
500 $linkstart .= $linkclose.
'>';
503 $result .= $linkstart;
505 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
507 if ($withpicto != 2) {
508 $result .= $this->ref;
513 $hookmanager->initHooks(array(
'hookdao'));
516 'getnomurl' => &$result,
519 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
521 $result = $hookmanager->resPrint;
523 $result .= $hookmanager->resPrint;
559 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
562 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Disabled');
563 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
564 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Disabled');
565 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
568 $statusType =
'status5';
569 if ($status == self::STATUS_VALIDATED) {
570 $statusType =
'status4';
573 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
584 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
585 $sql .=
' fk_user_creat, fk_user_modif';
586 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
587 $sql .=
' WHERE t.rowid = '.((int) $id);
588 $result = $this->db->query($sql);
590 if ($this->db->num_rows($result)) {
591 $obj = $this->db->fetch_object($result);
593 $this->
id = $obj->rowid;
595 $this->user_creation_id = $obj->fk_user_creat;
596 $this->user_modification_id = $obj->fk_user_modif;
597 $this->date_creation = $this->db->jdate($obj->datec);
598 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
601 $this->db->free($result);
if(! $sortfield) if(! $sortorder) $object
Parent class of all other business classes (invoices, contracts, proposals, orders,...
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
info($id)
Load the info information in the object.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetch($id, $ref=null)
Load object in memory from the database.
getLibStatut($mode=0)
Return label of the status.
create(User $user, $notrigger=0)
Create object into database.
update(User $user, $notrigger=0)
Update object into database.
createFromClone(User $user, $fromid)
Clone an object into another one.
LibStatut($status, $mode=0)
Return the status.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.