Skip to content

Commit

Permalink
Merge pull request #1753 from marcosgdf/triggers-refactor
Browse files Browse the repository at this point in the history
Refactored Dolibarr triggers
  • Loading branch information
eldy committed Jul 20, 2014
2 parents 5be7e75 + e2912b5 commit f46db55
Show file tree
Hide file tree
Showing 11 changed files with 663 additions and 1,518 deletions.
1 change: 1 addition & 0 deletions htdocs/core/class/interfaces.class.php
Expand Up @@ -23,6 +23,7 @@
* \brief Fichier de la classe de gestion des triggers
*/

require_once DOL_DOCUMENT_ROOT.'/core/triggers/DolibarrTriggers.class.php';

/**
* Class to manage triggers
Expand Down
149 changes: 149 additions & 0 deletions htdocs/core/triggers/DolibarrTriggers.class.php
@@ -0,0 +1,149 @@
<?php

/*
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* Class that all the triggers must extend
*/
abstract class DolibarrTriggers
{

/**
* Database handler
* @var DoliDB
*/
protected $db;

/**
* Name of the trigger
* @var mixed|string
*/
public $name = '';

/**
* Description of the trigger
* @var string
*/
public $description = '';

/**
* Version of the trigger
* @var string
*/
public $version = self::VERSION_DEVELOPMENT;

/**
* Image of the trigger
* @var string
*/
public $picto = 'technic';

/**
* Category of the trigger
* @var string
*/
public $family = '';

/**
* Error reported by the trigger
* @var string
* @deprecated Use $this->errors
*/
public $error = '';

/**
* Errors reported by the trigger
* @var array
*/
public $errors = array();

const VERSION_DEVELOPMENT = 'development';
const VERSION_EXPERIMENTAL = 'experimental';
const VERSION_DOLIBARR = 'dolibarr';

/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct(DoliDB $db) {

$this->db = $db;

if (!isset($this->name)) {
$this->name = preg_replace('/^Interface/i', '', get_class($this));
}
}

/**
* Returns the name of the trigger file
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Returns the description of trigger file
*
* @return string
*/
public function getDesc()
{
return $this->description;
}

/**
* Returns the version of the trigger file
*
* @return string Version of trigger file
*/
public function getVersion()
{
global $langs;
$langs->load("admin");

if ($this->version == self::VERSION_DEVELOPMENT) {
return $langs->trans("Development");
} elseif ($this->version == self::VERSION_EXPERIMENTAL) {
return $langs->trans("Experimental");
} elseif ($this->version == self::VERSION_DOLIBARR) {
return DOL_VERSION;
} elseif ($this->version) {
return $this->version;
} else {
return $langs->trans("Unknown");
}
}

/**
* Function called when a Dolibarrr business event is done.
* All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
*
* @param string $action Event action code
* @param Object $object Object
* @param User $user Object user
* @param Translate $langs Object langs
* @param conf $conf Object conf
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
*/
abstract function run_trigger($action, $object, User $user, Translate $langs, Conf $conf);

}

0 comments on commit f46db55

Please sign in to comment.