PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/utils/class.atktriggerlistener.inc

https://github.com/ibuildingsnl/ATK
PHP | 92 lines | 25 code | 4 blank | 63 comment | 3 complexity | dd2e9fc8b374ba89c9e7beaa0b14e2f2 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, LGPL-3.0
  1. <?php
  2. /**
  3. * This file is part of the Achievo ATK distribution.
  4. * Detailed copyright and licensing information can be found
  5. * in the doc/COPYRIGHT and doc/LICENSE files which should be
  6. * included in the distribution.
  7. *
  8. * @package atk
  9. * @subpackage utils
  10. *
  11. * @copyright (c)2005 Ibuildings.nl BV
  12. * @license http://www.achievo.org/atk/licensing ATK Open Source License
  13. *
  14. * @version $Revision: 4362 $
  15. * $Id$
  16. */
  17. /**
  18. * The atkTriggerListener base class for handling trigger events on records.
  19. *
  20. * The most useful purpose of the atkTriggerListener is to serve as a base
  21. * class for custom trigger listeners. Extend this class and implement
  22. * postUpdate, preDelete etc. functions that will automatically be called
  23. * when such a trigger occurs. For more flexibility, override only
  24. * the notify($trigger, $record) method which catches every trigger.
  25. * Using atkNode::addListener you can add listeners that catch evens such as
  26. * records updates and additions.
  27. * This is much like the classic atk postUpdate/postAdd triggers, only much
  28. * more flexible.
  29. *
  30. * @author Martin Roest <martin@ibuildings.nl>
  31. * @author Peter C. Verhage <peter@achievo.org>
  32. * @package atk
  33. * @subpackage utils
  34. */
  35. class atkTriggerListener
  36. {
  37. /**
  38. * The owning node of the listener.
  39. * @access private
  40. * @var atkNode
  41. */
  42. var $m_node = NULL;
  43. /**
  44. * Base constructor.
  45. *
  46. * @return atkTriggerListener
  47. */
  48. function atkTriggerListener()
  49. {
  50. }
  51. /**
  52. * Set the owning node of the listener.
  53. *
  54. * When using atkNode::addListener to add a listener to a node it is not
  55. * necessary to call this method as addListener will do that for you.
  56. *
  57. * @param atkNode $node The node to set as owner
  58. */
  59. function setNode(&$node)
  60. {
  61. $this->m_node = &$node;
  62. }
  63. /**
  64. * Notify the listener of any action on a record.
  65. *
  66. * This method is called by the framework for each action called on a
  67. * node. Depending on the actionfilter passed in the constructor, the
  68. * call is forwarded to the actionPerformed($action, $record) method.
  69. *
  70. * @param String $trigger The trigger being performed
  71. * @param array $record The record on which the trigger is performed
  72. * @param string $mode The mode (add/update)
  73. * @return boolean Result of operation.
  74. */
  75. function notify($trigger, &$record, $mode=NULL)
  76. {
  77. if (method_exists($this, $trigger))
  78. {
  79. atkdebug("Call listener ".get_class($this)." for trigger $trigger on ".$this->m_node->atkNodeType()." (".$this->m_node->primaryKey($record).")");
  80. return $this->$trigger($record, $mode);
  81. }
  82. else
  83. {
  84. return true;
  85. }
  86. }
  87. }
  88. ?>