actions_mymodule.class.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /* <one line to give the program's name and a brief idea of what it does.>
  3. * Copyright (C) <year> <name of author>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/modulebuilder/template/class/actions_mymodule.class.php
  20. * \ingroup mymodule
  21. * \brief Example hook overload.
  22. *
  23. * Put detailed description here.
  24. */
  25. /**
  26. * Class ActionsMyModule
  27. */
  28. class ActionsMyModule
  29. {
  30. /**
  31. * @var array Hook results. Propagated to $hookmanager->resArray for later reuse
  32. */
  33. public $results = array();
  34. /**
  35. * @var string String displayed by executeHook() immediately after return
  36. */
  37. public $resprints;
  38. /**
  39. * @var array Errors
  40. */
  41. public $errors = array();
  42. /**
  43. * Constructor
  44. */
  45. public function __construct()
  46. {
  47. }
  48. /**
  49. * Overloading the doActions function : replacing the parent's function with the one below
  50. *
  51. * @param array() $parameters Hook metadatas (context, etc...)
  52. * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
  53. * @param string $action Current action (if set). Generally create or edit or null
  54. * @param HookManager $hookmanager Hook manager propagated to allow calling another hook
  55. * @return int < 0 on error, 0 on success, 1 to replace standard code
  56. */
  57. public function doActions($parameters, &$object, &$action, $hookmanager)
  58. {
  59. $error = 0; // Error counter
  60. $myvalue = 'test'; // A result value
  61. print_r($parameters);
  62. echo "action: " . $action;
  63. print_r($object);
  64. if (in_array('somecontext', explode(':', $parameters['context']))) {
  65. // do something only for the context 'somecontext'
  66. }
  67. if (! $error) {
  68. $this->results = array('myreturn' => $myvalue);
  69. $this->resprints = 'A text to show';
  70. return 0; // or return 1 to replace standard code
  71. } else {
  72. $this->errors[] = 'Error message';
  73. return -1;
  74. }
  75. }
  76. }